/* ============================================================================
   SkinJourney DASHBOARD — Web-only token additions on top of tokens-app.css
   Same brand. Adapted for desktop, data-dense, RTL.
   ============================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@1,500;1,600;1,700&display=swap');

:root {
  /* --- Web-only role tokens (derived from existing ramps) ----------------- */
  --row-hover:        var(--sand-200);        /* table row hover */
  --row-stripe:       #FBFAF6;                /* very faint zebra */
  --nav-bg:           var(--sand-100);        /* rail background — same as page, hairline divider */
  --nav-item:         var(--text-secondary);
  --nav-item-hover:   var(--sand-200);
  --nav-active-bg:    var(--sage-50);
  --nav-active-fg:    var(--sage-700);
  --table-header-bg:  #F8F6F1;
  --focus-ring:       0 0 0 3px rgba(73,100,89,0.22);

  /* --- Data-viz palette (sage + coral families only, never neon) --------- */
  --viz-1: var(--sage-600);
  --viz-2: var(--sage-400);
  --viz-3: var(--coral-400);
  --viz-4: var(--coral-700);
  --viz-5: var(--sand-500);
  --viz-grid: var(--sand-300);

  /* --- Density (driven by Tweaks panel) ---------------------------------- */
  --density: 1;
  --row-h: calc(56px * var(--density));
  --pad-card: calc(24px * var(--density));
  --pad-card-sm: calc(16px * var(--density));

  /* --- Fonts ------------------------------------------------------------- */
  --font-serif: 'Playfair Display', 'Times New Roman', serif;

  /* --- Layout ------------------------------------------------------------ */
  --rail-w: 260px;
  --rail-w-collapsed: 76px;
  --topbar-h: 64px;
  --content-max: 1280px;
}

/* ============================================================================
   BASE
   ============================================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text-primary); font-family: var(--font-sans); }
html[dir="rtl"], [dir="rtl"] { direction: rtl; }
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; font-feature-settings: "kern", "ss01"; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

::selection { background: var(--sage-200); color: var(--sage-900); }

/* Custom scrollbar — discreet, warm */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sand-300); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--sand-400); }

/* Wordmark */
.wordmark {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* Tabular numbers — for stats, dates, the invite code */
.tabular { font-variant-numeric: tabular-nums; }

/* LTR run inside RTL line (for the invite code, emails, dates) */
.ltr-run { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ============================================================================
   APP SHELL
   ============================================================================ */
.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
  background: var(--bg);
}
.app-shell[data-rail="collapsed"] { grid-template-columns: var(--rail-w-collapsed) 1fr; }

.content-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
  background: rgba(252, 251, 249, 0.86);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 16px;
}

.content-scroll {
  padding: 32px 32px 96px;
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
}

/* ============================================================================
   NAV RAIL
   ============================================================================ */
.rail {
  background: var(--nav-bg);
  border-inline-end: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  gap: 20px;
}
.rail-brand {
  padding: 4px 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: 4px;
}
.rail-brand .wm { color: var(--sage-700); font-size: 24px; }
.rail-brand .clinic { font-size: 12px; color: var(--text-tertiary); font-weight: 600; letter-spacing: 0.2px; }

.rail-section { display: flex; flex-direction: column; gap: 2px; }
.rail-section-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.8px;
  color: var(--text-tertiary); text-transform: uppercase;
  padding: 0 10px 6px;
}

.rail-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--nav-item);
  transition: background var(--dur-quick) var(--ease-standard), color var(--dur-quick) var(--ease-standard);
  position: relative;
  cursor: pointer;
  border: none; background: transparent; width: 100%; text-align: start;
  white-space: nowrap;
}
.rail-item:hover { background: var(--nav-item-hover); color: var(--text-primary); }
.rail-item[data-active="true"] {
  background: var(--nav-active-bg);
  color: var(--nav-active-fg);
}
.rail-item[data-active="true"]::before {
  content: '';
  position: absolute;
  inset-inline-start: -14px;
  top: 8px; bottom: 8px;
  width: 3px;
  background: var(--sage-600);
  border-radius: 999px;
}
.rail-item .badge {
  margin-inline-start: auto;
  background: var(--coral-400);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}
.rail-item .icon { width: 20px; height: 20px; flex-shrink: 0; }

.rail-invite {
  margin-top: 6px;
  background: linear-gradient(160deg, var(--sage-50) 0%, var(--sand-100) 100%);
  border: 1px solid var(--sage-200);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.rail-invite .label { font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--sage-700); }
.rail-invite .code {
  font-family: var(--font-serif); font-style: italic; font-weight: 700;
  color: var(--sage-700); font-size: 22px; letter-spacing: 2px;
  direction: ltr;
}
.rail-invite button {
  margin-top: 4px;
  background: var(--sage-600); color: white;
  border: none; padding: 8px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
  align-self: stretch; justify-content: center;
  transition: background var(--dur-quick) var(--ease-standard), transform var(--dur-quick) var(--ease-standard);
}
.rail-invite button:hover { background: var(--sage-700); }
.rail-invite button:active { transform: scale(0.98); }

.rail-account {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: 10px;
  padding-inline: 6px;
}

/* ============================================================================
   COMMON COMPONENTS
   ============================================================================ */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background var(--dur-quick) var(--ease-standard),
              border-color var(--dur-quick) var(--ease-standard),
              transform var(--dur-quick) var(--ease-standard),
              box-shadow var(--dur-quick) var(--ease-standard);
  white-space: nowrap;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-primary { background: var(--sage-600); color: white; }
.btn-primary:hover { background: var(--sage-700); box-shadow: var(--shadow-sage); }

.btn-secondary { background: transparent; color: var(--text-primary); border-color: var(--border-default); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); }

.btn-accent { background: var(--coral-400); color: white; }
.btn-accent:hover { background: var(--coral-500); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text-primary); }

.btn-danger { background: transparent; color: var(--error); border-color: var(--error-container); }
.btn-danger:hover { background: var(--error-container); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }

.btn-icon {
  width: 36px; height: 36px; padding: 0; border-radius: 10px;
  background: transparent; color: var(--text-secondary);
  border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text-primary); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--elev-1);
  padding: var(--pad-card);
}
.card-flush { padding: 0; overflow: hidden; }
.card-flat { box-shadow: none; }
.card-sunken { background: var(--surface-sunken); border-color: transparent; box-shadow: none; }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 16px;
}
.card-header h3 { margin: 0; font-size: 16px; font-weight: 700; color: var(--text-primary); }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--sage-50);
  color: var(--sage-700);
  border: 1px solid var(--sage-100);
  line-height: 1.4;
  white-space: nowrap;
}
.chip-neutral { background: var(--sand-200); color: var(--text-secondary); border-color: var(--sand-300); }
.chip-coral { background: var(--coral-100); color: var(--coral-700); border-color: var(--coral-200); }
.chip-warning { background: var(--warning-container); color: var(--on-warning-container); border-color: var(--warning-container); }
.chip-success { background: var(--success-container); color: var(--on-success-container); border-color: var(--success-container); }
.chip-info { background: var(--info-container); color: var(--on-info-container); border-color: var(--info-container); }

.chip-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.7;
}

/* Badges */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--coral-400);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
}

/* Avatars */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--grad-sage);
  color: white;
  font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  user-select: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-lg { width: 56px; height: 56px; font-size: 22px; }
.avatar-xl { width: 80px; height: 80px; font-size: 30px; }

/* Inputs */
.input, .textarea, .select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--surface);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  transition: border-color var(--dur-quick) var(--ease-standard), box-shadow var(--dur-quick) var(--ease-standard);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }
.textarea { resize: vertical; min-height: 80px; line-height: 1.55; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.field-help { font-size: 12px; color: var(--text-tertiary); }
.field-error { font-size: 12px; color: var(--error); }

/* Search input */
.search {
  position: relative; display: flex; align-items: center;
}
.search input {
  width: 100%;
  padding: 9px 38px 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-default);
  background: var(--surface);
  font-size: 14px;
  font-family: inherit;
}
.search input:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.search .icon {
  position: absolute;
  inset-inline-end: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
  width: 16px; height: 16px;
}
.search .kbd {
  position: absolute; inset-inline-start: 8px; top: 50%; transform: translateY(-50%);
  font-size: 11px; font-weight: 600;
  background: var(--sand-200); border: 1px solid var(--border-default);
  padding: 2px 6px; border-radius: 6px;
  color: var(--text-tertiary);
  pointer-events: none;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--elev-1);
  overflow: hidden;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table thead th {
  background: var(--table-header-bg);
  text-align: start;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.3px;
  color: var(--text-tertiary);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.table tbody td {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--dur-quick) var(--ease-standard); }
.table tbody tr:hover { background: var(--row-hover); cursor: pointer; }
.table tbody tr[data-flagged="true"] { background: linear-gradient(90deg, transparent 0%, rgba(232,165,152,0.04) 100%); }

/* KPI card */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 20px 22px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--elev-1);
  position: relative;
  overflow: hidden;
  min-height: 132px;
}
.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.4px;
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
.kpi-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--sage-50); color: var(--sage-700);
  display: inline-flex; align-items: center; justify-content: center;
}
.kpi-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.4px;
  line-height: 1;
}
.kpi-meta { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-top: auto; }
.kpi-trend { font-size: 12px; font-weight: 600; color: var(--success); display: inline-flex; align-items: center; gap: 4px; }
.kpi-trend.neg { color: var(--coral-700); }
.kpi-trend.neutral { color: var(--text-tertiary); }

/* Sparkline */
.sparkline { width: 88px; height: 32px; flex-shrink: 0; }

/* Toast */
.toast-host { position: fixed; bottom: 24px; inset-inline-start: 24px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: var(--sand-900); color: white;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--elev-3);
  font-size: 14px;
  font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  pointer-events: auto;
  animation: toast-in var(--dur-emphasized) var(--ease-emphasized);
  max-width: 360px;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(22, 29, 31, 0.42);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: backdrop-in var(--dur-quick) var(--ease-standard);
}
.modal {
  background: var(--surface-elevated);
  border-radius: var(--radius-2xl);
  box-shadow: var(--elev-4);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  animation: modal-in var(--dur-emphasized) var(--ease-emphasized);
}
.modal-lg { max-width: 720px; }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--sand-200) 0%, var(--sand-300) 50%, var(--sand-200) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Animations */
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slide-up { from { transform: translateY(8px); } to { transform: none; } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(20px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.fade-up { animation: slide-up var(--dur-emphasized) var(--ease-emphasized); }
[data-stagger="1"] { animation-delay: 40ms; }
[data-stagger="2"] { animation-delay: 80ms; }
[data-stagger="3"] { animation-delay: 120ms; }
[data-stagger="4"] { animation-delay: 160ms; }
[data-stagger="5"] { animation-delay: 200ms; }
[data-stagger="6"] { animation-delay: 240ms; }

/* Reduced motion preference (driven by tweak) */
[data-motion="reduced"] *, [data-motion="reduced"] *::before, [data-motion="reduced"] *::after {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}

/* Tweak: density */
[data-density="compact"] {
  --density: 0.82;
}
[data-density="compact"] .table tbody td { padding: 10px 16px; }
[data-density="compact"] .table thead th { padding: 9px 16px; }
[data-density="compact"] .card { padding: 18px; }
[data-density="compact"] .kpi { padding: 16px 18px; min-height: 110px; }
[data-density="compact"] .kpi-value { font-size: 30px; }

/* Tweak: accent intensity */
[data-accent="sage"] .btn-accent { background: var(--sage-600); }
[data-accent="sage"] .btn-accent:hover { background: var(--sage-700); }
[data-accent="sage"] .badge { background: var(--sage-600); }
[data-accent="sage"] .rail-item .badge { background: var(--sage-600); }

/* Page transitions */
.screen { /* animations off by default — too fragile for html2canvas */ }
.screen.with-motion { animation: fade-up var(--dur-emphasized) var(--ease-emphasized); }

/* Section header */
.section-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
}
.section-header h2 {
  font-size: 22px; font-weight: 700; color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.2px;
}
.section-header .meta { font-size: 13px; color: var(--text-tertiary); }

/* Empty state */
.empty {
  padding: 56px 32px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-icon {
  width: 64px; height: 64px;
  border-radius: 20px;
  background: var(--sage-50);
  color: var(--sage-600);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.empty h3 { margin: 0; font-size: 18px; color: var(--text-primary); font-weight: 700; }
.empty p { margin: 0; max-width: 380px; font-size: 14px; line-height: 1.55; color: var(--text-secondary); }

/* Tablet */
@media (max-width: 1024px) {
  :root { --rail-w: 76px; }
  .app-shell { grid-template-columns: 1fr var(--rail-w); }
  .rail-item .label { display: none; }
  .rail-section-label { display: none; }
  .rail-brand .clinic { display: none; }
  .rail-brand .wm { font-size: 18px; text-align: center; }
  .rail-invite .code, .rail-invite .label, .rail-invite button .label-text { display: none; }
  .rail-invite { padding: 10px; align-items: center; }
  .rail-account .meta { display: none; }
  .content-scroll { padding: 24px 20px 80px; }
}
