/* ═══════════════════════════════════════════════════════════
   Mother Passport — Shared Base Styles / Design System
   v2 (August 2026)

   LOAD ORDER CONTRACT (important):
   This file is always linked BEFORE responsive.css and before any
   page's own <style> block. That means page-specific rules win over
   anything here. So this file is a safe FOUNDATION: it sets global
   defaults and a component library, and never fights a page's own
   layout. Enhancements here only take visible effect where a page
   does NOT already define its own rule.

   Every selector from the original base.css is preserved with the
   same geometry, so the 3 pages that already linked base.css do not
   shift. New components and polish are additive.
   ═══════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────
   DESIGN TOKENS
   ───────────────────────────────────────────── */
:root {
    /* Brand palette (unchanged) */
    --rose: #C4576A;
    --rose-pale: #FDF2F4;
    --rose-light: #E8A0AD;
    --rose-dark: #A83E52;
    --slate: #2D3142;
    --text: #1A1A2E;
    --text-sec: #555770;
    --border: #E8E4DF;
    --cream: #FFF9F5;
    --sage: #7A9E7E;
    --sage-light: #E8F5E9;
    --gold: #D4A853;
    --gold-light: #FFF8E1;
    --page-bg: #F5F3EF;

    /* Semantic status colors */
    --success: #2E7D32;
    --success-bg: #E8F5E9;
    --success-border: #C8E6C9;
    --danger: #C62828;
    --danger-bg: #FFEBEE;
    --danger-border: #FFCDD2;
    --warning: #E65100;
    --warning-bg: #FFF8E1;
    --warning-border: #FFE0B2;
    --info: #1565C0;
    --info-bg: #E3F2FD;
    --info-border: #BBDEFB;

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;

    /* Radius scale */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 50px;

    /* Shadow scale */
    --shadow-sm: 0 1px 2px rgba(45, 49, 66, 0.06);
    --shadow: 0 2px 8px rgba(45, 49, 66, 0.08);
    --shadow-md: 0 4px 16px rgba(45, 49, 66, 0.10);
    --shadow-lg: 0 8px 32px rgba(45, 49, 66, 0.12);

    /* Type scale */
    --fs-xs: 11px;
    --fs-sm: 13px;
    --fs-base: 14px;
    --fs-md: 16px;
    --fs-lg: 20px;
    --fs-xl: 28px;

    /* Transition */
    --t-fast: 0.15s ease;
    --t: 0.2s ease;

    /* Focus ring (accessibility) */
    --focus-ring: 0 0 0 3px rgba(196, 87, 106, 0.35);
}

/* ─────────────────────────────────────────────
   RESET (unchanged geometry) + global polish
   ───────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--page-bg);
    color: var(--text);
    /* Global polish — pages don't override these, so they apply everywhere */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    line-height: 1.55;
}

img, video { max-width: 100%; height: auto; }

/* Brand text selection */
::selection { background: var(--rose-light); color: #fff; }

/* Consistent, subtle custom scrollbars (WebKit) — pure polish, non-breaking */
* {
    scrollbar-width: thin;
    scrollbar-color: #cfc9c2 transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: #d5cfc8;
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #bfb8af; background-clip: content-box; }

/* ─────────────────────────────────────────────
   ACCESSIBILITY — keyboard focus rings
   Applied only for keyboard users (:focus-visible), so mouse
   clicks stay clean. Pages rarely define this → global win.
   ───────────────────────────────────────────── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* ─────────────────────────────────────────────
   LAYOUT (unchanged geometry)
   ───────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.main { margin-left: 260px; flex: 1; padding: 32px 40px; }

/* ─────────────────────────────────────────────
   SIDEBAR (unchanged geometry, minor polish)
   ───────────────────────────────────────────── */
.sidebar {
    width: 260px;
    background: var(--slate);
    color: white;
    padding: 24px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-logo {
    font-family: 'DM Serif Display', serif;
    font-size: 20px;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo span { color: var(--rose); }

.sidebar-nav { list-style: none; }
.sidebar-nav li { margin-bottom: 4px; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,0.08);
    color: white;
}

.sidebar-doctor {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 13px;
    color: rgba(255,255,255,0.5);
}

.sidebar-doctor strong {
    color: white;
    display: block;
    margin-bottom: 2px;
}

/* ─────────────────────────────────────────────
   PAGE HEADER (unchanged geometry)
   ───────────────────────────────────────────── */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-family: 'DM Serif Display', serif; font-size: 28px; }
.page-header p { color: var(--text-sec); font-size: 14px; margin-top: 4px; }

/* ─────────────────────────────────────────────
   ALERTS (unchanged geometry)
   ───────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 10px; font-size: 13.5px; margin-bottom: 20px; font-weight: 500; }
.alert-success { background: var(--sage-light); color: #2E7D32; border: 1px solid #C8E6C9; }
.alert-danger { background: #FFEBEE; color: #C62828; border: 1px solid #FFCDD2; }
.alert-warning { background: var(--gold-light); color: #E65100; border: 1px solid #FFE0B2; }
.alert-info { background: #E3F2FD; color: #1565C0; border: 1px solid #BBDEFB; }

/* ─────────────────────────────────────────────
   BADGES (unchanged geometry)
   ───────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 50px; font-size: 11px; font-weight: 600; }
.badge-success { background: var(--sage-light); color: #2E7D32; }
.badge-danger { background: #FFEBEE; color: #C62828; }
.badge-warning { background: var(--gold-light); color: #E65100; }
.badge-info { background: #E3F2FD; color: #1565C0; }

/* ─────────────────────────────────────────────
   LINKS (unchanged geometry)
   ───────────────────────────────────────────── */
.link { color: var(--rose); text-decoration: none; font-weight: 600; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════════
   COMPONENT LIBRARY (ADDITIVE)
   These provide good defaults for the 3 pages already on base.css
   and any page we convert later. Pages with their own <style>
   still win, so this never overrides existing bespoke components.
   ═══════════════════════════════════════════════════════════ */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: transform var(--t-fast), box-shadow var(--t), background var(--t), border-color var(--t), color var(--t);
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn.disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--rose); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--rose-dark); box-shadow: var(--shadow); }

.btn-secondary { background: #fff; color: var(--slate); border-color: var(--border); }
.btn-secondary:hover { background: var(--rose-pale); border-color: var(--rose-light); color: var(--rose-dark); }

.btn-ghost { background: transparent; color: var(--rose); }
.btn-ghost:hover { background: var(--rose-pale); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a71d1d; }

.btn-success { background: var(--sage); color: #fff; }
.btn-success:hover { background: #5f8463; }

.btn-sm { padding: 7px 14px; font-size: var(--fs-sm); }
.btn-lg { padding: 13px 26px; font-size: var(--fs-md); }
.btn-block { display: flex; width: 100%; }

/* Cards */
.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: var(--fs-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); background: #fcfbfa; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label,
.form-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.form-control,
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    font-family: inherit;
    font-size: var(--fs-base);
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--t), box-shadow var(--t);
}
.form-control:focus,
.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--rose-light);
    box-shadow: var(--focus-ring);
}
.form-control::placeholder { color: #9a9aa8; }
.form-hint { font-size: var(--fs-xs); color: var(--text-sec); margin-top: 4px; }
.form-error { font-size: var(--fs-xs); color: var(--danger); margin-top: 4px; font-weight: 600; }
.form-control.is-invalid { border-color: var(--danger-border); }

/* Auto-calculated field indicator (BMI, eGFR) — sage per brief */
.field-auto {
    background: var(--sage-light) !important;
    border-color: #B6D8BA !important;
    color: var(--success);
    font-weight: 600;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-base);
}
.table thead th {
    text-align: left;
    padding: 12px 14px;
    background: #faf8f6;
    color: var(--text-sec);
    font-weight: 700;
    font-size: var(--fs-sm);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--rose-pale); }

/* Toast container (available for future use, hidden until populated) */
.toast-stack {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
}
.toast {
    background: #fff;
    border-left: 4px solid var(--rose);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: var(--fs-sm);
    animation: mp-toast-in var(--t);
}
.toast-success { border-left-color: var(--sage); }
.toast-danger { border-left-color: var(--danger); }
@keyframes mp-toast-in {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Utility helpers (opt-in, never applied automatically) */
.u-muted { color: var(--text-sec); }
.u-center { text-align: center; }
.u-mt-0 { margin-top: 0; }
.u-mb-0 { margin-bottom: 0; }
.u-flex { display: flex; }
.u-gap-2 { gap: 8px; }
.u-gap-3 { gap: 12px; }
.u-items-center { align-items: center; }
.u-justify-between { justify-content: space-between; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-sec);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.6; }

/* ─────────────────────────────────────────────
   PRINT — cleaner PDF/print export (global, safe)
   ───────────────────────────────────────────── */
@media print {
    .sidebar, .mobile-header, .header-actions, .btn, .no-print { display: none !important; }
    .main { margin-left: 0 !important; padding: 0 !important; }
    body { background: #fff !important; }
    .card, .table { box-shadow: none !important; }
}
