:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #f0f4f1;
  --ink: #18201c;
  --muted: #647067;
  --line: #d8dfda;
  --accent: #176b5b;
  --accent-strong: #0f5147;
  --accent-soft: #dbece8;
  --warn: #a25b15;
  --danger: #a33a3a;
  --shadow: 0 18px 45px rgba(25, 43, 34, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

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

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

.masthead,
.section-heading,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 18px;
}

.ghost-button,
.primary-button {
  min-height: 44px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

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

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.ghost-button:hover,
.primary-button:not(:disabled):hover {
  transform: translateY(-1px);
}

.primary-button:not(:disabled):hover {
  background: var(--accent-strong);
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.tab-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.tab-button.is-active {
  background: #ffffff;
  border-color: var(--line);
  color: var(--accent-strong);
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 28px;
}

.picker-grid.single {
  grid-template-columns: minmax(0, 1fr);
}

.folder-picker {
  display: grid;
  gap: 10px;
  min-height: 172px;
  padding: 20px;
  background: var(--panel-soft);
  border: 1px dashed #aab8af;
  border-radius: 8px;
}

.picker-label {
  font-size: 18px;
  font-weight: 800;
}

.picker-hint,
.status-text,
.section-heading span {
  color: var(--muted);
  font-size: 14px;
}

.folder-picker input {
  width: 100%;
  min-height: 42px;
  color: var(--muted);
}

.picker-summary {
  align-self: end;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 6px;
  background: #ffffff;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.action-row {
  margin-top: 22px;
}

.status-text {
  text-align: right;
}

.settings-row {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.range-control {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(180px, 320px) 52px;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.range-control input {
  width: 100%;
}

.range-control strong {
  color: var(--accent-strong);
  text-align: right;
}

.signature-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.signature-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) minmax(320px, 1.3fr);
  gap: 16px;
  margin-top: 14px;
}

.signature-upload,
.signature-draw {
  display: grid;
  gap: 10px;
}

.field-label,
.draw-head {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.draw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.signature-preview {
  min-height: 132px;
  display: grid;
  place-items: center;
  padding: 12px;
  border: 1px dashed #aab8af;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 800;
}

.signature-preview img {
  max-width: 100%;
  max-height: 110px;
  object-fit: contain;
}

#signatureCanvas,
#patientSignatureCanvas {
  width: 100%;
  height: 132px;
  border: 1px solid #aab8af;
  border-radius: 8px;
  background: #ffffff;
  touch-action: none;
}

.signature-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.range-control.compact {
  grid-template-columns: minmax(150px, 1fr) minmax(130px, 220px) 62px;
}

.progress-wrap {
  height: 10px;
  margin-top: 16px;
  overflow: hidden;
  background: #e7ece8;
  border-radius: 999px;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #5aa87b);
  transition: width 180ms ease;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.stats-grid.remove-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
  min-height: 88px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.stat-value {
  display: block;
  font-size: 28px;
  font-weight: 850;
  line-height: 1;
}

.stat-label {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.results-section {
  margin-top: 28px;
}

.table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-action {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.table-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.page-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.page-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.page-chip input {
  width: 16px;
  height: 16px;
  margin: 0;
}

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

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--panel-soft);
  color: #2c3830;
  font-size: 13px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.file-list {
  display: grid;
  gap: 4px;
}

.file-pill {
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.badge.warning {
  background: #f6e7d5;
  color: var(--warn);
}

.badge.danger {
  background: #f4dddd;
  color: var(--danger);
}

.preview-dialog {
  width: min(960px, calc(100% - 28px));
  height: min(820px, calc(100% - 28px));
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.preview-dialog::backdrop {
  background: rgba(24, 32, 28, 0.44);
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.preview-frame-wrap {
  height: calc(100% - 72px);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: 0;
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 10px 0;
  }

  .workspace {
    padding: 18px;
  }

  .masthead,
  .section-heading,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .picker-grid,
  .signature-grid,
  .signature-controls,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .range-control,
  .range-control.compact {
    grid-template-columns: 1fr;
  }

  .range-control strong {
    text-align: left;
  }

  .status-text {
    text-align: left;
  }

  .primary-button,
  .ghost-button,
  .button-group {
    width: 100%;
  }

  .button-group {
    flex-direction: column;
  }
}
