/* =========================================================
   KIASWA Maternal Health System — Base Styles
   Mobile-first, responsive. Pair with Bootstrap Icons CDN/local.
   ========================================================= */

/* Brand palette taken from the KIASWA logo: crimson umbrella, black type, white.
   Every colour is a variable so light and night mode only swap values. */
:root {
    --primary: #b01e24;
    --primary-hover: #86161b;
    --primary-dark: #86161b;      /* headings / emphasis text */
    --link: #b01e24;
    --on-primary: #ffffff;
    --accent: #1a1a1a;
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --danger-border: #f5c6c0;
    --ok-bg: #e9f6ee;
    --ok-text: #1d6b3a;
    --ok-border: #bfe3cd;
    --warn-bg: #fff8e1;
    --warn-text: #8a6d00;
    --bg: #f7f4f3;
    --card-bg: #ffffff;
    --text: #1f1b1b;
    --text-muted: #6d6565;
    --border: #e7dfde;
    --input-bg: #ffffff;
    --input-ro: #f1ecec;
    --track: #eadfde;
    --tint: rgba(176,30,36,0.09);
    --focus-ring: rgba(176,30,36,0.18);
    --login-from: #b01e24;
    --login-to: #1a1a1a;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(0,0,0,0.06);
    --header-height: 60px;
}

/* Night mode */
html[data-theme="dark"] {
    color-scheme: dark;
    --primary: #c4262c;
    --primary-hover: #dc3a40;
    --primary-dark: #ff9094;
    --link: #ff9094;
    --accent: #f1ecec;
    --danger: #ff6b6b;
    --danger-bg: #2d1618;
    --danger-border: #5c2a2e;
    --ok-bg: #13281b;
    --ok-text: #7fdc9f;
    --ok-border: #245a38;
    --warn-bg: #2b2411;
    --warn-text: #f0c94d;
    --bg: #121010;
    --card-bg: #1c1818;
    --text: #f2eded;
    --text-muted: #a99f9f;
    --border: #342d2d;
    --input-bg: #231e1e;
    --input-ro: #2a2424;
    --track: #3a3232;
    --tint: rgba(255,120,125,0.12);
    --focus-ring: rgba(255,120,125,0.25);
    --login-from: #3a0f12;
    --login-to: #0b0909;
    --shadow: 0 2px 12px rgba(0,0,0,0.45);
}
html[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
}

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

/* ---------- Layout ---------- */
.app-header {
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: inset 0 3px 0 var(--primary);
}
.app-header .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
    color: var(--primary-dark);
}
.app-header .brand img { height: 34px; width: auto; }

.app-body {
    display: flex;
    min-height: calc(100vh - var(--header-height));
}

.sidebar {
    width: 230px;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    padding: 1rem 0.75rem;
    flex-shrink: 0;
}
.sidebar a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.8rem;
    border-radius: var(--radius);
    color: var(--text);
    margin-bottom: 0.25rem;
}
.sidebar a { position: relative; }
.sidebar a:hover, .sidebar a.active {
    background: var(--tint);
    color: var(--primary-dark);
    text-decoration: none;
}

.main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1200px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    border: 1px solid var(--border);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem;
    border-left: 4px solid var(--primary);
}
.stat-card .stat-number { font-size: 1.8rem; font-weight: 700; color: var(--primary-dark); }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: 0.3rem; font-size: 0.92rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], select, textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
input[readonly], select[disabled], textarea[readonly] {
    background: var(--input-ro);
    color: var(--text-muted);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-outline { background: transparent; border: 1px solid var(--primary); color: var(--link); }
.btn-outline:hover { background: var(--tint); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
html[data-theme="dark"] .btn-danger { background: #c0343a; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Login page ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, var(--login-from) 0%, var(--login-to) 100%);
}
.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
}
.login-card .brand-center {
    text-align: center;
    margin-bottom: 1.5rem;
}
.login-card .brand-center img { height: 56px; margin-bottom: 0.5rem; }
.alert {
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.alert-success { background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ok-border); }

/* ---------- Progress ---------- */
.progress-bar-outer {
    background: var(--track);
    border-radius: 20px;
    height: 10px;
    width: 100%;
    overflow: hidden;
}
.progress-bar-inner {
    background: var(--primary);
    height: 100%;
    transition: width 0.3s ease;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}
.badge-green { background: var(--ok-bg); color: var(--ok-text); }
.badge-yellow { background: var(--warn-bg); color: var(--warn-text); }
.badge-red { background: var(--danger-bg); color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .app-body { flex-direction: column; }
    .sidebar {
        width: 100%;
        display: flex;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar a { white-space: nowrap; margin-bottom: 0; margin-right: 0.4rem; }
    .main-content { padding: 1rem; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* ---------- Desktop: sidebar and page content scroll independently ----------
   The header and sidebar stay in place while the content scrolls, and the sidebar only
   moves when the mouse is over it (and its menu is longer than the screen). Phones keep the normal layout above. */
@media (min-width: 901px) {
    html, body { height: 100%; }
    body { overflow: hidden; }
    .app-body {
        height: calc(100vh - var(--header-height));
        height: calc(100dvh - var(--header-height));
        min-height: 0;
        overflow: hidden;
    }
    .sidebar {
        height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .main-content {
        height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
        max-width: none;
        /* keep the readable 1200px width, but put the scrollbar at the screen edge */
        padding-right: max(1.5rem, calc(100% - 1454px));
    }
}

@media (max-width: 480px) {
    .login-card { padding: 1.4rem; }
    body { font-size: 15px; }
}

/* ---------- Questionnaire (Interviewer Guide) ---------- */
.qhead { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.5rem 1rem; }
.qrow { display: flex; gap: 0.75rem; padding: 0.75rem 0; border-top: 1px solid var(--border); }
.qrow:first-of-type { border-top: none; }
.qnum { flex: 0 0 48px; font-weight: 700; color: var(--primary-dark); }
.qbody { flex: 1; min-width: 0; }
.qtext { font-weight: 600; margin-bottom: 0.2rem; }
.qsmall { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.qfield { margin: 0.35rem 0; }
.qlabel { font-size: 0.85rem; color: var(--text-muted); margin-right: 0.3rem; }
.qopts { display: inline-flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: center; }
.opt { font-weight: normal; margin: 0; display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.92rem; }
.opt input[type=radio], .opt input[type=checkbox] { width: auto; }
input.inline { width: 170px; padding: 0.25rem 0.5rem; }
.qclear { font-size: 0.75rem; color: var(--text-muted); }
.qnote { color: var(--text-muted); margin: 0.5rem 0 1rem; }
@media (max-width: 600px) { .qrow { flex-direction: column; gap: 0.2rem; } .qnum { flex: none; } }

/* ---------- Sidebar notification badges ---------- */
.nav-badge {
    position: absolute;
    top: -5px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #d9232b;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--card-bg);
    pointer-events: none;
}

/* ---------- Theme toggle (light / night) ---------- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 1.05rem;
    padding: 0;
}
.theme-toggle:hover { background: var(--tint); }
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
.theme-toggle.floating { position: fixed; top: 12px; right: 12px; z-index: 100; }

/* The logo has black lettering: give it a light plate in night mode so it stays readable. */
html[data-theme="dark"] .app-header .brand img,
html[data-theme="dark"] .login-card .brand-center img {
    background: #ffffff;
    border-radius: 8px;
    padding: 2px;
}

/* Slightly softer tables / dividers / inline notes in night mode */
.note-box { margin: 0.6rem 0 0; padding: 0.6rem; background: var(--danger-bg); border: 1px solid var(--danger-border); border-radius: 6px; }

/* ---------- Printing (reports) ---------- */
@media print {
    html, body { height: auto !important; overflow: visible !important; }
    .app-body { height: auto !important; overflow: visible !important; }
    .main-content { height: auto !important; overflow: visible !important; }
    .sidebar, .app-header, .no-print, .theme-toggle, .offline-banner { display: none !important; }
    .app-body { display: block !important; }
    .main-content { margin: 0 !important; padding: 0 !important; max-width: none !important; }
    body { background: #fff !important; color: #000 !important; }
    .card, .stat-card { box-shadow: none !important; break-inside: avoid; }
    html[data-theme="dark"] { --bg:#fff; --card-bg:#fff; --text:#000; --text-muted:#555; --border:#ccc; --primary:#b01e24; --primary-dark:#86161b; --link:#b01e24; }
}

/* ---------- Offline banner ---------- */
.offline-banner {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 200;
    padding: 0.7rem 1rem;
    background: #1a1a1a;
    color: #fff;
    font-size: 0.92rem;
    text-align: center;
    border-top: 3px solid #d9232b;
}
.offline-banner[hidden] { display: none; }
.offline-banner.is-online { border-top-color: #2e9e5b; }
html[data-theme="dark"] .offline-banner { background: #2a2424; }
