/* ============================================================
   NIAMR DESIGN SYSTEM — core variables, resets, components
   Aesthetic: Precision Medical Dark — clinical authority with
   warmth. Inspired by high-end medical imaging software.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@300;400;500;600&family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,600;1,9..144,300&display=swap');

:root {
  /* Background scale */
  --bg-0: #060b10;
  --bg-1: #0a1118;
  --bg-2: #0e1822;
  --bg-3: #12202e;
  --bg-4: #172638;
  --bg-5: #1c2e42;

  /* Surface & borders */
  --surface-1: #1a2a3a;
  --surface-2: #1f3347;
  --border-1: #1e3348;
  --border-2: #264257;
  --border-focus: rgba(0,200,230,0.5);

  /* Primary accent — Teal/Cyan (medical clarity) */
  --accent:       #00c8e6;
  --accent-dim:   rgba(0,200,230,0.12);
  --accent-glow:  rgba(0,200,230,0.25);

  /* Status colors */
  --success:  #22d68a;
  --warning:  #f5a623;
  --danger:   #e63946;
  --info:     #4a9eff;
  --critical: #ff3860;

  /* AMR risk tier colors */
  --risk-green:  #22d68a;
  --risk-yellow: #f5a623;
  --risk-red:    #e63946;
  --risk-purple: #c084fc;

  /* Text */
  --text-1: #e8f0f8;
  --text-2: #9ab3cc;
  --text-3: #5a7a96;
  --text-4: #3a566e;

  /* Specialty colors */
  --php-color:     #8b92d9;
  --flutter-color: #54c5f8;
  --python-color:  #fbbf24;

  /* Typography */
  --font-display: 'Fraunces', serif;
  --font-body:    'Outfit', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 9999px;

  /* Transitions */
  --t-fast: 0.12s ease;
  --t-mid:  0.22s ease;
  --t-slow: 0.4s cubic-bezier(0.16, 1, 0.3, 1);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.35);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.45);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.55);
  --shadow-glow: 0 0 30px rgba(0,200,230,0.15);

  /* Layout */
  --sidebar-w: 260px;
  --header-h:  60px;
}

/* ======= RESET ======= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 15px; }
body {
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font-body);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: var(--font-body); border: none; background: none; }
input, select, textarea { font-family: var(--font-body); }
img { max-width: 100%; }
ul, ol { list-style: none; }

/* ======= SCROLLBAR ======= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ======= TYPOGRAPHY ======= */
.display-lg { font-family: var(--font-display); font-size: 3.2rem; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.display-md { font-family: var(--font-display); font-size: 2.2rem; font-weight: 600; line-height: 1.2; }
.display-sm { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.3rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
h4 { font-size: 0.95rem; font-weight: 600; }
.mono { font-family: var(--font-mono); }
.caption { font-size: 0.8rem; color: var(--text-3); }
.label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-3); }

/* ======= BUTTONS ======= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--r-md); font-size: 0.875rem;
  font-weight: 600; transition: all var(--t-mid); position: relative;
  white-space: nowrap; letter-spacing: 0.01em;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #0099b3 100%);
  color: var(--bg-0); box-shadow: 0 4px 16px rgba(0,200,230,0.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(0,200,230,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: var(--surface-1); color: var(--text-1);
  border: 1px solid var(--border-2);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }
.btn-danger { background: rgba(230,57,70,0.15); color: var(--danger); border: 1px solid rgba(230,57,70,0.3); }
.btn-danger:hover { background: rgba(230,57,70,0.25); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { color: var(--accent); background: var(--accent-dim); border-radius: var(--r-md); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 13px 28px; font-size: 1rem; }
.btn-icon { padding: 8px; border-radius: var(--r-md); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }

/* ======= FORM ELEMENTS ======= */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.8rem; font-weight: 600; color: var(--text-2); letter-spacing: 0.03em; }
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
  background: var(--bg-2); border: 1px solid var(--border-1);
  border-radius: var(--r-md); padding: 10px 14px;
  color: var(--text-1); font-size: 0.9rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-input::placeholder { color: var(--text-4); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235a7a96' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.form-textarea { resize: vertical; min-height: 90px; }
.form-hint { font-size: 0.78rem; color: var(--text-3); }
.form-error { font-size: 0.78rem; color: var(--danger); }
.input-group { position: relative; }
.input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon + .form-input { padding-left: 38px; }

/* ======= CARDS ======= */
.card {
  background: var(--bg-2); border: 1px solid var(--border-1);
  border-radius: var(--r-lg); padding: var(--space-5);
  transition: border-color var(--t-mid);
}
.card:hover { border-color: var(--border-2); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-1); }
.card-subtitle { font-size: 0.8rem; color: var(--text-3); margin-top: 2px; }

/* STAT CARDS */
.stat-card {
  background: var(--bg-2); border: 1px solid var(--border-1);
  border-radius: var(--r-lg); padding: var(--space-5);
  position: relative; overflow: hidden;
  transition: transform var(--t-mid), box-shadow var(--t-mid);
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--stat-color, var(--accent));
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; margin: 8px 0 4px; color: var(--text-1); font-family: var(--font-mono); }
.stat-label { font-size: 0.78rem; color: var(--text-3); font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
.stat-change { font-size: 0.8rem; font-weight: 600; margin-top: 8px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }
.stat-icon { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font-size: 2.5rem; opacity: 0.07; }

/* ======= BADGES ======= */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
}
.badge-success  { background: rgba(34,214,138,0.12); color: var(--success); border: 1px solid rgba(34,214,138,0.25); }
.badge-warning  { background: rgba(245,166,35,0.12); color: var(--warning); border: 1px solid rgba(245,166,35,0.25); }
.badge-danger   { background: rgba(230,57,70,0.12); color: var(--danger); border: 1px solid rgba(230,57,70,0.25); }
.badge-info     { background: rgba(74,158,255,0.12); color: var(--info); border: 1px solid rgba(74,158,255,0.25); }
.badge-neutral  { background: var(--surface-1); color: var(--text-2); border: 1px solid var(--border-1); }
.badge-accent   { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent-glow); }
.badge-dot::before { content: '●'; font-size: 7px; }

/* ======= TABLES ======= */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border-1); }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--bg-3); }
.data-table th { padding: 11px 16px; text-align: left; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-3); border-bottom: 1px solid var(--border-1); white-space: nowrap; }
.data-table td { padding: 13px 16px; font-size: 0.87rem; color: var(--text-1); border-bottom: 1px solid rgba(30,51,72,0.5); vertical-align: middle; }
.data-table tbody tr { transition: background var(--t-fast); }
.data-table tbody tr:hover { background: var(--bg-3); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ======= ALERTS / NOTIFICATIONS ======= */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 18px; border-radius: var(--r-md);
  font-size: 0.875rem; border-left: 3px solid;
}
.alert-success { background: rgba(34,214,138,0.07); border-color: var(--success); color: var(--success); }
.alert-warning { background: rgba(245,166,35,0.07); border-color: var(--warning); color: var(--warning); }
.alert-danger  { background: rgba(230,57,70,0.07); border-color: var(--danger); color: var(--danger); }
.alert-info    { background: rgba(74,158,255,0.07); border-color: var(--info); color: var(--info); }
.alert-body { color: var(--text-1); }
.alert-body p { color: var(--text-2); font-size: 0.82rem; margin-top: 3px; }

/* ======= TABS ======= */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-1); margin-bottom: var(--space-5); }
.tab { padding: 10px 18px; font-size: 0.875rem; font-weight: 500; color: var(--text-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all var(--t-fast); }
.tab:hover { color: var(--text-1); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ======= MODAL ======= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(4px);
  z-index: 1000; display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; animation: fadeIn 0.18s ease; }
.modal {
  background: var(--bg-2); border: 1px solid var(--border-2);
  border-radius: var(--r-xl); padding: var(--space-6);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.25s cubic-bezier(0.16,1,0.3,1);
  box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-5); }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: var(--r-md); display: flex; align-items: center; justify-content: center; color: var(--text-3); transition: all var(--t-fast); }
.modal-close:hover { background: var(--bg-3); color: var(--text-1); }
.modal-lg { max-width: 820px; }
.modal-xl { max-width: 1100px; }

/* ======= PROGRESS / LOADING ======= */
.progress-bar { height: 6px; background: var(--bg-4); border-radius: var(--r-full); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--r-full); background: linear-gradient(90deg, var(--accent), var(--success)); transition: width 0.6s ease; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-4) 50%, var(--bg-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-md); }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ======= SIDEBAR ======= */
.sidebar {
  width: var(--sidebar-w); background: var(--bg-1);
  border-right: 1px solid var(--border-1);
  display: flex; flex-direction: column;
  position: fixed; left: 0; top: 0; bottom: 0;
  z-index: 100; transition: transform var(--t-slow);
}
.sidebar-logo { padding: 20px; border-bottom: 1px solid var(--border-1); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-section { padding: 16px 16px 6px; }
.nav-section-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-4); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: var(--r-md); margin: 1px 8px;
  font-size: 0.875rem; font-weight: 500; color: var(--text-2);
  cursor: pointer; transition: all var(--t-fast); position: relative;
}
.nav-item:hover { background: var(--bg-3); color: var(--text-1); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item.active::before { content: ''; position: absolute; left: -8px; top: 50%; transform: translateY(-50%); width: 3px; height: 20px; background: var(--accent); border-radius: 0 2px 2px 0; }
.nav-item .nav-badge { margin-left: auto; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

/* ======= TOPBAR ======= */
.topbar {
  height: var(--header-h); background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
  display: flex; align-items: center; padding: 0 var(--space-5);
  gap: var(--space-4); position: sticky; top: 0; z-index: 90;
  /* margin-left: var(--sidebar-w); */
}

/* ======= MAIN LAYOUT ======= */
.main-layout { display: flex; min-height: 100vh; }
.main-content { flex: 1; margin-left: var(--sidebar-w); min-height: 100vh; background: var(--bg-0); }
.page-content { padding: var(--space-6); }
.page-header { margin-bottom: var(--space-6); }
.page-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.page-subtitle { color: var(--text-3); font-size: 0.87rem; }

/* ======= GRID LAYOUTS ======= */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-5); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-5); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-5 { gap: 24px; }

/* ======= RISK INDICATORS ======= */
.risk-badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: var(--r-full); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.risk-low    { background: rgba(34,214,138,0.12); color: var(--risk-green);  }
.risk-medium { background: rgba(245,166,35,0.12);  color: var(--risk-yellow); }
.risk-high   { background: rgba(230,57,70,0.12);   color: var(--risk-red);    }
.risk-critical { background: rgba(192,132,252,0.12); color: var(--risk-purple); animation: pulse-border 2s infinite; }
@keyframes pulse-border { 0%,100%{box-shadow:none} 50%{box-shadow:0 0 0 3px rgba(192,132,252,0.2)} }

/* ======= TOOLTIP ======= */
[data-tooltip] { position: relative; }
[data-tooltip]::after { content: attr(data-tooltip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--bg-5); color: var(--text-1); font-size: 0.75rem; padding: 5px 10px; border-radius: var(--r-sm); white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity var(--t-fast); border: 1px solid var(--border-2); z-index: 200; }
[data-tooltip]:hover::after { opacity: 1; }

/* ======= ANIMATIONS ======= */
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
@keyframes slideUp { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }
@keyframes slideIn { from{opacity:0;transform:translateX(-20px)} to{opacity:1;transform:translateX(0)} }
@keyframes pulseDot { 0%,100%{transform:scale(1);opacity:1} 50%{transform:scale(1.3);opacity:0.7} }
.animate-fade { animation: fadeIn 0.3s ease both; }
.animate-slide-up { animation: slideUp 0.4s cubic-bezier(0.16,1,0.3,1) both; }
.stagger > * { animation: slideUp 0.4s cubic-bezier(0.16,1,0.3,1) both; }
.stagger > *:nth-child(1){animation-delay:0.05s}
.stagger > *:nth-child(2){animation-delay:0.1s}
.stagger > *:nth-child(3){animation-delay:0.15s}
.stagger > *:nth-child(4){animation-delay:0.2s}
.stagger > *:nth-child(5){animation-delay:0.25s}
.stagger > *:nth-child(6){animation-delay:0.3s}

/* ======= CHART CONTAINERS ======= */
.chart-container { position: relative; }
.chart-placeholder { background: var(--bg-3); border-radius: var(--r-md); display: flex; align-items: center; justify-content: center; color: var(--text-3); font-size: 0.85rem; }

/* ======= RESPONSIVE ======= */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: none; }
  .main-content { margin-left: 0; }
  .topbar { margin-left: 0; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .page-content { padding: var(--space-4); }
  .grid-4 { grid-template-columns: 1fr; }
}

/* ======= UTILITY ======= */
.mt-1{margin-top:4px} .mt-2{margin-top:8px} .mt-3{margin-top:12px} .mt-4{margin-top:16px} .mt-5{margin-top:24px} .mt-6{margin-top:32px}
.mb-1{margin-bottom:4px} .mb-2{margin-bottom:8px} .mb-3{margin-bottom:12px} .mb-4{margin-bottom:16px} .mb-5{margin-bottom:24px}
.p-0{padding:0} .p-4{padding:16px} .p-5{padding:24px}
.w-full{width:100%} .h-full{height:100%}
.text-center{text-align:center} .text-right{text-align:right}
.text-accent{color:var(--accent)} .text-success{color:var(--success)} .text-danger{color:var(--danger)} .text-warning{color:var(--warning)} .text-muted{color:var(--text-3)}
.font-mono{font-family:var(--font-mono)} .font-bold{font-weight:700}
.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.divider{height:1px;background:var(--border-1);margin:var(--space-4) 0}
.hidden{display:none!important} .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)}
.relative{position:relative} .overflow-hidden{overflow:hidden}
.rounded{border-radius:var(--r-md)} .rounded-lg{border-radius:var(--r-lg)}
.border{border:1px solid var(--border-1)} .border-accent{border:1px solid var(--accent-glow)}
