/* ------------------------------------------------------------------
   HLG Hospital ESS - theme
   All colours come from CSS variables so they can be re-skinned in
   one place (the :root block) or replaced at runtime via the Settings
   page (see layout.php which injects an override <style> block).
------------------------------------------------------------------- */
:root {
    --primary: #0b57a4;
    --primary-dark: #083f79;
    --primary-soft: #e8f1fb;
    --accent: #2aa99a;
    --accent-dark: #1e8174;
    --bg: #f4f6fa;
    --surface: #ffffff;
    --text: #1c2a3a;
    --text-soft: #5a6b80;
    --border: #dfe4ec;
    --success: #1f9d55;
    --warning: #d78f00;
    --danger: #c0392b;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(10,25,55,.06), 0 1px 3px rgba(10,25,55,.05);
    --shadow: 0 4px 12px rgba(10,25,55,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14.5px;
    line-height: 1.5;
}

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

/* ---------- Layout ---------- */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: linear-gradient(180deg, var(--primary-dark), var(--primary));
    color: #fff;
    padding: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar .brand {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar .brand img { width: 36px; height: 36px; object-fit: contain; background: #fff; padding:4px; border-radius: 8px; }
.sidebar .brand-text { font-weight: 600; font-size: 15px; line-height: 1.2; }
.sidebar .brand-text small { display: block; opacity: .75; font-weight: 400; font-size: 11px; }

.sidebar nav { padding: 10px 0; }
.sidebar .nav-section {
    padding: 14px 20px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    opacity: .7;
}
.sidebar a.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: rgba(255,255,255,.88);
    font-size: 14px;
    border-left: 3px solid transparent;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar a.nav-link.active {
    background: rgba(255,255,255,.14);
    border-left-color: var(--accent);
    color: #fff;
}
.sidebar .nav-badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
}

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    background: var(--surface);
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 16px;
    position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.user-chip {
    display: flex; align-items: center; gap: 10px;
    background: var(--primary-soft); padding: 6px 12px; border-radius: 999px;
    color: var(--primary-dark); font-weight: 500; font-size: 13px;
}
.user-chip .avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--primary); color: #fff; display:flex; align-items:center; justify-content:center;
    font-size: 12px; font-weight: 600;
}
.content { padding: 24px; }

/* ---------- Flashes ---------- */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.flash.success { background: #e3f5ea; color: #155d33; border: 1px solid #b9dfc6; }
.flash.error   { background: #fbeaea; color: #8a231c; border: 1px solid #eec3bf; }
.flash.warn    { background: #fdf4e0; color: #8d5a00; border: 1px solid #f1dca0; }
.flash.info    { background: #e9f1fb; color: #0c4b87; border: 1px solid #c5dbf1; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2, .card h3 { margin-top: 0; }
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin: -4px -4px 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 16px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 16px; }

/* ---------- Stat tiles ---------- */
.stat {
    padding: 18px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 12px; text-transform: uppercase; color: var(--text-soft); letter-spacing: .05em; }
.stat .value { font-size: 28px; font-weight: 700; color: var(--primary-dark); margin-top: 4px; }
.stat .sub   { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.stat.accent { border-top: 3px solid var(--accent); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--primary); color: #fff;
    border: 0; padding: 9px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer; font-size: 14px; font-weight: 500;
    text-decoration: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.secondary:hover { background: var(--primary-soft); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #962e22; }
.btn.success { background: var(--success); }
.btn.ghost   { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--bg); }
.btn.sm      { padding: 5px 10px; font-size: 12px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; font-size: 13.5px; }
.table th { background: #f8fafd; font-weight: 600; color: var(--text-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tr:hover td { background: #fafbfd; }
.table .actions { white-space: nowrap; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }

/* ---------- Forms ---------- */
.form-row { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 14px; margin-bottom: 14px; }
label { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; font-weight: 500; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=time], input[type=number],
textarea, select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: var(--primary); outline: none;
    box-shadow: 0 0 0 3px rgba(11,87,164,.12);
}
.hint { font-size: 12px; color: var(--text-soft); margin-top: 4px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---------- Status pills ---------- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 20px; }
.pill.p-pending  { background: #fdf4e0; color: #8d5a00; }
.pill.p-approved { background: #e3f5ea; color: #155d33; }
.pill.p-rejected { background: #fbeaea; color: #8a231c; }
.pill.p-cancel   { background: #eceff3; color: #5a6b80; }
.pill.p-info     { background: #e9f1fb; color: #0c4b87; }
.pill.p-warn     { background: #fdf4e0; color: #8d5a00; }

/* ---------- Login page ---------- */
.login-wrap {
    min-height: 100vh; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: 20px;
}
.login-box {
    background: #fff; width: 100%; max-width: 400px;
    border-radius: var(--radius); padding: 30px 28px; box-shadow: var(--shadow);
}
.login-box .brand { display:flex; align-items:center; gap:12px; margin-bottom: 18px; }
.login-box .brand img { width: 44px; height: 44px; object-fit: contain; }
.login-box h1 { margin: 0; font-size: 20px; color: var(--primary-dark); }
.login-box p.sub { margin: 0; font-size: 13px; color: var(--text-soft); }
.login-box .btn { width: 100%; justify-content: center; padding: 11px; }
.login-box .links { margin-top: 14px; text-align: center; font-size: 13px; }

/* ---------- Utilities ---------- */
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 16px; }
.text-soft { color: var(--text-soft); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.hide { display: none; }

/* ---------- Calendar ---------- */
.cal {
    width: 100%; border-collapse: separate; border-spacing: 4px;
}
.cal th { font-size: 11px; color: var(--text-soft); text-transform: uppercase; padding: 4px; }
.cal td {
    background: #fff; border: 1px solid var(--border); height: 72px; vertical-align: top;
    padding: 4px 6px; font-size: 12px; border-radius: 6px;
}
.cal td.off { background: #f4f6fa; }
.cal td.holiday { background: #fff4e5; }
.cal td .d { font-weight: 600; color: var(--text-soft); }
.cal td.today .d { color: var(--primary); }
.cal td .tag {
    display: block; margin-top: 4px; background: var(--primary-soft);
    color: var(--primary-dark); padding: 1px 4px; border-radius: 4px;
    font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Timeline (approvals log) ---------- */
.timeline { border-left: 2px solid var(--border); padding-left: 16px; }
.timeline .tl-item { position: relative; margin-bottom: 14px; }
.timeline .tl-item::before {
    content: ""; position: absolute; left: -22px; top: 5px;
    width: 10px; height: 10px; background: var(--accent); border-radius: 50%;
}
.timeline .tl-item .tl-when { font-size: 11px; color: var(--text-soft); }

/* ---------- Hamburger button (mobile only) ---------- */
.menu-toggle {
    display: none;
    background: transparent;
    border: 0;
    padding: 8px;
    margin-right: 4px;
    cursor: pointer;
    color: var(--text);
    border-radius: 8px;
    -webkit-tap-highlight-color: rgba(11,87,164,.15);
}
.menu-toggle:hover { background: var(--primary-soft); }
.menu-toggle svg { display: block; width: 26px; height: 26px; }

/* Scrim that covers the page when the mobile sidebar is open */
.scrim {
    position: fixed; inset: 0;
    background: rgba(13,32,58,.45);
    backdrop-filter: blur(2px);
    z-index: 19;
    opacity: 0; pointer-events: none;
    transition: opacity .18s ease;
}
body.nav-open .scrim { opacity: 1; pointer-events: auto; }

/* iOS: prevent body scroll when the sidebar drawer is open */
body.nav-open { overflow: hidden; }

/* ---------- Tablet (<= 1024px): tighter spacing ---------- */
@media (max-width: 1024px) {
    .app { grid-template-columns: 220px 1fr; }
    .content { padding: 18px; }
    .topbar { padding: 10px 16px; }
    .stat .value { font-size: 24px; }
}

/* ---------- Phone (<= 760px): drawer sidebar + single column ---------- */
@media (max-width: 760px) {
    /* Single-column layout */
    .app { grid-template-columns: 1fr; }

    /* Hamburger appears in the topbar */
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        height: 100dvh;            /* iOS Safari dynamic viewport */
        width: 84vw; max-width: 320px;
        z-index: 20;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 4px 0 24px rgba(10,25,55,.25);
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    body.nav-open .sidebar { transform: translateX(0); }

    /* Restore vertical nav layout in the drawer */
    .sidebar nav { display: block; padding: 10px 0; }
    .sidebar .nav-section { display: block; }
    .sidebar a.nav-link {
        padding: 12px 20px;       /* roomier tap target */
        border-left: 3px solid transparent;
        border-radius: 0;
        font-size: 15px;
    }

    /* Topbar */
    .topbar {
        padding: 10px 14px;
        padding-top: calc(10px + env(safe-area-inset-top));
        gap: 8px;
    }
    .topbar h1 { font-size: 16px; }
    .user-chip { padding: 4px 10px; font-size: 12px; }
    .user-chip > div:nth-child(2) { display: none; }     /* hide name+roles, keep avatar */
    .user-chip .avatar { width: 32px; height: 32px; }

    /* Content area */
    .content {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .card { padding: 14px; border-radius: 12px; margin-bottom: 14px; }
    .card-header { flex-wrap: wrap; gap: 8px; }
    .card-header h2 { font-size: 15px; }

    /* Forms: stack everything */
    .form-row { grid-template-columns: 1fr; gap: 12px; }
    label { font-size: 14px; }
    /* iOS auto-zooms inputs with font-size < 16px - bump to 16px */
    input[type=text], input[type=password], input[type=email],
    input[type=date], input[type=time], input[type=number],
    textarea, select {
        font-size: 16px;
        padding: 12px 12px;
    }

    /* Buttons: easier to tap, full-width when stacked */
    .btn { padding: 12px 18px; font-size: 15px; min-height: 44px; }
    .btn.sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }
    .login-box .btn { padding: 13px; }

    /* Cards/grids - single column tiles */
    .card-grid { grid-template-columns: 1fr; gap: 12px; }
    .stat { padding: 14px; }
    .stat .value { font-size: 22px; }

    /* Tables - smooth horizontal scroll on iOS */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 10px;
    }
    .table th, .table td { padding: 9px 10px; font-size: 13px; white-space: nowrap; }

    /* Calendar shrinks; horizontal scroll if still cramped */
    .cal { border-spacing: 2px; }
    .cal td { height: 56px; padding: 3px 4px; font-size: 11px; }
    .cal td .tag { font-size: 10px; padding: 1px 3px; }

    /* Login page - full screen friendly */
    .login-wrap { padding: 14px; min-height: 100vh; min-height: 100dvh; }
    .login-box { padding: 22px 18px; border-radius: 14px; }
    .login-box h1 { font-size: 18px; }

    /* Flash messages */
    .flash { font-size: 14px; padding: 12px 14px; }
}

/* ---------- Very small phones (<= 380px) ---------- */
@media (max-width: 380px) {
    .topbar h1 { font-size: 15px; }
    .user-chip { padding: 3px 6px; }
    .user-chip .avatar { width: 28px; height: 28px; font-size: 11px; }
    .stat .value { font-size: 20px; }
    .card { padding: 12px; }
    .cal td { height: 48px; }
    .cal th { font-size: 10px; }
}

/* ---------- Tap-friendly defaults across the app ---------- */
a, button, .btn, input, select, textarea {
    -webkit-tap-highlight-color: rgba(11,87,164,.18);
}
@media (pointer: coarse) {
    .table .actions .btn.sm { min-height: 36px; }   /* fingers, not mouse */
}

/* ---------- Print: hide chrome ---------- */
@media print {
    .sidebar, .topbar, .scrim, .menu-toggle, .btn { display: none !important; }
    .app { grid-template-columns: 1fr; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
}
