/* ===========================================================
   Treatment Tracker — clinical / editorial design system
   Palette: warm bone, deep ink, single forest accent
   =========================================================== */

:root {
  --bone:        #f5f1ea;
  --bone-deep:   #ece6dc;
  --paper:       #fbfaf6;
  --ink:         #1a1815;
  --ink-soft:    #4a463f;
  --ink-faint:   #7a7468;
  --line:        #d9d2c4;
  --line-soft:   #e7e1d4;

  --forest:      #2c5e4c;     /* primary accent */
  --forest-deep: #1f4536;
  --forest-mist: #e8efea;

  --rust:        #b04a2f;     /* alert / overdue */
  --rust-mist:   #f5e6df;
  --gold:        #b8893f;     /* due today */
  --gold-mist:   #f4ecda;
  --moss:        #5d7a3a;     /* accepted / good */
  --moss-mist:   #e8eddd;
  --slate:       #5b6470;     /* neutral state */
  --slate-mist:  #e6e8eb;

  --shadow-sm: 0 1px 2px rgba(26,24,21,.04);
  --shadow:    0 4px 16px rgba(26,24,21,.06);
  --shadow-lg: 0 12px 40px rgba(26,24,21,.10);

  --radius:    6px;
  --radius-lg: 10px;

  --serif:  "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans:   "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono:   "JetBrains Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--sans);
  background: var(--bone);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--forest); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ===== Layout ===== */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--line);
  padding: 32px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink);
  margin-bottom: 4px;
}
.sidebar-brand .accent { color: var(--forest); font-style: italic; }
.sidebar-tagline {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  margin-bottom: 36px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  padding: 14px 12px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  transition: background 120ms ease, color 120ms ease;
}
.nav-item:hover { background: var(--bone-deep); color: var(--ink); }
.nav-item.active { background: var(--ink); color: var(--paper); }
.nav-item.active .nav-badge { background: var(--paper); color: var(--ink); }

.nav-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--rust);
  color: white;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--ink-faint);
  line-height: 1.5;
}

/* ===== Main content ===== */
.main {
  padding: 36px 48px 64px;
  max-width: 1400px;
}

.page-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.page-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  font-weight: 600;
  margin-bottom: 8px;
}

.page-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 38px;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.page-title .italic { font-style: italic; color: var(--forest); font-weight: 400; }

.page-actions { display: flex; gap: 10px; align-items: center; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  transition: all 120ms ease;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--forest); }
.btn-secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--ink); }
.btn-ghost { color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bone-deep); color: var(--ink); }
.btn-danger { color: var(--rust); }
.btn-danger:hover { background: var(--rust-mist); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ===== Cards ===== */
.card {
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.card-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.card-subtitle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  font-weight: 600;
}

/* ===== KPI grid ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 32px;
}

.kpi {
  background: var(--paper);
  padding: 22px 24px;
  position: relative;
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  font-weight: 600;
  margin-bottom: 10px;
}
.kpi-value {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.kpi-value .currency-symbol { color: var(--ink-faint); font-weight: 400; margin-right: 2px; }
.kpi-value .small { font-size: 18px; color: var(--ink-faint); margin-left: 4px; }
.kpi-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}
.kpi-sub .pos { color: var(--moss); font-weight: 600; }
.kpi-sub .neg { color: var(--rust); font-weight: 600; }

/* ===== Period tabs ===== */
.tabs {
  display: inline-flex;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}
.tab {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tab.active { background: var(--ink); color: var(--paper); }
.tab:not(.active):hover { color: var(--ink); }

/* ===== Tables ===== */
.table-wrap {
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  font-weight: 700;
  padding: 14px 16px;
  background: var(--bone);
  border-bottom: 1px solid var(--line);
}
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
  font-size: 13px;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 100ms ease; cursor: pointer; }
.table tbody tr:hover { background: var(--bone); }

.table .num { font-family: var(--mono); font-size: 12px; }
.table .name { font-weight: 600; color: var(--ink); }
.table .muted { color: var(--ink-faint); font-size: 12px; }
.table .notes-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
  font-size: 12px;
}

/* ===== Stage chips ===== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.chip-accepted { background: var(--moss-mist); color: var(--moss); }
.chip-overdue  { background: var(--rust-mist); color: var(--rust); }
.chip-due      { background: var(--gold-mist); color: var(--gold); }
.chip-upcoming { background: var(--forest-mist); color: var(--forest); }
.chip-neutral  { background: var(--slate-mist); color: var(--slate); }
.chip-firm     { background: #f0e0e0; color: #8b3a2c; }

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--ink-faint);
  font-weight: 600;
}
.field input,
.field select,
.field textarea {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--ink);
  transition: border-color 120ms ease;
  width: 100%;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 3px var(--forest-mist);
}
.field textarea { min-height: 80px; resize: vertical; font-family: inherit; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26,24,21,0.4);
  backdrop-filter: blur(3px);
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px;
  overflow-y: auto;
}
.modal {
  background: var(--paper);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-large { max-width: 920px; }
.modal-header {
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.modal-close {
  font-size: 22px;
  color: var(--ink-faint);
  padding: 4px 10px;
  border-radius: var(--radius);
}
.modal-close:hover { background: var(--bone-deep); color: var(--ink); }
.modal-body { padding: 24px 28px; }
.modal-footer {
  padding: 16px 28px;
  background: var(--bone);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line-soft);
}

/* ===== Patient detail layout ===== */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}
@media (max-width: 980px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}
.detail-stat:last-child { border-bottom: none; }
.detail-stat .label { color: var(--ink-faint); }
.detail-stat .value { font-weight: 600; text-align: right; }

.contact-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.contact-entry {
  padding: 12px 14px;
  background: var(--bone);
  border-radius: var(--radius);
  border-left: 3px solid var(--forest);
}
.contact-entry-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.contact-entry-type {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--ink-faint);
  font-weight: 600;
}
.contact-entry-date {
  font-size: 12px;
  color: var(--ink-soft);
  font-family: var(--mono);
}
.contact-entry-note { font-size: 13px; color: var(--ink); white-space: pre-wrap; }

/* ===== Filters bar ===== */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filters input,
.filters select {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
}
.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 3px var(--forest-mist);
}

/* ===== Empty / loading ===== */
.empty {
  padding: 64px 24px;
  text-align: center;
  color: var(--ink-faint);
}
.empty-icon {
  font-family: var(--serif);
  font-size: 36px;
  font-style: italic;
  color: var(--line);
  margin-bottom: 12px;
}
.loading {
  padding: 60px;
  text-align: center;
  color: var(--ink-faint);
  font-style: italic;
  font-family: var(--serif);
}

/* ===== Misc ===== */
.section-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}
@media (max-width: 1100px) { .section-grid { grid-template-columns: 1fr; } }

.divider-text {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 32px 0 20px;
}
.divider-text::before,
.divider-text::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.divider-text span {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 16px;
  color: var(--ink-soft);
}

.dot-divider { color: var(--line); margin: 0 6px; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: slideUp 200ms ease;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 20px; }
  .main { padding: 24px 20px; }
  .form-grid { grid-template-columns: 1fr; }
}
