:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #162033;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #176b87;
  --accent-strong: #0f5269;
  --warm: #ef7b45;
  --shadow: 0 18px 50px rgba(31, 41, 55, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(23, 107, 135, 0.08), transparent 280px),
    var(--bg);
  color: var(--text);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans CJK SC",
    system-ui,
    sans-serif;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell,
.admin-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 0;
}

.panel {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.narrow {
  max-width: 520px;
}

.panel-head,
.admin-header {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 36px);
  line-height: 1.15;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  gap: 18px;
}

.notice-box {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
  padding: 14px 16px;
  border: 1px solid #c6dce4;
  border-radius: 8px;
  background: #f3fafc;
  color: #344054;
}

.notice-box strong {
  color: var(--accent-strong);
  font-size: 15px;
}

.notice-box p {
  margin: 0;
  line-height: 1.6;
  font-size: 14px;
}

label {
  display: grid;
  gap: 8px;
  color: #344054;
  font-weight: 700;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 8px;
  color: #344054;
  font-weight: 700;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.segmented-control label {
  display: block;
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.segmented-control span {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #344054;
  cursor: pointer;
  font-weight: 700;
}

.segmented-control input:checked + span {
  border-color: var(--accent);
  background: #e9f5f8;
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--accent);
}

input[type="text"],
input:not([type]) {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.16);
}

.primary-action,
.secondary-action,
.danger-action,
.ghost-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 700;
}

.primary-action {
  background: var(--accent);
  color: #fff;
}

.primary-action:hover {
  background: var(--accent-strong);
}

.primary-action:disabled {
  background: #98a2b3;
  cursor: not-allowed;
}

.secondary-action {
  background: #fff;
  color: var(--accent-strong);
  border-color: #b7d4dd;
}

.secondary-action:hover {
  border-color: var(--accent);
  background: #f3fafc;
}

.danger-action {
  background: #fff;
  color: #b42318;
  border-color: #f1b8b2;
}

.danger-action:hover {
  background: #fff5f4;
  border-color: #d92d20;
}

.danger-action:disabled {
  color: #98a2b3;
  border-color: var(--line);
  cursor: not-allowed;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.ghost-button:hover {
  background: #fff;
  color: var(--text);
}

.signature-stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: #eef3f8;
  z-index: 10;
}

body.signing {
  overflow: hidden;
}

.signature-header,
.signature-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.signature-header h1 {
  font-size: clamp(22px, 3vw, 30px);
}

.canvas-wrap {
  flex: 1;
  min-height: 280px;
  border: 1px solid #b8c4d3;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8);
}

#signatureCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.signature-actions {
  justify-content: flex-end;
}

.signature-actions button {
  min-width: 120px;
}

.muted {
  color: var(--muted);
}

.success-panel {
  text-align: center;
}

.success-panel h1 {
  margin-bottom: 10px;
}

.success-actions {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.rotate-hint {
  display: none;
}

.admin-shell {
  padding: 28px 0;
}

.admin-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.filter-group {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(58px, auto));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.filter-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.filter-button.active {
  background: #e9f5f8;
  color: var(--accent-strong);
}

.check-control {
  display: inline-flex;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.check-control input {
  width: 18px;
  height: 18px;
}

.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 13px;
}

tbody tr:hover {
  background: #fbfdff;
}

.select-col {
  width: 50px;
}

.action-col {
  width: 150px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.text-danger {
  border: 0;
  padding: 0;
  background: transparent;
  color: #b42318;
  cursor: pointer;
  font: inherit;
}

.text-danger:hover {
  text-decoration: underline;
}

.file-name {
  max-width: 340px;
  overflow-wrap: anywhere;
  color: #344054;
}

.empty-state {
  padding: 44px 16px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 680px) {
  .app-shell,
  .admin-shell {
    width: min(100% - 20px, 1120px);
  }

  .panel {
    padding: 22px;
  }

  .admin-header {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar > button,
  .toolbar > .link-button {
    flex: 1 1 160px;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  body.signing.virtual-landscape .signature-stage {
    inset: auto;
    top: 50%;
    left: 50%;
    width: 100dvh;
    height: 100dvw;
    min-width: 100dvh;
    min-height: 100dvw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
    gap: 10px;
    padding: 10px max(12px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
  }

  body.signing.virtual-landscape .signature-header h1 {
    font-size: 22px;
  }

  body.signing.virtual-landscape .signature-header .eyebrow {
    margin-bottom: 3px;
  }

  body.signing.virtual-landscape .canvas-wrap {
    min-height: 0;
  }

  body.signing.virtual-landscape .signature-actions button {
    min-width: 108px;
  }

  body.signing.virtual-landscape .rotate-hint {
    display: none;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .signature-stage {
    gap: 10px;
    padding: 10px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  }

  .signature-header h1 {
    font-size: 22px;
  }

  .signature-header .eyebrow {
    margin-bottom: 3px;
  }

  .signature-actions button {
    min-width: 108px;
  }
}
