/* ============================================================
   OsteoScan Design System — handcrafted CSS, no frameworks
   ============================================================ */

/* 1 ── Tokens ------------------------------------------------ */
:root {
  /* Brand palette */
  --navy:        #0f1b3c;
  --navy-mid:    #1a2744;
  --navy-light:  #243460;
  --teal:        #0ea5a0;
  --teal-d:      #0c8a86;
  --teal-light:  #e0f7f6;
  --teal-subtle: #f0fbfa;

  /* Neutrals */
  --bg:          #f0f4f8;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e2e8f0;
  --border-mid:  #cbd5e1;

  /* Text */
  --text:        #1e293b;
  --text-muted:  #64748b;
  --text-faint:  #94a3b8;

  /* Semantic — Normal */
  --green:       #16a34a;
  --green-d:     #15803d;
  --green-bg:    #f0fdf4;
  --green-bdr:   #bbf7d0;

  /* Semantic — Osteopenia */
  --amber:       #d97706;
  --amber-d:     #b45309;
  --amber-bg:    #fffbeb;
  --amber-bdr:   #fde68a;

  /* Semantic — Osteoporosis */
  --red:         #dc2626;
  --red-d:       #b91c1c;
  --red-bg:      #fef2f2;
  --red-bdr:     #fecaca;

  /* Radius */
  --r-xs:   4px;
  --r-sm:   8px;
  --r:      12px;
  --r-lg:   16px;
  --r-pill: 999px;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(15,27,60,.06), 0 1px 2px rgba(15,27,60,.04);
  --shadow:    0 4px 16px rgba(15,27,60,.08), 0 2px 6px rgba(15,27,60,.04);
  --shadow-lg: 0 12px 40px rgba(15,27,60,.14), 0 4px 12px rgba(15,27,60,.06);

  /* Motion */
  --t:      0.18s ease;
  --t-slow: 0.75s ease;
}

/* 2 ── Reset + Base ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}
img  { max-width: 100%; display: block; }
a    { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }

/* 3 ── Layout helpers ---------------------------------------- */
.container     { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.container--md { max-width: 760px;  margin: 0 auto; padding: 0 20px; }
.container--sm { max-width: 560px;  margin: 0 auto; padding: 0 20px; }
.container--xs { max-width: 420px;  margin: 0 auto; padding: 0 20px; }

/* 4 ── Site Header ------------------------------------------- */
.site-header {
  background: var(--navy);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 1px 0 rgba(255,255,255,.05), 0 4px 16px rgba(0,0,0,.2);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  flex-shrink: 0;
}
.logo-mark {
  width: 36px; height: 36px;
  background: var(--teal);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -1px;
  flex-shrink: 0;
}
.logo-text { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.3px; line-height: 1.1; }
.logo-sub  { font-size: 0.68rem; color: rgba(255,255,255,.45); letter-spacing: 0.6px; text-transform: uppercase; }

.site-nav { display: flex; align-items: center; gap: 4px; }
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  color: rgba(255,255,255,.7);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color var(--t), background var(--t);
  white-space: nowrap;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.09); text-decoration: none; }
.nav-link.nav-active { color: #fff; }

.nav-avatar {
  width: 26px; height: 26px;
  background: var(--teal);
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.nav-logout { color: rgba(255,255,255,.65); }

/* 5 ── Site Main + Footer ------------------------------------ */
.site-main { flex: 1; padding: 32px 0 56px; }
.site-main--auth {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: linear-gradient(140deg, var(--navy) 0%, var(--navy-light) 55%, #0c6b68 100%);
  min-height: calc(100vh - 62px - 48px);
}
.site-footer {
  background: var(--navy);
  color: rgba(255,255,255,.35);
  text-align: center;
  padding: 14px 20px;
  font-size: 0.7rem;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

/* 6 ── Flash Messages --------------------------------------- */
.flash-wrap { padding: 0 20px; max-width: 1100px; margin: 0 auto 4px; }
.flash {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 11px 16px;
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  margin-bottom: 12px;
}
.flash::before { font-size: 1rem; flex-shrink: 0; line-height: 1.4; }
.flash-error, .flash-danger {
  background: var(--red-bg); border-color: var(--red-bdr); color: var(--red-d);
}
.flash-error::before, .flash-danger::before { content: '⚠'; }
.flash-success {
  background: var(--green-bg); border-color: var(--green-bdr); color: var(--green-d);
}
.flash-success::before { content: '✓'; }
.flash-info, .flash-message {
  background: var(--teal-light); border-color: #99e6e3; color: var(--teal-d);
}
.flash-info::before, .flash-message::before { content: 'ℹ'; }
.flash-warning {
  background: var(--amber-bg); border-color: var(--amber-bdr); color: var(--amber-d);
}
.flash-warning::before { content: '⚠'; }

/* 7 ── Cards ------------------------------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card-body { padding: 28px; }
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--navy-mid);
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.1px;
}

/* 8 ── Buttons ----------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  border: 1.5px solid transparent;
  border-radius: var(--r);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--t), border-color var(--t), color var(--t), opacity var(--t);
  white-space: nowrap;
  line-height: 1;
}
.btn:focus-visible { outline: 2.5px solid var(--teal); outline-offset: 3px; }
.btn:hover { text-decoration: none; }

.btn-primary   { background: var(--teal);    color: #fff; }
.btn-primary:hover { background: var(--teal-d); }

.btn-secondary { background: transparent; color: var(--navy-mid); border-color: var(--border-mid); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-danger    { background: var(--red-bg); color: var(--red); border-color: var(--red-bdr); }
.btn-danger:hover  { background: var(--red); color: #fff; border-color: var(--red); }

.btn-ghost     { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm  { padding: 5px 12px; font-size: 0.78rem; border-radius: var(--r-sm); }
.btn-lg  { padding: 13px 28px; font-size: 1rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* 9 ── Forms ------------------------------------------------- */
.form-field   { margin-bottom: 18px; }
.form-label   { display: block; font-size: 0.85rem; font-weight: 600; color: var(--navy-mid); margin-bottom: 6px; }
.form-label-opt { font-weight: 400; color: var(--text-faint); font-size: 0.8rem; }
.form-input,
.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
  appearance: none;
}
.form-input::placeholder { color: var(--text-faint); }
.form-input:focus,
.form-select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14,165,160,.14);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* 10 ── Badges ----------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-normal       { background: var(--green-bg); color: var(--green);   border-color: var(--green-bdr); }
.badge-osteopenia   { background: var(--amber-bg); color: var(--amber);   border-color: var(--amber-bdr); }
.badge-osteoporosis { background: var(--red-bg);   color: var(--red);     border-color: var(--red-bdr);   }
.badge-admin        { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge-dentist      { background: var(--green-bg); color: var(--green-d); border-color: var(--green-bdr); }
.badge-proto        { background: rgba(14,165,160,.1); color: var(--teal-d); font-size: 0.7rem; padding: 2px 8px; }
.badge-model        { background: var(--green-bg); color: var(--green-d); border-color: var(--green-bdr); }
.badge-fallback     { background: var(--amber-bg); color: var(--amber-d); border-color: var(--amber-bdr); }

/* 11 ── Data Tables ------------------------------------------ */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
  text-align: left;
  padding: 9px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.table-empty td {
  text-align: center;
  color: var(--text-faint);
  padding: 40px !important;
  font-style: italic;
}

/* 12 ── Admin Stats Cards ------------------------------------ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 20px; margin-bottom: 28px; }
.stat-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  border-top: 3px solid var(--teal);
}
.stat-num   { font-size: 2.8rem; font-weight: 800; color: var(--teal); line-height: 1; }
.stat-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 8px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; }

/* 13 ── Admin Sub-Nav ---------------------------------------- */
.admin-nav {
  background: var(--navy-mid);
  border-bottom: 1px solid rgba(255,255,255,.06);
  padding: 0 20px;
  display: flex;
  gap: 2px;
  justify-content: center;
}
.admin-nav a {
  padding: 10px 16px;
  color: rgba(255,255,255,.6);
  font-size: 0.85rem;
  font-weight: 500;
  transition: color var(--t), border-color var(--t);
  border-bottom: 2px solid transparent;
  text-decoration: none;
}
.admin-nav a:hover { color: #fff; }
.admin-nav a.active { color: var(--teal); border-bottom-color: var(--teal); }

/* 14 ── Confidence Bars ------------------------------------- */
.conf-section h3 { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 14px; }
.conf-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.conf-label  { width: 108px; font-size: 0.82rem; color: var(--text); flex-shrink: 0; font-weight: 500; }
.conf-track  { flex: 1; background: var(--border); border-radius: var(--r-pill); height: 8px; overflow: hidden; }
.conf-fill   { height: 100%; border-radius: var(--r-pill); width: 0; transition: width var(--t-slow); }
.conf-fill--normal       { background: var(--green); }
.conf-fill--osteopenia   { background: var(--amber); }
.conf-fill--osteoporosis { background: var(--red);   }
.conf-pct { width: 44px; font-size: 0.8rem; font-weight: 700; color: var(--text); text-align: right; flex-shrink: 0; }

/* 15 ── Pipeline Status Row --------------------------------- */
.pipeline-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0; }
.pipeline-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  flex: 1;
  min-width: 90px;
  text-align: center;
}
.chip-stage  { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.chip-status { font-size: 0.75rem; font-weight: 600; }
.chip-status--model    { color: var(--green-d); }
.chip-status--fallback { color: var(--amber-d); }
.chip-status--active   { color: var(--teal-d); }
.pipeline-chip--active { border-color: var(--teal); background: var(--teal-subtle); }

/* 16 ── Drop Zone ------------------------------------------- */
.drop-zone {
  border: 2px dashed var(--border-mid);
  border-radius: var(--r);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--t), background var(--t);
  background: var(--surface-2);
  position: relative;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--teal);
  background: var(--teal-subtle);
}
.drop-zone-icon   { color: var(--teal); margin: 0 auto 12px; opacity: 0.8; }
.drop-zone-title  { font-size: 0.95rem; font-weight: 600; color: var(--navy-mid); margin-bottom: 4px; }
.drop-zone-hint   { font-size: 0.78rem; color: var(--text-muted); }
.drop-link        { color: var(--teal); }
#dz-preview { max-width: 100%; max-height: 180px; object-fit: contain; margin: 16px auto 0; border-radius: var(--r-sm); display: none; border: 1px solid var(--border); }
#dz-name    { font-size: 0.8rem; color: var(--teal-d); margin-top: 8px; font-weight: 500; }

/* 17 ── Loading Overlay ------------------------------------- */
.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.92);
  border-radius: inherit;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 50;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { font-size: 0.88rem; font-weight: 600; color: var(--navy-mid); }

/* 18 ── Result Page ----------------------------------------- */
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.diagnosis-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: var(--r-pill);
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 18px;
  border: 2px solid transparent;
}
.diagnosis-badge.badge-normal       { background: var(--green-bg); color: var(--green-d);  border-color: var(--green-bdr); }
.diagnosis-badge.badge-osteopenia   { background: var(--amber-bg); color: var(--amber-d);  border-color: var(--amber-bdr); }
.diagnosis-badge.badge-osteoporosis { background: var(--red-bg);   color: var(--red-d);    border-color: var(--red-bdr);   }
.xray-img { width: 100%; border-radius: var(--r-sm); border: 1px solid var(--border); display: block; }
.img-caption { font-size: 0.74rem; color: var(--text-muted); margin-top: 6px; text-align: center; }
.img-block { margin-bottom: 18px; }
.patient-strip {
  display: flex; flex-wrap: wrap; gap: 6px 20px;
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 12px 16px; margin-bottom: 18px;
  font-size: 0.84rem; color: var(--text-muted);
  border: 1px solid var(--border);
}
.patient-strip strong { color: var(--navy-mid); font-weight: 600; }
.alert-panoramic {
  background: var(--amber-bg);
  border: 1px solid var(--amber-bdr);
  border-left: 4px solid #f59e0b;
  border-radius: var(--r-sm);
  padding: 11px 14px;
  margin-bottom: 14px;
  font-size: 0.82rem;
  color: var(--amber-d);
  line-height: 1.55;
}
.alert-high {
  background: var(--red-bg);
  border: 1px solid var(--red-bdr);
  border-left: 4px solid var(--red);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.alert-high-title { font-size: 0.9rem; font-weight: 700; color: var(--red-d); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.alert-high p { font-size: 0.81rem; color: #7f1d1d; line-height: 1.6; }
.stats-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.stat-pill {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 7px 14px;
  font-size: 0.78rem; color: var(--text-muted);
}
.stat-pill strong { color: var(--navy-mid); font-weight: 700; }

/* 19 ── Upload / Hero --------------------------------------- */
.hero { text-align: center; padding: 8px 0 24px; }
.hero-title { font-size: 1.55rem; font-weight: 800; color: var(--navy); line-height: 1.2; }
.hero-sub   { font-size: 0.88rem; color: var(--text-muted); margin-top: 6px; }
.hero-tags  { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }

/* 20 ── Inline Error Alert (form) --------------------------- */
.error-alert {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--red-bg); border: 1.5px solid var(--red-bdr);
  border-radius: var(--r-sm); padding: 13px 16px;
  margin-bottom: 18px; color: var(--red-d); font-size: 0.875rem; font-weight: 500;
}
.error-alert::before { content: '⚠'; font-size: 1rem; flex-shrink: 0; margin-top: 1px; }

/* 21 ── Auth Pages ------------------------------------------ */
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  margin: 32px 20px;
}
.auth-header { text-align: center; margin-bottom: 28px; }
.auth-logo { width: 52px; height: 52px; background: var(--teal); border-radius: var(--r); display: flex; align-items: center; justify-content: center; font-size: 1.6rem; font-weight: 800; color: #fff; margin: 0 auto 14px; }
.auth-title { font-size: 1.35rem; font-weight: 800; color: var(--navy); }
.auth-sub   { font-size: 0.83rem; color: var(--text-muted); margin-top: 4px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 0.85rem; color: var(--text-muted); }
.auth-footer a { color: var(--teal); font-weight: 600; }

/* Flash messages inside auth pages: constrain width + adapt colors for dark background */
.site-main--auth > .container {
  max-width: 440px;
  width: 100%;
  padding-bottom: 0;
  margin-bottom: 0;
}
.site-main--auth .flash-warning { background: #3d2000; border-color: #f59e0b; color: #fde68a; }
.site-main--auth .flash-error,
.site-main--auth .flash-danger  { background: #3d0000; border-color: #ef4444; color: #fca5a5; }
.site-main--auth .flash-success { background: #003d20; border-color: #22c55e; color: #86efac; }
.site-main--auth .flash-info,
.site-main--auth .flash-message { background: #003d3d; border-color: #0ea5a0; color: #99e6e3; }

/* 22 ── Profile page ---------------------------------------- */
.profile-row { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.profile-row:last-of-type { border-bottom: none; }
.profile-key { width: 120px; flex-shrink: 0; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); }

/* 23 ── Section heading ------------------------------------- */
.section-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-muted); margin-bottom: 10px; }

/* 24 ── Responsive ------------------------------------------ */
@media (max-width: 720px) {
  .result-grid { grid-template-columns: 1fr; }
  .admin-nav { gap: 0; padding: 0 8px; }
  .admin-nav a { padding: 10px 10px; font-size: 0.8rem; }
}
@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .header-inner { height: 54px; }
  .site-main { padding: 20px 0 40px; }
  .logo-sub { display: none; }
  .hero-title { font-size: 1.25rem; }
  .auth-card { padding: 28px 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 360px) {
  .pipeline-row { flex-direction: column; }
  .pipeline-chip { flex-direction: row; justify-content: space-between; }
}
