:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #16202a;
  --muted: #607080;
  --line: #d8dee6;
  --accent: #1f7a64;
  --accent-strong: #145846;
  --danger: #b42318;
  --warning: #9a6500;
  --ok: #177245;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0 10px;
  cursor: pointer;
}

button:disabled {
  border-color: #bcc6d1;
  background: #cbd3dc;
  cursor: not-allowed;
}

button.secondary,
.topbar-actions button,
.topbar-actions .button-link {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.topbar-actions .button-link {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 0 10px;
  text-decoration: none;
}

.doctor-admin-console {
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 6px 8px;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
}

.login-panel {
  width: min(680px, 100%);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: 116px;
  height: auto;
  flex: 0 0 auto;
}

.topbar h1 {
  margin-bottom: 2px;
  font-size: 18px;
}

.topbar p {
  margin-bottom: 0;
  color: var(--muted);
}

.topbar-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 380px) minmax(620px, 1fr);
  grid-template-areas:
    "recovery recovery"
    "left result";
  gap: 12px;
  align-items: start;
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 12px;
}

#recovery-panel {
  grid-area: recovery;
}

.left-stack {
  display: grid;
  grid-area: left;
  gap: 10px;
  align-content: start;
}

#result-view {
  grid-area: result;
  align-self: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
}

.hidden {
  display: none;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-heading h2,
.panel > h2 {
  margin-bottom: 9px;
  font-size: 19px;
}

.section-heading.compact h3 {
  margin-bottom: 0;
}

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

.left-stack .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#doctor-login-form .form-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 9px 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 7px;
}

.left-stack .tab {
  min-height: 32px;
  padding: 0 9px;
  font-size: 14px;
}

.tab {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.project-card {
  border: 1px solid var(--line);
  background: #fbfcfd;
  padding: 9px;
  margin-bottom: 9px;
}

.project-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 8px 0;
}

.project-actions button {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  padding: 0 10px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.file-picker {
  margin-bottom: 10px;
}

.meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0;
  color: var(--muted);
}

.timer {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  background: #f9fafb;
  font-size: 13px;
}

.status-pill.ok {
  border-color: #b7dbc9;
  color: var(--ok);
}

.status-pill.warn {
  border-color: #f1cf8a;
  color: var(--warning);
}

.status-pill.danger {
  border-color: #f5b5ae;
  color: var(--danger);
}

.message {
  margin: 8px 0 0;
  color: var(--muted);
}

.message.danger {
  color: var(--danger);
}

.message.ok {
  color: var(--ok);
}

.status-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 9px 0 0;
}

.status-summary div {
  border: 1px solid var(--line);
  background: #fbfcfd;
  padding: 6px 7px;
}

.status-summary dt {
  color: var(--muted);
  font-size: 12px;
}

.status-summary dd {
  margin: 4px 0 0;
  color: var(--text);
  font-weight: 700;
}

.progress-line {
  height: 8px;
  background: #edf1f5;
  overflow: hidden;
  margin-top: 10px;
}

#upload-progress {
  height: 100%;
  background: var(--accent-strong);
  transition: width 180ms ease;
}

.list {
  display: grid;
  gap: 8px;
}

.history-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.history-controls-admin,
.history-controls-wide {
  grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
}

.list-item {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  padding: 8px;
  background: #fbfcfd;
}

.list-item button {
  justify-self: start;
  margin-top: 4px;
}

.history-item-actions {
  margin-top: 2px;
}

.history-delete-button {
  min-height: 28px;
  padding: 0 9px;
  font-size: 13px;
}

.history-pagination {
  display: grid;
  grid-template-columns: minmax(0, 80px) minmax(0, 1fr) minmax(0, 80px);
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.history-pagination span {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.result-panels {
  display: grid;
  gap: 8px;
}

.result-panel {
  border: 1px solid var(--line);
  background: #fbfcfd;
}

.result-panel summary {
  min-height: 36px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 700;
}

.result-panel-actions {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding: 6px 8px;
}

.result-copy-button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 13px;
}

.result-panel pre {
  border-width: 1px 0 0;
}

.clipboard-fallback {
  position: fixed;
  left: -9999px;
  top: 0;
}

pre {
  min-height: 80px;
  max-height: 260px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  background: #fbfcfd;
  padding: 8px 10px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 860px) {
  .topbar,
  .meter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-logo {
    width: 104px;
  }

  .app-shell,
  .form-grid,
  #doctor-login-form .form-grid,
  .history-controls {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-areas:
      "recovery"
      "left"
      "result";
  }
}
