/* ============================================================
   Diabeasy by Caresoft — Design System
   Registry-grade clinical aesthetic
   ============================================================ */

:root {
  /* Parchment & Ink */
  --parchment: #F7F1E3;
  --parchment-soft: #FBF6E8;
  --parchment-deep: #EFE6CC;
  --paper-white: #FDFAF1;
  --ink: #1F1A12;
  --ink-soft: #463C2A;
  --ink-muted: #8A7C5C;
  --rule: #D9CDA8;
  --rule-soft: #E8DFC0;

  /* Mahogany (Primary - Authority) */
  --mahogany: #6B2E2E;
  --mahogany-dark: #4A1F1F;
  --mahogany-light: #8B4444;
  --mahogany-wash: #F3E4DA;

  /* Gold (Seal - Premium markers) */
  --gold: #B8862C;
  --gold-dark: #8E661E;
  --gold-light: #D9A94C;
  --gold-wash: #F5E9CB;

  /* Teal (Clinical / Medical) */
  --teal: #1F5F5B;
  --teal-dark: #143F3D;
  --teal-light: #3A8480;
  --teal-wash: #DCEBE8;

  /* Status */
  --status-good: #2D6A4F;
  --status-good-wash: #D8E8DE;
  --status-warn: #B8862C;
  --status-warn-wash: #F5E9CB;
  --status-alert: #A03928;
  --status-alert-wash: #F3DBD4;
  --status-info: #2C5282;
  --status-info-wash: #D8E1EE;

  /* Typography */
  --font-serif: 'Lora', 'Georgia', serif;
  --font-sans: 'Albert Sans', 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  /* Shadows */
  --shadow-paper: 0 1px 0 rgba(70, 60, 42, 0.04), 0 2px 8px rgba(70, 60, 42, 0.06);
  --shadow-raised: 0 2px 4px rgba(70, 60, 42, 0.08), 0 8px 24px rgba(70, 60, 42, 0.10);
  --shadow-deep: 0 4px 12px rgba(31, 26, 18, 0.12), 0 16px 48px rgba(31, 26, 18, 0.14);

  /* Radii */
  --r-sm: 3px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--parchment);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(at 20% 0%, rgba(184, 134, 44, 0.04) 0px, transparent 50%),
    radial-gradient(at 80% 100%, rgba(31, 95, 91, 0.03) 0px, transparent 50%);
  background-attachment: fixed;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, .serif {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
}

h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 22px; line-height: 1.25; }
h3 { font-size: 18px; line-height: 1.3; }

.eyebrow {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.eyebrow-mahogany { color: var(--mahogany); }
.eyebrow-gold { color: var(--gold-dark); }
.eyebrow-teal { color: var(--teal); }

.numeric {
  font-family: var(--font-serif);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

/* ===== Top Bar ===== */
.app-topbar {
  background: var(--mahogany-dark);
  color: var(--parchment-soft);
  border-bottom: 3px solid var(--gold);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-inner {
  display: flex;
  align-items: center;
  padding: 14px 28px;
  gap: 24px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-seal {
  width: 38px;
  height: 38px;
  background: var(--gold);
  border: 2px solid var(--gold-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  color: var(--mahogany-dark);
  font-weight: 700;
  font-size: 15px;
  box-shadow: inset 0 0 0 2px var(--mahogany-dark), 0 1px 3px rgba(0,0,0,0.3);
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.1;
  margin: 0;
}

.brand-tagline {
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-light);
  margin: 0;
}

.topbar-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.topbar-nav a {
  color: var(--parchment-soft);
  text-decoration: none;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--r-sm);
  opacity: 0.78;
  transition: all 0.15s;
}

.topbar-nav a:hover {
  background: rgba(255,255,255,0.08);
  opacity: 1;
}

.topbar-nav a.active {
  background: rgba(184, 134, 44, 0.18);
  color: var(--gold-light);
  opacity: 1;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 16px;
  border-left: 1px solid rgba(255,255,255,0.12);
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--gold-wash);
  color: var(--mahogany-dark);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 13px;
  border: 1px solid var(--gold);
}

.user-info { font-size: 12px; line-height: 1.3; }
.user-info strong { color: var(--gold-light); font-weight: 500; }
.user-info small { color: rgba(255,255,255,0.6); font-size: 10px; }

/* ===== Sub bar ===== */
.sub-bar {
  background: var(--paper-white);
  border-bottom: 1px solid var(--rule);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.crumb {
  font-size: 11.5px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}
.crumb a { color: var(--mahogany); text-decoration: none; }
.crumb .sep { margin: 0 8px; color: var(--rule); }

.sub-bar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ===== Layout shell ===== */
.app-shell { display: flex; min-height: calc(100vh - 70px); }

.app-sidebar {
  width: 240px;
  background: var(--paper-white);
  border-right: 1px solid var(--rule);
  padding: 20px 0;
  flex-shrink: 0;
}

.sidebar-section {
  margin-bottom: 22px;
  padding: 0 16px;
}

.sidebar-section .eyebrow {
  padding-left: 8px;
  margin-bottom: 8px;
  display: block;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  border-radius: var(--r-sm);
  border-left: 2px solid transparent;
  transition: all 0.12s;
  position: relative;
}

.sidebar-link:hover {
  background: var(--parchment-soft);
  color: var(--ink);
}

.sidebar-link.active {
  background: var(--mahogany-wash);
  color: var(--mahogany-dark);
  border-left-color: var(--mahogany);
  font-weight: 500;
}

.sidebar-link .badge {
  margin-left: auto;
  background: var(--mahogany);
  color: var(--parchment);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 9px;
  font-weight: 600;
}

.sidebar-link .ic {
  width: 16px;
  height: 16px;
  opacity: 0.7;
  display: inline-block;
}

.app-main {
  flex: 1;
  padding: 24px 32px 60px;
  max-width: calc(100% - 240px);
}

/* ===== Cards & Panels ===== */
.panel {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-paper);
  position: relative;
}

.panel-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--rule-soft);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.panel-header .panel-sub {
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.panel-header-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.panel-body { padding: 20px; }
.panel-body-tight { padding: 12px 20px; }

.panel-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--rule-soft);
  background: var(--parchment-soft);
  border-bottom-left-radius: var(--r-md);
  border-bottom-right-radius: var(--r-md);
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Document panel (registry feel) */
.panel-doc {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  position: relative;
  padding: 28px 32px;
  background-image:
    linear-gradient(var(--paper-white), var(--paper-white)),
    repeating-linear-gradient(90deg, transparent, transparent 4px, rgba(107, 46, 46, 0.012) 4px, rgba(107, 46, 46, 0.012) 5px);
}

.panel-doc::before,
.panel-doc::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 4px;
}
.panel-doc::before { top: 0; background: var(--mahogany); border-bottom: 1px solid var(--gold); }
.panel-doc::after { bottom: 0; background: linear-gradient(90deg, transparent, var(--gold), transparent); opacity: 0.4; }

/* ===== KPI cards ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 18px 18px 16px;
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--mahogany);
}
.kpi.kpi-gold::before { background: var(--gold); }
.kpi.kpi-teal::before { background: var(--teal); }
.kpi.kpi-alert::before { background: var(--status-alert); }

.kpi-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-family: var(--font-serif);
  font-size: 32px;
  line-height: 1;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.kpi-value .unit { font-size: 14px; color: var(--ink-muted); margin-left: 3px; font-weight: 400; }

.kpi-meta {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.delta-up { background: var(--status-good-wash); color: var(--status-good); }
.delta-down { background: var(--status-alert-wash); color: var(--status-alert); }
.delta-flat { background: var(--parchment-deep); color: var(--ink-muted); }

.kpi-sub { color: var(--ink-muted); }

/* Sparkline */
.spark {
  position: absolute;
  right: 12px;
  top: 14px;
  width: 80px;
  height: 32px;
  opacity: 0.85;
}

/* ===== Buttons ===== */
.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.12s;
  background: none;
}

.btn-primary {
  background: var(--mahogany);
  color: var(--parchment-soft);
  border-color: var(--mahogany-dark);
}
.btn-primary:hover { background: var(--mahogany-dark); }

.btn-gold {
  background: var(--gold);
  color: var(--mahogany-dark);
  border-color: var(--gold-dark);
  font-weight: 600;
}
.btn-gold:hover { background: var(--gold-dark); color: var(--parchment-soft); }

.btn-teal {
  background: var(--teal);
  color: var(--parchment-soft);
  border-color: var(--teal-dark);
}
.btn-teal:hover { background: var(--teal-dark); }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--rule);
}
.btn-ghost:hover { background: var(--parchment-soft); border-color: var(--ink-muted); }

.btn-sm { padding: 4px 9px; font-size: 11.5px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }

/* ===== Pills / Tags ===== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-sans);
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.pill-good { background: var(--status-good-wash); color: var(--status-good); border-color: rgba(45, 106, 79, 0.18); }
.pill-warn { background: var(--status-warn-wash); color: var(--gold-dark); border-color: rgba(184, 134, 44, 0.28); }
.pill-alert { background: var(--status-alert-wash); color: var(--status-alert); border-color: rgba(160, 57, 40, 0.18); }
.pill-info { background: var(--status-info-wash); color: var(--status-info); border-color: rgba(44, 82, 130, 0.18); }
.pill-neutral { background: var(--parchment-deep); color: var(--ink-soft); border-color: var(--rule); }
.pill-mahogany { background: var(--mahogany-wash); color: var(--mahogany-dark); border-color: rgba(107, 46, 46, 0.18); }
.pill-teal { background: var(--teal-wash); color: var(--teal-dark); border-color: rgba(31, 95, 91, 0.18); }

.pill-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* ===== Tables ===== */
.dtable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.dtable thead th {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 10px 12px;
  border-bottom: 1.5px solid var(--rule);
  text-align: left;
  background: var(--parchment-soft);
}

.dtable tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: middle;
}

.dtable tbody tr:hover {
  background: var(--parchment-soft);
  cursor: pointer;
}

.dtable .col-num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-family: var(--font-serif);
}

.cell-patient {
  display: flex;
  align-items: center;
  gap: 10px;
}

.patient-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--mahogany-wash);
  color: var(--mahogany-dark);
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(107, 46, 46, 0.15);
}

.cell-patient strong { font-weight: 600; font-size: 13px; }
.cell-patient small { color: var(--ink-muted); display: block; font-size: 11px; }

/* ===== Filter bar ===== */
.filterbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--parchment-soft);
  border-bottom: 1px solid var(--rule-soft);
}

.filter-select, .filter-input {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.filter-select:focus, .filter-input:focus { border-color: var(--mahogany); }

.filter-input { min-width: 240px; }

/* ===== Charts ===== */
.chart-wrap {
  position: relative;
  padding: 0 20px 16px;
}
.chart-canvas { width: 100%; height: auto; display: block; }

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--ink-soft);
  padding: 0 20px 12px;
}

.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; }

/* ===== Progress / Bar ===== */
.bar-track {
  height: 6px;
  background: var(--parchment-deep);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.bar-fill-mahogany { background: var(--mahogany); }
.bar-fill-gold { background: var(--gold); }
.bar-fill-alert { background: var(--status-alert); }

/* ===== Wax seal ===== */
.wax-seal {
  width: 64px;
  height: 64px;
  background: radial-gradient(circle at 35% 35%, var(--gold-light) 0%, var(--gold) 35%, var(--gold-dark) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: inset 0 -2px 6px rgba(0,0,0,0.25), 0 3px 8px rgba(184, 134, 44, 0.3);
  font-family: var(--font-serif);
  color: var(--mahogany-dark);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  line-height: 1.1;
  flex-shrink: 0;
}
.wax-seal::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1.5px dashed rgba(74, 31, 31, 0.4);
  border-radius: 50%;
}

/* ===== Banners ===== */
.banner {
  padding: 12px 18px;
  border-radius: var(--r-md);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
}
.banner-info { background: var(--status-info-wash); border-left: 3px solid var(--status-info); color: var(--status-info); }
.banner-warn { background: var(--status-warn-wash); border-left: 3px solid var(--gold-dark); color: var(--gold-dark); }
.banner-alert { background: var(--status-alert-wash); border-left: 3px solid var(--status-alert); color: var(--status-alert); }
.banner-good { background: var(--status-good-wash); border-left: 3px solid var(--status-good); color: var(--status-good); }

/* ===== Utils ===== */
.row-flex { display: flex; gap: 16px; }
.col-flex { display: flex; flex-direction: column; gap: 16px; }
.gap-sm { gap: 8px; }
.gap-lg { gap: 24px; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.text-muted { color: var(--ink-muted); }
.text-mahogany { color: var(--mahogany); }
.text-gold { color: var(--gold-dark); }
.text-teal { color: var(--teal); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fs-11 { font-size: 11px; }
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }
.flex-1 { flex: 1; }
.divider-v { width: 1px; background: var(--rule-soft); align-self: stretch; }
.divider-h { height: 1px; background: var(--rule-soft); margin: 12px 0; }

/* ===== Animations ===== */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fade-up 0.4s ease both; }
.animate-in:nth-child(1) { animation-delay: 0.05s; }
.animate-in:nth-child(2) { animation-delay: 0.1s; }
.animate-in:nth-child(3) { animation-delay: 0.15s; }
.animate-in:nth-child(4) { animation-delay: 0.2s; }

/* ===== Audit footer (registry feel) ===== */
.audit-footer {
  margin-top: 32px;
  padding: 16px 20px;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.audit-footer .audit-stamp { display: flex; gap: 14px; }

/* ===== Patient mobile frame (for app mocks) ===== */
.phone-frame {
  width: 380px;
  margin: 0 auto;
  background: #0F0E0C;
  border-radius: 36px;
  padding: 12px;
  box-shadow: var(--shadow-deep);
  position: relative;
}
.phone-screen {
  background: var(--parchment);
  border-radius: 28px;
  overflow: hidden;
  min-height: 760px;
  position: relative;
}
.phone-notch {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 90px;
  height: 22px;
  background: #0F0E0C;
  border-radius: 14px;
  z-index: 10;
}
.phone-status {
  display: flex;
  justify-content: space-between;
  padding: 14px 24px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
}

/* ===== Print suppression for screenshots ===== */
@media print {
  .app-topbar, .app-sidebar, .sub-bar { display: none; }
  .app-main { max-width: 100%; padding: 20px; }
}
