:root {
    --accent: #006940;
    --accent-lt: #e8f5ee;
    --danger: #dc2626;
    --warn: #d97706;
    --blue: #1d4ed8;
    --purple: #7c3aed;
    --text: #0f172a;
    --muted: #475569;
    --text3: #94a3b8;
    --border: #e2e8f0;
    --border2: #cbd5e1;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --warning-bg: #fffbeb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --sans: 'Plus Jakarta Sans', sans-serif;
    --mono: 'DM Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--sans);
    background: linear-gradient(135deg, var(--bg) 0%, #eef2f6 100%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   TOP BAR
   Three fixed zones: brand | links | user.
   The bar never wraps — the links strip scrolls sideways instead, so adding
   another menu item later can't break the layout again.
   ========================================================================== */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    flex-wrap: nowrap;
    gap: 14px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.nav-brand img { width: 34px; height: 34px; object-fit: contain; }
.nav-brand .brand-text .t1 { font-size: 12.5px; font-weight: 700; color: var(--text); white-space: nowrap; }
.nav-brand .brand-text .t2 { font-size: 9.5px; color: var(--text3); white-space: nowrap; }

.nav-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.nav-links::-webkit-scrollbar { display: none; }

.nav-links a {
    padding: 8px 10px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    border-radius: 6px 6px 0 0;
    white-space: nowrap;
    flex-shrink: 0;
}
.nav-links a:hover, .nav-links a.active { color: var(--accent); border-bottom-color: var(--accent); }

.nav-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    color: var(--muted);
    flex-shrink: 0;
    white-space: nowrap;
}
.nav-user strong { color: var(--text); }
.nav-user .badge { font-size: 9.5px; padding: 2px 7px; }

.btn-logout {
    color: var(--danger);
    text-decoration: none;
    font-weight: 600;
    font-size: 11.5px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.container { max-width: 1500px; margin: 0 auto; padding: 26px 22px; width: 100%; flex: 1; }

/* Login / setup card */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--bg) 0%, #eef2f6 100%);
}
.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 14px;
    box-shadow: var(--shadow-md), 0 10px 30px rgba(0,0,0,0.06);
    width: 100%;
    max-width: 400px;
    border-top: 4px solid var(--accent);
}
.login-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.login-logo img { width: 68px; height: 68px; object-fit: contain; }
.login-card h1 { color: var(--text); font-size: 1.25rem; margin-bottom: 4px; text-align: center; font-weight: 800; }
.login-card p.sub { color: var(--muted); margin-top: 0; margin-bottom: 26px; font-size: 0.85rem; text-align: center; }

label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
input[type=text], input[type=password], input[type=email], input[type=file], select, input[type=date], textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border2);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    font-family: var(--sans);
    outline: none;
    background: #fff;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

button, .btn {
    background: var(--accent);
    color: #fff;
    border: 1.5px solid var(--accent);
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--sans);
}
button:hover, .btn:hover { opacity: 0.92; }
.btn-secondary { background: #fff; color: var(--muted); border-color: var(--border2); }
.btn-danger { background: var(--danger); border-color: var(--danger); }

.error-msg {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.success-msg {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}

h1.page-title { color: var(--text); margin-bottom: 4px; font-size: 22px; font-weight: 800; }
p.page-sub { color: var(--muted); margin-top: 0; margin-bottom: 24px; font-size: 13px; }

/* Department Badges */
.badge-hp { background: #dbeafe; color: #1d4ed8; }
.badge-ddc-i { background: #dcfce7; color: #15803d; }
.badge-ddc-ii { background: #fef3c7; color: #92400e; }
.badge-superadmin { background: #f3e8ff; color: #7c3aed; }

/* Procurement code badges */
.badge-sml { background: #dbeafe; color: #1d4ed8; }
.badge-retender { background: #fef3c7; color: #92400e; }
.badge-nsml { background: #dcfce7; color: #15803d; }
.badge-unknown { background: #e5e7eb; color: #6b7280; }

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}
.stat-card .icon-box {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--accent-lt); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; margin-bottom: 10px;
}
.stat-card.warn .icon-box { background: #fee2e2; color: var(--danger); }
.stat-card .label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; }
.stat-card .value { font-size: 1.5rem; font-weight: 800; color: var(--text); margin-top: 4px; font-family: var(--mono); }
.stat-card .sub { font-size: 0.72rem; color: var(--text3); margin-top: 2px; }

.charts-grid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.chart-card .chart-hdr {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.chart-card .chart-hdr i { color: var(--accent); }
.chart-card .chart-body { padding: 18px; }

/* ==========================================================================
   FILTER ROWS
   Deliberately NOT scoped to .filter-bar — the demand analysis page uses the
   same row/group markup inside a chart-card, and scoping it broke that panel.
   .filter-bar now only supplies the card chrome.
   ========================================================================== */
.filter-bar {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 14px 18px;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 130px;
    max-width: 100%;
}

.filter-group label {
    margin-bottom: 0;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    font-weight: 700;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 6px 10px;
    border: 1.5px solid var(--border2);
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: var(--sans);
    outline: none;
    background: #fff;
    margin-bottom: 0;
    height: 34px;
}

.filter-group input:focus,
.filter-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 105, 64, 0.08);
}

.filter-actions-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex: 0 0 auto;
    padding-bottom: 0;
}

.filter-actions-row button,
.filter-actions-row .btn {
    padding: 6px 16px;
    font-size: 0.8rem;
    border-radius: 6px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.filter-actions-row .btn-secondary {
    background: #fff;
    color: var(--muted);
    border-color: var(--border2);
}
.filter-actions-row .btn-secondary:hover {
    background: var(--bg);
    color: var(--text);
}

/* Summary tiles on the analysis page */
.metric-strip { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 22px; }
.metric-strip .chart-card { flex: 1 1 180px; margin: 0; }
.metric-strip .metric-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text3); font-weight: 700; }
.metric-strip .metric-value { font-size: 1.1rem; font-weight: 800; margin-top: 4px; font-family: var(--mono); }

/* --- Tables --- */
.table-wrap {
    overflow-x: auto;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    font-size: 0.7rem;
    min-width: 100%;
}

th, td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-size: 0.7rem;
    line-height: 1.3;
}

td[title]:hover { background: var(--accent-lt); cursor: help; }
tr.dup-row td { background: var(--warning-bg); }

th {
    background: #f8fafc;
    color: var(--muted);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    padding: 6px 8px;
    white-space: nowrap;
}
th a { color: inherit; text-decoration: none; }
tr.dup-row { background: var(--warning-bg); }
tr:hover:not(.dup-row) { background: #f8fafc; }
.po-num { font-family: var(--mono); font-weight: 700; color: var(--accent); }

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    font-size: 0.8rem;
}
.pagination .active { background: var(--accent); color: #fff; border-color: var(--accent); }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
}
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-procurement_officer { background: #dbeafe; color: #1d4ed8; }
.badge-viewer { background: #e5e7eb; color: #374151; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }

.footer { text-align: center; padding: 20px; color: var(--text3); font-size: 0.75rem; }
.footer .designer { color: var(--accent); font-weight: 600; font-size: 0.7rem; margin-top: 4px; display: block; }

form.inline { display: inline; }

/* --- Medicine Search --- */
#medicine_search { border-color: var(--blue); background: #f0f7ff; }
#medicine_search:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.08); }

/* --- Active Filter Tags --- */
.filter-tag {
    background: var(--accent-lt);
    padding: 3px 10px 3px 12px;
    border-radius: 12px;
    font-size: 0.72rem;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
}
.filter-tag .remove { cursor: pointer; color: var(--danger); font-weight: 700; font-size: 14px; line-height: 1; text-decoration: none; }
.filter-tag .remove:hover { opacity: 0.7; }

/* Print button in table */
td .fa-print { color: var(--accent); transition: all 0.2s ease; }
td .fa-print:hover { color: var(--blue); transform: scale(1.1); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

/* Narrower desktops — tighten the menu before anything is dropped */
@media (max-width: 1400px) {
    .nav-links a { padding: 8px 8px; font-size: 11px; }
    .nav-brand .brand-text .t1 { font-size: 11.5px; }
}

/* Laptops — the hospital name goes, the crest stays */
@media (max-width: 1200px) {
    .nav-brand .brand-text { display: none; }
    .nav-links { justify-content: flex-start; }
    .nav-links a { padding: 8px 7px; font-size: 10.5px; }
    .nav-user { font-size: 11px; gap: 6px; }
}

/* Tablet */
@media (max-width: 1024px) {
    .filter-group { min-width: 110px; }
    .filter-group input,
    .filter-group select { font-size: 0.75rem; padding: 5px 8px; height: 32px; }
    .filter-actions-row button,
    .filter-actions-row .btn { font-size: 0.75rem; padding: 5px 12px; height: 32px; }
    th, td { font-size: 0.65rem; padding: 4px 6px; }
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 800px; }
}

/* Mobile — here the bar is allowed to stack, which is correct on a phone */
@media (max-width: 768px) {
    .navbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
    .nav-links { order: 3; width: 100%; justify-content: flex-start; }
    .nav-links a { padding: 7px 9px; font-size: 11px; }
    .nav-user { font-size: 11px; gap: 8px; margin-left: auto; }

    .filter-bar { padding: 12px 14px; }
    .filter-row { flex-direction: column; gap: 8px; }
    .filter-group { min-width: 100%; flex: 1 1 100%; }
    .filter-group input,
    .filter-group select { font-size: 0.78rem; padding: 6px 10px; height: 36px; }

    .filter-actions-row { flex: 1 1 100%; width: 100%; gap: 8px; padding-top: 4px; }
    .filter-actions-row button,
    .filter-actions-row .btn { flex: 1; justify-content: center; height: 36px; font-size: 0.78rem; padding: 6px 12px; }

    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { font-size: 0.6rem; min-width: 700px; }
    th, td { padding: 4px 6px; font-size: 0.6rem; }

    .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* Small mobile */
@media (max-width: 480px) {
    .filter-bar { padding: 10px 12px; }
    .filter-actions-row { flex-direction: column; }
    .filter-actions-row button,
    .filter-actions-row .btn { width: 100%; justify-content: center; flex: none; }
    .stats-grid { grid-template-columns: 1fr; }
    .container { padding: 16px 12px; }
    .nav-user { width: 100%; justify-content: flex-start; flex-wrap: wrap; margin-left: 0; }
}

/* --- Print --- */
@media print {
    .navbar, .filter-bar, .toolbar, .pagination, .footer { display: none !important; }
    .table-wrap { overflow: visible !important; }
    table { font-size: 0.6rem !important; }
}