/* ==========================================================================
   RenalDose Design System
   A precision clinical interface — Deep Medical Blue + Teal
   ========================================================================== */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400;1,500&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ==========================================================================
   1. Design Tokens (CSS Custom Properties)
   ========================================================================== */

:root {
    /* ---- Brand: Deep Medical Blue ---- */
    --brand-50:  #eff6ff;
    --brand-100: #dbeafe;
    --brand-200: #bfdbfe;
    --brand-300: #93c5fd;
    --brand-400: #60a5fa;
    --brand-500: #3b82f6;
    --brand-600: #2563eb;
    --brand-700: #1e40af;
    --brand-800: #1e3a8a;
    --brand-900: #172554;

    /* ---- Accent: Teal (Renal identity) ---- */
    --accent-50:  #ecfeff;
    --accent-100: #cffafe;
    --accent-200: #a5f3fc;
    --accent-300: #67e8f9;
    --accent-400: #22d3ee;
    --accent-500: #06b6d4;
    --accent-600: #0891b2;
    --accent-700: #0e7490;
    --accent-800: #155e75;
    --accent-900: #164e63;

    /* ---- Neutrals ---- */
    --gray-50:  #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --gray-950: #020617;

    /* ---- Clinical Status ---- */
    --status-safe:     #059669;
    --status-safe-bg:  #ecfdf5;
    --status-mild:     #0891b2;
    --status-mild-bg:  #ecfeff;
    --status-moderate: #d97706;
    --status-mod-bg:   #fffbeb;
    --status-severe:   #dc2626;
    --status-severe-bg:#fef2f2;
    --status-critical: #7c2d12;
    --status-crit-bg:  #fef2f2;

    /* ---- Semantic Colors (Light) ---- */
    --primary-color:  var(--brand-600);
    --primary-hover:  var(--brand-700);
    --primary-light:  var(--brand-100);
    --secondary-color:var(--gray-500);
    --accent-color:   var(--accent-600);
    --success-color:  var(--status-safe);
    --warning-color:  var(--status-moderate);
    --error-color:    #dc2626;
    --danger-color:   #b91c1c;

    /* ---- Backgrounds ---- */
    --bg-body:      #f8fafd;
    --bg-primary:   #ffffff;
    --bg-secondary: var(--gray-50);
    --bg-tertiary:  var(--gray-100);
    --bg-overlay:   rgba(15, 23, 42, 0.55);
    --bg-header:    rgba(255, 255, 255, 0.82);

    /* ---- Text ---- */
    --text-primary:   var(--gray-900);
    --text-secondary: var(--gray-600);
    --text-tertiary:  var(--gray-500);
    --text-inverse:   #ffffff;
    --text-brand:     var(--brand-700);

    /* ---- Borders ---- */
    --border-primary:   var(--gray-200);
    --border-secondary: var(--gray-300);
    --border-focus:     var(--brand-500);

    /* ---- Typography ---- */
    --font-sans:  'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

    --text-xs:   0.75rem;
    --text-sm:   0.875rem;
    --text-base: 1rem;
    --text-lg:   1.125rem;
    --text-xl:   1.25rem;
    --text-2xl:  1.5rem;
    --text-3xl:  1.875rem;
    --text-4xl:  2.25rem;

    --leading-tight:  1.25;
    --leading-normal: 1.5;
    --leading-relaxed:1.625;

    --tracking-tight:  -0.025em;
    --tracking-normal:  0;
    --tracking-wide:    0.025em;

    /* ---- Spacing ---- */
    --space-xs:  0.25rem;
    --space-sm:  0.5rem;
    --space-md:  1rem;
    --space-lg:  1.5rem;
    --space-xl:  2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* ---- Border Radius ---- */
    --radius-sm:   4px;
    --radius-md:   8px;
    --radius-lg:   12px;
    --radius-xl:   16px;
    --radius-full: 9999px;

    /* ---- Shadows ---- */
    --shadow-xs:  0 1px 2px rgba(0,0,0,0.02);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
    --shadow-md:  0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.03);
    --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.06), 0 4px 6px -4px rgba(0,0,0,0.03);
    --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.06), 0 8px 10px -6px rgba(0,0,0,0.03);
    --shadow-inner: inset 0 2px 4px rgba(0,0,0,0.02);
    --shadow-ring:  0 0 0 3px rgba(37, 99, 235, 0.1);
    --shadow-ring-accent: 0 0 0 3px rgba(8, 145, 178, 0.1);

    /* ---- Transitions ---- */
    --transition-fast:   150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow:   300ms ease;

    /* ---- Z-Index Scale ---- */
    --z-base:     1;
    --z-dropdown: 50;
    --z-sticky:   100;
    --z-header:   200;
    --z-overlay:  500;
    --z-modal:    600;
    --z-toast:    700;

    /* ---- Layout ---- */
    --header-h:   64px;
    --sidebar-w:  340px;
    --max-content:1280px;

    /* ---- Theme transition ---- */
    --theme-transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ==========================================================================
   2. Dark Mode
   ========================================================================== */

[data-theme="dark"] {
    --primary-color:  var(--brand-400);
    --primary-hover:  var(--brand-300);
    --primary-light:  rgba(59,130,246,0.15);
    --accent-color:   var(--accent-400);
    --success-color:  #34d399;
    --warning-color:  #fbbf24;
    --error-color:    #f87171;

    --bg-body:      #0c1222;
    --bg-primary:   #111827;
    --bg-secondary: #1a2332;
    --bg-tertiary:  #243044;
    --bg-overlay:   rgba(0, 0, 0, 0.65);
    --bg-header:    rgba(17, 24, 39, 0.85);

    --text-primary:   #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary:  #94a3b8;
    --text-inverse:   #0f172a;
    --text-brand:     var(--brand-300);

    --border-primary:   #1e293b;
    --border-secondary: #334155;
    --border-focus:     var(--brand-400);

    --shadow-xs:  0 1px 2px rgba(0,0,0,0.1);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.15), 0 1px 2px rgba(0,0,0,0.1);
    --shadow-md:  0 4px 6px -1px rgba(0,0,0,0.15), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.2), 0 4px 6px -4px rgba(0,0,0,0.1);
    --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.2), 0 8px 10px -6px rgba(0,0,0,0.1);

    --status-safe-bg:  rgba(5,150,105,0.12);
    --status-mild-bg:  rgba(8,145,178,0.12);
    --status-mod-bg:   rgba(217,119,6,0.12);
    --status-severe-bg:rgba(220,38,38,0.12);
    --status-crit-bg:  rgba(124,45,18,0.12);
}

/* ==========================================================================
   3. CSS Reset
   ========================================================================== */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-body);
    min-height: 100vh;
    transition: var(--theme-transition);
}

img, svg { display: block; max-width: 100%; }
a { color: var(--primary-color); text-decoration: none; }
a:hover { color: var(--primary-hover); }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
h1, h2, h3, h4, h5, h6 { line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); color: var(--text-primary); }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }

/* ==========================================================================
   4. Typography
   ========================================================================== */

h1 { font-size: var(--text-2xl); font-weight: 700; }
h2 { font-size: var(--text-xl);  font-weight: 700; }
h3 { font-size: var(--text-lg);  font-weight: 600; }
h4 { font-size: var(--text-base);font-weight: 600; }

.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }
.text-mono { font-family: var(--font-mono); }

/* ==========================================================================
   5. Header & Navigation
   ========================================================================== */

.header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    height: var(--header-h);
    background: var(--bg-header);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-primary);
    transition: var(--theme-transition);
}

.header-content {
    max-width: var(--max-content);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    gap: var(--space-md);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
    flex-shrink: 0;
}

.header-brand-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.header-brand-icon {
    width: 32px;
    height: 32px;
    background: var(--brand-600);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.header-brand-icon svg {
    width: 18px;
    height: 18px;
}

.header-brand-text {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: var(--tracking-tight);
}

.header-brand-text span {
    color: var(--accent-600);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.header-nav a {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    transition: color var(--transition-fast), background var(--transition-fast);
}

.header-nav a:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header-text {
    display: none;
}

/* ==========================================================================
   6. Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: 600;
    line-height: 1;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
    outline: none;
}

.btn:focus-visible {
    box-shadow: var(--shadow-ring);
}

.btn-primary {
    background: var(--brand-600);
    color: white;
    border-color: var(--brand-600);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--brand-700);
    border-color: var(--brand-700);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border-color: var(--border-primary);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.btn-accent {
    background: var(--accent-600);
    color: white;
    border-color: var(--accent-600);
    box-shadow: var(--shadow-sm);
}

.btn-accent:hover {
    background: var(--accent-700);
    border-color: var(--accent-700);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

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

.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-sm {
    font-size: var(--text-xs);
    padding: 6px 12px;
}

.btn-lg {
    font-size: var(--text-base);
    padding: 14px 28px;
    border-radius: var(--radius-lg);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

/* Theme toggle */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.theme-icon { display: flex; align-items: center; }
.theme-icon svg { width: 16px; height: 16px; }

/* ==========================================================================
   7. Form Controls
   ========================================================================== */

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
    outline: none;
}

.form-control::placeholder {
    color: var(--gray-400);
}

.form-control:hover {
    border-color: var(--border-secondary);
}

.form-control:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-ring);
    background: var(--bg-primary);
}

.form-control:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-tertiary);
}

select.form-control,
select {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    background-size: 16px !important;
    padding-right: 38px !important;
    cursor: pointer;
}
select::-ms-expand { display: none !important; }

select.form-control:focus,
select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] select.form-control,
[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
}

[data-theme="dark"] select.form-control:focus,
[data-theme="dark"] select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2360a5fa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
}

.help-text {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin-top: 4px;
    line-height: var(--leading-relaxed);
}

/* ==========================================================================
   8. Page Layout
   ========================================================================== */

.main-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-wrapper {
    display: flex;
    flex: 1;
    max-width: var(--max-content);
    margin: 0 auto;
    width: 100%;
    padding: 0;
}

/* ---------- Sidebar ---------- */

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-right: 1px solid var(--border-primary);
    background: var(--bg-primary);
    overflow-y: auto;
    height: calc(100vh - var(--header-h));
    position: sticky;
    top: var(--header-h);
    transition: var(--theme-transition);
}

.sidebar-content {
    padding: var(--space-xl);
}

.sidebar-content > h2 {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--brand-600);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.input-section {
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
}

.input-header {
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.input-header::before {
    content: '';
    width: 3px;
    height: 14px;
    border-radius: 2px;
    background: var(--brand-500);
    flex-shrink: 0;
}

.sidebar-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-primary);
}

.sidebar-actions .btn {
    flex: 1;
    padding: 12px 16px;
    white-space: normal;
    text-align: center;
    line-height: var(--leading-tight);
}

/* Prevent sidebar overflow */
.sidebar-content {
    overflow: hidden;
}

/* ---------- Main content ---------- */

.main-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: var(--space-xl);
    background: var(--bg-body);
}

/* ==========================================================================
   9. Medication Search & Selection
   ========================================================================== */

.medication-select-container {
    position: relative;
}

.medication-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: var(--z-dropdown);
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 260px;
    overflow-y: auto;
    display: none;
    margin-top: 4px;
}

.medication-dropdown.active {
    display: block;
}

.medication-option {
    padding: 10px 14px;
    font-size: var(--text-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-primary);
}

.medication-option:last-child {
    border-bottom: none;
}

.medication-option:hover {
    background: var(--brand-50);
    color: var(--brand-700);
}

[data-theme="dark"] .medication-option:hover {
    background: var(--primary-light);
    color: var(--brand-300);
}

.medication-option.selected {
    background: var(--brand-100);
    color: var(--brand-700);
    font-weight: 600;
}

[data-theme="dark"] .medication-option.selected {
    background: var(--primary-light);
    color: var(--brand-300);
}

.selected-medications {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    min-height: 0;
}

.medication-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--brand-100);
    color: var(--brand-700);
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: var(--radius-full);
    border: 1px solid var(--brand-200);
    transition: all var(--transition-fast);
}

[data-theme="dark"] .medication-tag {
    background: var(--primary-light);
    color: var(--brand-300);
    border-color: rgba(59,130,246,0.3);
}

.medication-tag button,
.medication-tag .remove-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}

.medication-tag button:hover,
.medication-tag .remove-btn:hover {
    opacity: 1;
}

/* ==========================================================================
  10. Results Container & Action Bar
   ========================================================================== */

.results-container {
    display: none;
    animation: fadeIn 0.3s ease;
}

/* Pro Action Bar */
.action-bar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-lg);
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.action-bar .btn {
    font-size: var(--text-xs);
    padding: 8px 14px;
}

.action-bar .btn-locked {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    border: 1px solid var(--border-primary);
    position: relative;
}

.action-bar .btn-locked:hover {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-color: var(--border-secondary);
}

.action-bar .btn-locked .lock-icon {
    width: 12px;
    height: 12px;
    opacity: 0.6;
}

.action-bar-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: auto;
}

/* ==========================================================================
  11. Medication Cards
   ========================================================================== */

.medication-recommendations {
    margin-bottom: var(--space-xl);
}

.medication-recommendations > h2 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-lg);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.medication-results-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.medication-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
    contain: layout style paint;
}

.medication-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-secondary);
}

.medication-header {
    padding: var(--space-md) var(--space-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background var(--transition-fast);
    border-left: 4px solid var(--accent-600);
}

.medication-header:hover {
    background: var(--bg-secondary);
}

.medication-header h3 {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.expand-icon {
    display: flex;
    align-items: center;
    transition: transform var(--transition-normal);
    color: var(--text-tertiary);
}

.medication-header.expanded .expand-icon,
.expanded > .medication-header .expand-icon {
    transform: rotate(180deg);
}

.medication-content {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s ease, border-top-color 0.3s ease;
    border-top: 1px solid transparent;
}

.medication-content-inner {
    min-height: 0;
    overflow: hidden;
    padding: 0 var(--space-lg);
}

.medication-content.expanded {
    grid-template-rows: 1fr;
    border-top-color: var(--border-primary);
}

.medication-content.expanded .medication-content-inner {
    padding: var(--space-lg);
}

.medication-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
}

.rfe-section h4,
.dosing-section h4 {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* ==========================================================================
  12. Metrics & Clinical Data Display
   ========================================================================== */

.metric {
    margin-bottom: var(--space-md);
}

.metric-value {
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-brand);
    letter-spacing: var(--tracking-tight);
}

.metric-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 2px;
}

.metric-help {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin-top: 4px;
    font-style: italic;
}

.metric-unit {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--accent-600);
    margin-top: 4px;
}

/* Recommendation boxes */
.recommendation-box {
    padding: var(--space-md);
    background: var(--status-mod-bg);
    border: 1px solid rgba(217, 119, 6, 0.2);
    border-left: 4px solid var(--status-moderate);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
}

.recommendation-box p { color: var(--text-primary); }
.recommendation-box strong { color: var(--status-moderate); }

.no-adjustment-box {
    padding: var(--space-md);
    background: var(--status-safe-bg);
    border: 1px solid rgba(5, 150, 105, 0.2);
    border-left: 4px solid var(--status-safe);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.no-adjustment-box p { color: var(--text-primary); }
.no-adjustment-box strong { color: var(--status-safe); }

.dosing-limit {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-md);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-primary);
}

.warning-note {
    padding: var(--space-md);
    background: var(--status-mod-bg);
    border: 1px solid rgba(217, 119, 6, 0.2);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--text-primary);
    margin-top: var(--space-md);
    line-height: var(--leading-relaxed);
}

/* ---- Dosing Discordance Panel ---- */

.discordance-alert {
    margin-top: var(--space-lg);
    padding: var(--space-lg);
    border: 2px solid var(--status-moderate);
    border-radius: var(--radius-lg);
    background-color: var(--status-mod-bg);
}

[data-theme="dark"] .discordance-alert {
    background-color: rgba(217, 119, 6, 0.08);
}

.discordance-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--status-moderate);
    margin-bottom: var(--space-xs);
}

.discordance-header svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.discordance-subtext {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
    line-height: var(--leading-relaxed);
}

.discordance-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: var(--space-md);
    align-items: stretch;
    margin-bottom: var(--space-lg);
}

.discordance-col {
    padding: var(--space-md);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
}

.discordance-col-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    color: var(--text-tertiary);
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.discordance-col-method {
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: var(--space-sm);
}

.discordance-col-value {
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
}

.discordance-col-value small {
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--text-secondary);
}

.discordance-col-rec {
    font-size: var(--text-sm);
    color: var(--text-primary);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
    line-height: var(--leading-relaxed);
}

.discordance-label .discordance-col-rec {
    border-left: 3px solid var(--brand-500);
    background: var(--brand-50);
}

.discordance-nkf .discordance-col-rec {
    border-left: 3px solid var(--status-moderate);
    background: var(--status-mod-bg);
}

[data-theme="dark"] .discordance-label .discordance-col-rec {
    background: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .discordance-nkf .discordance-col-rec {
    background: rgba(217, 119, 6, 0.1);
}

.discordance-col-source {
    font-size: 11px;
    font-style: italic;
    color: var(--text-tertiary);
    line-height: var(--leading-relaxed);
}

.discordance-vs {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: var(--text-lg);
    color: var(--text-tertiary);
}

.discordance-note {
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
}

.discordance-note strong {
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .discordance-grid {
        grid-template-columns: 1fr;
    }

    .discordance-vs {
        padding: var(--space-xs) 0;
    }
}

.uptodate-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    margin-top: var(--space-md);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--accent-600);
    transition: color var(--transition-fast);
}

.uptodate-link:hover {
    color: var(--accent-700);
}

/* ==========================================================================
  13. Clinical Profile & Tabs
   ========================================================================== */

.patient-profile {
    margin-top: var(--space-xl);
}

.patient-profile > h2 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--border-primary);
    margin-bottom: var(--space-lg);
}

.tab-button {
    padding: 10px 20px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    cursor: pointer;
    position: relative;
    transition: color var(--transition-fast);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tab-button:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.tab-button.active {
    color: var(--brand-600);
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--brand-600);
    border-radius: 2px 2px 0 0;
}

.tab-content {
    display: none;
    animation: fadeIn 0.25s ease;
}

.tab-content.active {
    display: block;
}

/* Profile grid */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
}

.profile-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-normal);
    contain: layout style paint;
}

.profile-card:hover {
    box-shadow: var(--shadow-md);
}

.profile-header {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.info-box {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-sm);
    border: 1px solid var(--border-primary);
}

/* Chart */
.chart-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    height: 350px;
    contain: layout style;
}

/* ==========================================================================
  14. Loading Screen
   ========================================================================== */

.loading-screen {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    contain: strict;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--brand-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--space-md);
}

.loading-content p {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==========================================================================
  15. Initial Instructions & Warnings
   ========================================================================== */

.initial-instructions {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.instruction-content {
    max-width: 480px;
    text-align: center;
    padding: var(--space-2xl);
}

.instruction-content h3 {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-lg);
}

.instruction-list {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.instruction-list li {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: var(--text-base);
    color: var(--text-secondary);
    padding: var(--space-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.instruction-list li:hover {
    border-color: var(--brand-300);
    box-shadow: var(--shadow-sm);
}

.instruction-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--brand-100);
    color: var(--brand-600);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.instruction-icon svg {
    width: 18px;
    height: 18px;
}

.warning-message {
    display: none;
    padding: var(--space-md) var(--space-lg);
    background: var(--status-mod-bg);
    border: 1px solid rgba(217, 119, 6, 0.25);
    border-left: 4px solid var(--status-moderate);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
}

.warning-message p {
    font-size: var(--text-sm);
    color: var(--text-primary);
}

/* ==========================================================================
  16. Footer
   ========================================================================== */

.footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-primary);
    padding: var(--space-xl) var(--space-lg);
    margin-top: auto;
    transition: var(--theme-transition);
}

.footer-content {
    max-width: var(--max-content);
    margin: 0 auto;
}

.footer-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: var(--space-lg);
}

.footer-brand {
    flex-shrink: 0;
}

.footer-brand-name {
    font-size: var(--text-lg);
    font-weight: 800;
    font-family: var(--font-sans);
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
    letter-spacing: -0.02em;
}

.footer-brand-desc {
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    color: var(--text-tertiary);
    max-width: 300px;
    line-height: 1.6;
}

.footer-links {
    display: flex;
    gap: var(--space-2xl);
}

.footer-links-group h4 {
    font-size: 11px;
    font-weight: 800;
    font-family: var(--font-sans);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
}

.footer-links-group a {
    display: block;
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--text-secondary);
    padding: 4px 0;
    transition: color var(--transition-fast);
}

.footer-links-group a:hover {
    color: var(--brand-500);
}

.footer-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-md);
}

.footer-copyright {
    font-size: var(--text-xs);
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--text-tertiary);
    letter-spacing: 0.01em;
}

.footer-disclaimer {
    font-size: var(--text-xs);
    font-family: var(--font-sans);
    font-weight: 400;
    color: var(--text-tertiary);
    font-style: italic;
    max-width: 500px;
    line-height: 1.6;
}

/* Legacy footer elements */
.disclaimer-section { margin-top: var(--space-md); }

.disclaimer-details {
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    box-shadow: var(--shadow-sm);
}

.disclaimer-summary {
    padding: var(--space-md) var(--space-lg);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: 700;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    transition: color var(--transition-fast), background var(--transition-fast);
    border-radius: var(--radius-lg);
    letter-spacing: 0.01em;
}

.disclaimer-summary:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.disclaimer-content {
    padding: 0 var(--space-lg) var(--space-lg);
}

.warning-box,
.disclaimer-content .info-box {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    line-height: 1.7;
    margin-bottom: var(--space-md);
    letter-spacing: 0.01em;
}

.warning-box {
    background-color: rgba(254,243,199,0.6);
    border: 1px solid rgba(217,119,6,0.15);
    border-left: 4px solid #d97706;
    color: var(--text-primary);
}

[data-theme="dark"] .warning-box {
    background-color: rgba(120,53,15,0.2);
    border-color: rgba(217,119,6,0.25);
    border-left-color: #f59e0b;
}

.disclaimer-content .info-box {
    background-color: rgba(239,246,255,0.6);
    border: 1px solid rgba(37,99,235,0.1);
    border-left: 4px solid var(--brand-400);
}

[data-theme="dark"] .disclaimer-content .info-box {
    background-color: rgba(30,58,138,0.15);
    border-color: rgba(96,165,250,0.15);
    border-left-color: var(--brand-500);
}

/* ==========================================================================
  17. Inline SVG Icons
   ========================================================================== */

.icon-inline {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
}

.icon-inline.chevron {
    transition: transform var(--transition-normal);
}

/* ==========================================================================
  18. Animations
   ========================================================================== */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.pulse { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }

/* ==========================================================================
  19. Responsive
   ========================================================================== */

@media (max-width: 1024px) {
    .content-wrapper {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        top: 0;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
    }

    .sidebar-content {
        padding: var(--space-lg);
    }

    .main-content {
        padding: var(--space-lg);
    }

    .medication-grid {
        grid-template-columns: 1fr;
    }

    .profile-grid {
        grid-template-columns: 1fr 1fr;
    }

    .footer-top {
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    :root {
        --header-h: 56px;
    }

    .header-nav {
        display: none;
    }

    .header-brand-text {
        font-size: var(--text-base);
    }

    .profile-grid {
        grid-template-columns: 1fr;
    }

    .action-bar {
        flex-wrap: wrap;
    }

    .footer-links {
        flex-direction: column;
        gap: var(--space-lg);
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
    }

    .sidebar-content {
        padding: var(--space-md);
    }

    .main-content {
        padding: var(--space-md);
    }

    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-button {
        white-space: nowrap;
        padding: 8px 14px;
    }
}

@media (max-width: 480px) {
    html { font-size: 15px; }

    .sidebar-actions {
        flex-direction: column;
    }

    .chart-container {
        height: 280px;
    }

    .instruction-content {
        padding: var(--space-lg);
    }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    .btn, .tab-button, .medication-option, .form-control {
        min-height: 44px;
    }

    .btn:active { transform: scale(0.98); }
}

/* ==========================================================================
  20. Accessibility
   ========================================================================== */

.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--brand-500);
    outline-offset: 2px;
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: var(--space-md);
    background: var(--brand-600);
    color: white;
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    border-radius: var(--radius-md);
    z-index: 1000;
    font-size: var(--text-sm);
    font-weight: 600;
}

.skip-link:focus { top: var(--space-md); color: white; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast */
@media (prefers-contrast: high) {
    :root {
        --border-primary: #000;
        --border-secondary: #000;
        --shadow-sm: none;
        --shadow-md: none;
        --shadow-lg: none;
    }
}

/* ==========================================================================
  21. Print
   ========================================================================== */

@media print {
    .header, .sidebar-actions, .theme-toggle, .action-bar,
    .footer, .initial-instructions, .cookie-banner { display: none !important; }

    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        border: none;
        page-break-after: always;
    }

    .main-content { padding: 0; }

    .medication-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .medication-content { grid-template-rows: 1fr !important; border-top-color: var(--border-primary) !important; }
    .medication-content-inner { padding: 12px !important; }

    body { background: white; color: black; font-size: 12pt; }
}
