:root {
  --bg: #f6fafe;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-line: #e2e8f0;
  --line-strong: #cbd5e1;
  --ink: #0f172a;
  --muted: #64748b;
  --teal: #0f766e;
  --teal-dark: #0b5f59;
  --teal-soft: #ccfbf1;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #be123c;
  --red-soft: #ffe4e6;
  --green: #047857;
  --green-soft: #d1fae5;
  --radius: 8px;
  --sidebar: 232px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 28px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  line-height: 22px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  background: #ffffff;
  border-right: 1px solid var(--surface-line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--surface-line);
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 4px;
  margin-top: 18px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  border-radius: 6px;
  color: #334155;
  text-decoration: none;
  border: 1px solid transparent;
}

.nav-item::before {
  width: 18px;
  color: var(--muted);
  text-align: center;
}

.nav-item[data-icon="grid"]::before {
  content: "▦";
}

.nav-item[data-icon="folder"]::before {
  content: "▤";
}

.nav-item[data-icon="note"]::before {
  content: "◫";
}

.nav-item[data-icon="route"]::before {
  content: "↗";
}

.nav-item[data-icon="calendar"]::before {
  content: "▣";
}

.nav-item.active,
.nav-item:hover {
  background: #ecfdf5;
  border-color: #99f6e4;
  color: var(--teal-dark);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--surface-line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--amber);
}

.status-dot.ok {
  background: var(--green);
}

.workspace {
  min-width: 0;
  padding: 16px;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--surface-line);
  border-radius: var(--radius);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.identity {
  min-width: 190px;
  padding: 5px 10px;
  border: 1px solid var(--surface-line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.identity span,
.identity strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity span {
  color: var(--muted);
  font-size: 11px;
}

.identity strong {
  font-size: 13px;
}

.notice {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--surface-line);
  border-radius: var(--radius);
  background: #ffffff;
}

.notice.error {
  border-color: #fecdd3;
  background: var(--red-soft);
  color: #9f1239;
}

.notice.success {
  border-color: #a7f3d0;
  background: var(--green-soft);
  color: #065f46;
}

.doctor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(380px, 0.9fr);
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.main-column,
.detail-column {
  display: grid;
  gap: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header.compact {
  align-items: center;
}

.panel-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.auth-panel.is-signed-in {
  display: none;
}

.form-grid,
.stack-form,
.followup-form,
.case-summary,
.action-panel,
.upload-box {
  display: grid;
  gap: 10px;
}

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

.form-grid.active {
  display: grid;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

label span {
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.16);
  border-color: var(--teal);
}

.primary-action,
.secondary-action,
.row-action,
.template-row button {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 8px 12px;
  font-weight: 700;
}

.primary-action {
  background: var(--teal);
  color: #ffffff;
}

.primary-action:hover {
  background: var(--teal-dark);
}

.secondary-action,
.row-action,
.template-row button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line-strong);
}

.secondary-action:hover,
.row-action:hover,
.template-row button:hover {
  border-color: #94a3b8;
}

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

.metric-tile {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--surface-line);
  border-radius: var(--radius);
  background: #ffffff;
}

.metric-tile.attention {
  background: #fffbeb;
  border-color: #fde68a;
}

.metric-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric-tile strong {
  font-size: 24px;
  line-height: 28px;
}

.queue-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px;
  gap: 8px;
  min-width: min(100%, 450px);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--surface-line);
  border-radius: var(--radius);
}

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

th,
td {
  min-height: 42px;
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

td {
  color: #1e293b;
}

td:nth-child(4) {
  min-width: 240px;
  white-space: normal;
}

tr:hover td,
tr.active-row td {
  background: #f0fdfa;
}

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

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-chip.neutral,
.status-chip.archived {
  background: #f1f5f9;
  color: #475569;
}

.status-chip.new,
.status-chip.primary_consultation {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.status-chip.observation {
  background: var(--blue-soft);
  color: #1d4ed8;
}

.status-chip.referred {
  background: var(--amber-soft);
  color: #92400e;
}

.detail-panel {
  display: grid;
  gap: 12px;
}

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

.summary-item {
  min-height: 54px;
  padding: 9px;
  background: var(--surface-soft);
  border: 1px solid var(--surface-line);
  border-radius: 6px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.summary-item strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.span-2 {
  grid-column: 1 / -1;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-content: center;
  gap: 4px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 16px;
}

.empty-state strong {
  color: var(--ink);
}

.timeline {
  display: grid;
  gap: 0;
  padding: 4px 0;
}

.timeline-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  min-height: 48px;
  position: relative;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 18px;
  bottom: -6px;
  width: 1px;
  background: var(--surface-line);
}

.timeline-item:last-child::before {
  display: none;
}

.timeline-item > span {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  margin-top: 4px;
  background: #cbd5e1;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px var(--surface-line);
}

.timeline-item.active > span,
.timeline-item.done > span {
  background: var(--teal);
}

.timeline-item strong,
.timeline-item small {
  display: block;
}

.timeline-item small {
  color: var(--muted);
  margin-top: 2px;
}

.upload-box {
  padding: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.asset-list,
.comment-list {
  display: grid;
  gap: 8px;
}

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

.protocol-slot {
  min-height: 142px;
  display: grid;
  grid-template-rows: minmax(86px, 1fr) auto;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--surface-line);
  border-radius: var(--radius);
  background: #ffffff;
}

.protocol-preview {
  display: grid;
  place-items: center;
  min-height: 86px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--surface-soft);
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.protocol-preview img {
  width: 100%;
  height: 100%;
  min-height: 86px;
  object-fit: cover;
  display: block;
}

.protocol-meta {
  min-width: 0;
}

.protocol-meta strong,
.protocol-meta span,
.list-item strong,
.list-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.protocol-meta strong {
  font-size: 12px;
}

.protocol-meta span,
.list-item span,
.muted {
  color: var(--muted);
}

.protocol-meta span {
  font-size: 11px;
  margin-top: 2px;
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--surface-line);
  border-radius: 6px;
  background: #ffffff;
}

.referral-item span:not(.status-chip) {
  white-space: normal;
}

.template-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.template-row button {
  min-height: 32px;
  padding: 6px 9px;
  color: var(--teal-dark);
}

.comment-card {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--surface-line);
  border-radius: var(--radius);
  background: #ffffff;
}

.comment-card p {
  color: #1e293b;
  line-height: 1.45;
}

.comment-card small {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}

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

.comment-meta span {
  color: var(--muted);
  font-size: 12px;
}

.segmented {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  background: var(--surface-soft);
  border: 1px solid var(--surface-line);
  border-radius: 8px;
}

.wide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.radio-segment {
  display: block;
}

.radio-segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.radio-segment span {
  display: grid;
  place-items: center;
  min-height: 32px;
  border-radius: 6px;
  color: var(--muted);
}

.radio-segment input:checked + span {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line-strong);
  color: var(--teal-dark);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--surface-line);
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
  }

  .sidebar-footer {
    margin-top: 12px;
  }

  .doctor-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .workspace {
    padding: 10px;
  }

  .topbar,
  .panel-header,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .metrics-row,
  .summary-grid,
  .queue-controls,
  .protocol-grid {
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-template-columns: 1fr 1fr;
  }

  .identity,
  .queue-controls {
    min-width: 0;
  }
}
