/* =========================================================
   ASMS — Ambulance Service Management System
   Design system + Light/Dark theme
   ========================================================= */

:root {
    /* Brand */
    --brand: #dc2626;
    --brand-600: #b91c1c;
    --brand-700: #991b1b;
    --brand-soft: #fef2f2;
    --accent: #2563eb;

    /* Light theme (default) */
    --bg: #f1f5f9;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);

    --ok: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;

    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 250px;
    --topbar-h: 60px;
    --font: 'Segoe UI', Roboto, system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
    --bg: #0b1120;
    --bg-elev: #111827;
    --surface: #111827;
    --surface-2: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --brand-soft: #2a1414;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0b1120;
        --bg-elev: #111827;
        --surface: #111827;
        --surface-2: #1e293b;
        --text: #e2e8f0;
        --text-muted: #94a3b8;
        --border: #1e293b;
        --brand-soft: #2a1414;
        --shadow: 0 1px 3px rgba(0, 0, 0, .4);
        --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
    }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 700; line-height: 1.25; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .5rem; justify-content: center;
    padding: .6rem 1.1rem; border-radius: var(--radius-sm); border: 1px solid transparent;
    font-size: .95rem; font-weight: 600; cursor: pointer; transition: .15s ease;
    text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-block { width: 100%; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.05rem; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .35rem; color: var(--text); }
.form-control, input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], select, textarea {
    width: 100%; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font-size: .95rem; font-family: inherit; transition: .15s;
}
.form-control:focus, input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(220, 38, 38, .15);
}
.text-danger, .field-validation-error { color: var(--danger); font-size: .82rem; }
.input-hint { color: var(--text-muted); font-size: .82rem; margin-top: .25rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 620px) { .row-2 { grid-template-columns: 1fr; } }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.5rem;
}
.card-title { font-size: 1.1rem; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }

/* ---------- Alerts ---------- */
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .9rem; border: 1px solid transparent; }
.alert-success { background: rgba(22, 163, 74, .12); color: var(--ok); border-color: rgba(22, 163, 74, .25); }
.alert-danger  { background: rgba(220, 38, 38, .10); color: var(--danger); border-color: rgba(220, 38, 38, .25); }
.alert-warning { background: rgba(217, 119, 6, .12); color: var(--warn); border-color: rgba(217, 119, 6, .3); }
.alert-info    { background: rgba(37, 99, 235, .10); color: var(--accent); border-color: rgba(37, 99, 235, .25); }

/* ---------- Badges / chips ---------- */
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .65rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.chip-ok { background: rgba(22,163,74,.14); color: var(--ok); }
.chip-warn { background: rgba(217,119,6,.16); color: var(--warn); }
.chip-danger { background: rgba(220,38,38,.14); color: var(--danger); }

/* ---------- Theme toggle ---------- */
.theme-toggle {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    width: 40px; height: 40px; border-radius: 999px; cursor: pointer; font-size: 1.1rem;
    display: inline-flex; align-items: center; justify-content: center; transition: .15s;
}
.theme-toggle:hover { border-color: var(--brand); }

/* =========================================================
   PUBLIC layout (landing / auth)
   ========================================================= */
.public-topbar {
    height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem; background: var(--bg-elev); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
}
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .logo { font-size: 1.4rem; }
.brand small { display: block; font-size: .62rem; color: var(--text-muted); font-weight: 600; letter-spacing: .04em; }

.auth-wrap { min-height: calc(100vh - var(--topbar-h)); display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 440px; }
.auth-card .card { padding: 2rem; }
.auth-head { text-align: center; margin-bottom: 1.5rem; }
.auth-head .logo-lg { font-size: 2.5rem; }
.auth-head h1 { font-size: 1.5rem; margin-top: .5rem; }
.auth-head p { color: var(--text-muted); margin: 0; }
.auth-foot { text-align: center; margin-top: 1.25rem; font-size: .9rem; color: var(--text-muted); }

/* =========================================================
   APP shell (authenticated)
   ========================================================= */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w); background: var(--bg-elev); border-right: 1px solid var(--border);
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; display: flex; flex-direction: column;
    transition: transform .2s ease;
}
.sidebar-head { height: var(--topbar-h); display: flex; align-items: center; padding: 0 1.1rem; border-bottom: 1px solid var(--border); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin: 1rem .5rem .35rem; font-weight: 700; }
.nav-link {
    display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: var(--radius-sm);
    color: var(--text); font-weight: 500; margin-bottom: .15rem; transition: .12s;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; }
.nav-link .ico { width: 20px; text-align: center; font-size: 1.05rem; }
.sidebar-foot { padding: .75rem; border-top: 1px solid var(--border); }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0 1.25rem; background: var(--bg-elev); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
}
.topbar-left { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.topbar-title { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.hamburger { display: none; background: none; border: none; color: var(--text); font-size: 1.4rem; cursor: pointer; }
.content { padding: 1.5rem; flex: 1; }

.user-pill { display: flex; align-items: center; gap: .5rem; padding: .3rem .3rem .3rem .7rem; border: 1px solid var(--border); border-radius: 999px; }
.user-pill .avatar { width: 30px; height: 30px; border-radius: 999px; background: var(--brand); color:#fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.user-pill .uname { font-size: .85rem; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .kpi-ico { position: absolute; right: .9rem; top: .9rem; font-size: 1.6rem; opacity: .35; }
.kpi .kpi-label { color: var(--text-muted); font-size: .82rem; font-weight: 600; }
.kpi .kpi-value { font-size: 1.7rem; font-weight: 800; margin-top: .2rem; }
.kpi.brand-accent { border-left: 3px solid var(--brand); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.table tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* Expiry banner */
.expiry-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.flex { display: flex; } .items-center { align-items: center; } .gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; }
.between { justify-content: space-between; }
.text-center { text-align: center; }

/* Sidebar backdrop for mobile */
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 45; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .main { margin-left: 0; }
    .hamburger { display: inline-block; }
    .backdrop.show { display: block; }
    .user-pill .uname { display: none; }
}

/* =========================================================
   Landing page
   ========================================================= */
.hero { padding: 4rem 1.25rem 3rem; text-align: center; background:
    radial-gradient(1200px 400px at 50% -50%, rgba(220,38,38,.15), transparent); }
.hero h1 { font-size: 2.4rem; max-width: 780px; margin: 0 auto 1rem; }
.hero p { font-size: 1.1rem; color: var(--text-muted); max-width: 620px; margin: 0 auto 1.75rem; }
.hero-cta { display: inline-flex; gap: .75rem; flex-wrap: wrap; justify-content: center; }
.section { max-width: 1080px; margin: 0 auto; padding: 2.5rem 1.25rem; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.25rem; }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.feature .fico { font-size: 1.8rem; }
.feature h3 { font-size: 1.05rem; margin: .6rem 0 .35rem; }
.feature p { color: var(--text-muted); font-size: .9rem; margin: 0; }
.site-foot { text-align: center; padding: 2rem 1rem; color: var(--text-muted); font-size: .85rem; border-top: 1px solid var(--border); }
