/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #072c93;
    --primary-light: #0d3eb8;
    --primary-dark: #051d5c;
    --accent: #2f6fa3;
    --accent-light: #5d9dcc;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #4f7fa8;
    --chart-blue-1: #1e3a5f;
    --chart-blue-2: #2a5a8f;
    --chart-blue-3: #2f6fa3;
    --chart-blue-4: #5d9dcc;
    --chart-blue-5: #8bbfe0;
    --chart-blue-6: #c7dff0;
    --chart-neutral: #64748b;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 250px;
    --topbar-height: 52px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

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

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }

/* ========== Top Bar ========== */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    height: var(--topbar-height);
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.topbar-logo { width: 30px; height: 30px; border-radius: 6px; object-fit: contain; background: #fff; padding: 3px; }
.topbar-title { font-size: 1.05rem; font-weight: 700; letter-spacing: .3px; }
.sidebar-toggle {
    background: none; border: none; color: #fff; font-size: 1.25rem;
    cursor: pointer; padding: 4px 6px; border-radius: 4px; transition: background .15s;
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.15); }
.toggle-icon { line-height: 1; }

.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(255,255,255,.2); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 700; letter-spacing: .5px;
    flex-shrink: 0;
}
.topbar-user-info { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-user-info strong { font-size: .82rem; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user-info small { font-size: .68rem; opacity: .65; }
.topbar-action {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; padding: 4px; border-radius: 4px;
    color: rgba(255,255,255,.75); text-decoration: none; font-size: 1.05rem; line-height: 1;
    filter: grayscale(1); transition: all .15s;
    background: none; border: none; cursor: pointer;
}
.topbar-action:hover { color: #fff; background: rgba(255,255,255,.12); filter: none; }
.topbar-nav-links { display: flex; align-items: center; gap: 8px; }
.topbar-nav-links a {
    color: rgba(255,255,255,.8); text-decoration: none; font-size: .84rem;
    padding: 5px 10px; border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08);
    transition: all .15s;
}
.topbar-nav-links a:hover { background: rgba(255,255,255,.18); color: #fff; }

/* ========== Sidebar ========== */
.sidebar {
    position: fixed; top: var(--topbar-height); bottom: 0; left: 0; z-index: 100;
    width: var(--sidebar-width);
    background: var(--primary); color: #fff;
    display: flex; flex-direction: column;
    transition: width .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
}
.sidebar.collapsed { width: 0; transform: translateX(calc(-1 * var(--sidebar-width))); }
.sidebar.expanded { width: var(--sidebar-width); transform: translateX(0); }

.sidebar-nav { list-style: none; padding: 8px 0; flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.nav-group { border-bottom: 1px solid rgba(255,255,255,.06); }
.nav-group-toggle {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 10px 18px; border: none; background: none; color: rgba(255,255,255,.5);
    font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1.1px;
    cursor: pointer; transition: all .15s; user-select: none;
}
.nav-group-toggle:hover { color: rgba(255,255,255,.8); background: rgba(255,255,255,.04); }
.chevron { font-size: .6rem; transition: transform .2s ease; }
.chevron.open { transform: rotate(180deg); }

.nav-group-items { list-style: none; padding: 0 0 4px; }
.nav-group-items li a {
    display: flex; align-items: center; gap: 10px; padding: 8px 18px 8px 24px;
    color: rgba(255,255,255,.75); text-decoration: none; font-size: .84rem; transition: all .15s;
    border-left: 3px solid transparent;
}
.nav-group-items li a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-group-items li a.active {
    background: rgba(255,255,255,.12); color: #fff; font-weight: 600;
    border-left-color: var(--accent-light);
}
.nav-icon { font-size: .9rem; width: 18px; text-align: center; filter: grayscale(1); opacity: .6; flex-shrink: 0; }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
    padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.35); font-size: .72rem; text-align: center;
}

/* ========== Overlay (mobile) ========== */
.sidebar-overlay {
    display: none; position: fixed; inset: 0; top: var(--topbar-height);
    background: rgba(0,0,0,.4); z-index: 90;
}

/* ========== Main Content ========== */
.main-content {
    margin-top: var(--topbar-height); flex: 1; display: flex; flex-direction: column;
    transition: margin-left .25s cubic-bezier(.4,0,.2,1);
    min-height: calc(100vh - var(--topbar-height));
}
.main-content.sidebar-is-expanded { margin-left: var(--sidebar-width); }
.main-content.sidebar-is-collapsed { margin-left: 0; }
.content-area { max-width: 1440px; margin: 0 auto; padding: 24px 32px; flex: 1; }
.public-content-area { max-width: 900px; }

/* ========== Page Header ========== */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 18px; margin-bottom: 22px; padding: 20px;
    background: var(--surface); border: 1px solid rgba(219,227,239,.9);
    border-left: 4px solid var(--primary); border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.page-header-icon { font-size: 1.7rem; opacity: .8; filter: grayscale(.4); }
.page-header h1 { margin: 0; font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.page-header p { margin: 5px 0 0; color: var(--text-muted); }
.page-header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ========== Cards ========== */
.card {
    background: var(--surface); border: 1px solid rgba(219,227,239,.9);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-title { margin: 0; font-size: 1rem; font-weight: 700; }

/* ========== Login ========== */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 430px; padding: 0; overflow: hidden; }
.login-logo-header {
    background: #fff; padding: 26px 0 22px;
    display: flex; align-items: center; justify-content: center;
    border-bottom: 1px solid var(--border);
}
.login-logo { width: min(250px, 72%); height: auto; object-fit: contain; }
.login-card-body { padding: 28px; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { margin: 0; font-size: 1.4rem; color: var(--primary); }
.login-brand p, .login-note { margin: 3px 0 0; color: var(--text-muted); font-size: .9rem; }
.login-actions { display: flex; flex-direction: column; gap: 12px; }
.login-button { justify-content: center; width: 100%; min-height: 44px; }
.login-note { margin-top: 18px; line-height: 1.55; }
.login-form-group { display: flex; flex-direction: column; gap: 14px; margin-bottom: 4px; }

/* ========== Stat cards ========== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
    background: var(--surface); border: 1px solid rgba(219,227,239,.9);
    border-left: 4px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow);
}
.stat-card span { display: block; font-size: 1.8rem; font-weight: 800; }
.stat-card small { color: var(--text-muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.stat-card.total { border-left-color: var(--primary); }
.stat-card.open { border-left-color: var(--accent); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.danger { border-left-color: var(--danger); }

/* ========== Table ========== */
.table-container { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
    padding: 12px 14px; text-align: left; background: #f8fafc;
    color: var(--text-muted); font-size: .74rem; text-transform: uppercase;
    letter-spacing: .04em; border-bottom: 1px solid var(--border);
}
td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
td small { display: block; color: var(--text-muted); margin-top: 2px; }
tbody tr:hover { background: #f8fafc; }

/* ========== Buttons ========== */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border: none; border-radius: var(--radius); font-size: .85rem; font-weight: 500;
    cursor: pointer; transition: all .15s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-light); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .85; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { opacity: .85; }

/* ========== Forms ========== */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: .85rem; font-weight: 600; color: var(--text-muted); }
.form-control {
    padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .9rem; outline: none; transition: border .15s; background: #fff; color: var(--text);
    width: 100%;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,111,163,.15); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; font-family: inherit; }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.span-2  { grid-column: span 2; }
.span-3  { grid-column: span 3; }
.span-4  { grid-column: span 4; }
.span-6  { grid-column: span 6; }
.span-12 { grid-column: span 12; }

.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* ========== Alerts ========== */
.alert {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 16px; border-radius: var(--radius); margin-bottom: 16px;
    font-size: .9rem;
}
.alert-success { background: #dcfce7; color: #166534; border-left: 4px solid var(--success); }
.alert-error   { background: #fecaca; color: #991b1b; border-left: 4px solid var(--danger); }
.alert-warning { background: #fef3c7; color: #92400e; border-left: 4px solid var(--warning); }
.alert-info    { background: #dbeafe; color: #1e40af; border-left: 4px solid var(--accent); }

/* ========== Badges ========== */
.badge {
    display: inline-flex; align-items: center; min-height: 22px;
    padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .3px; white-space: nowrap;
}
.badge.success, .badge-resolved   { background: #dcfce7; color: #166534; }
.badge.warning, .badge-pending    { background: #fef3c7; color: #92400e; }
.badge.danger,  .badge-rejected   { background: #fecaca; color: #991b1b; }
.badge-allocated, .badge-approved { background: #dcfce7; color: #166534; }
.badge-default                    { background: rgba(100,116,139,.12); color: #475569; }
.badge-open                       { background: #dbeafe; color: #1e40af; }
.badge-closed                     { background: #f1f5f9; color: #475569; }

/* ========== Price box ========== */
.price-box {
    min-height: 44px; display: flex; align-items: center;
    font-weight: 800; color: var(--primary);
    background: #eef2ff; border-radius: var(--radius); padding: 10px 12px;
    border: 1px solid #c7d4f8;
}

/* ========== Muted helper ========== */
.muted, .text-muted { color: var(--text-muted); }

/* ========== Empty state ========== */
.empty-state {
    min-height: 180px; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center; color: var(--text-muted);
    border: 1px dashed var(--border); border-radius: var(--radius); background: #fbfdff;
}
.empty-state h2 { margin: 0 0 8px; color: var(--text); font-size: 1.05rem; }

/* ========== Loading / Spinner ========== */
.spinner {
    display: inline-block; width: 24px; height: 24px;
    border: 3px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .7s linear infinite;
    margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Back link ========== */
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); text-decoration: none; font-size: .9rem; margin-bottom: 16px; }
.back-link:hover { text-decoration: underline; }

/* ========== Responsive ========== */

/* ── Tablet / small desktop: sidebar becomes an overlay drawer ── */
@media (max-width: 860px) {

    /* Sidebar always overlays (full-width push disabled) */
    .sidebar {
        width: var(--sidebar-width);
    }
    .sidebar.expanded  { transform: translateX(0); }
    .sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-width))); }

    /* Content never shifts — sidebar floats above */
    .main-content.sidebar-is-expanded,
    .main-content.sidebar-is-collapsed { margin-left: 0; }

    /* Dim overlay is managed by JS adding/removing display via inline style;
       this class just ensures correct base behaviour */
    .sidebar-overlay { display: none; }

    /* Tighter content padding */
    .content-area { padding: 16px 14px; }

    /* Page header: let actions wrap below the title on small screens */
    .page-header {
        flex-wrap: wrap;
        gap: 12px;
        padding: 14px 16px;
    }
    .page-header h1 { font-size: 1.15rem; }
    .page-header-actions { width: 100%; justify-content: flex-start; }

    /* Card header: wrap title + actions */
    .card-header { flex-wrap: wrap; gap: 10px; }

    /* Grid: collapse all spans to two columns */
    .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .span-2, .span-3, .span-4, .span-6, .span-12 { grid-column: span 2; }

    /* Stats: two per row */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

    /* Hide verbose user info in topbar (keep avatar) */
    .topbar-user-info { display: none; }

    /* Shrink topbar nav link text on tablet */
    .topbar-nav-links a { font-size: .78rem; padding: 4px 8px; }

    /* Tables: ensure horizontal scroll kicks in cleanly */
    .table-container { -webkit-overflow-scrolling: touch; }
    table { min-width: 520px; }

    /* Form actions: stack buttons full-width */
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions .btn { justify-content: center; }
}

/* ── Mobile: single column everything ── */
@media (max-width: 600px) {

    /* Single column grid */
    .grid { grid-template-columns: 1fr; }
    .span-2, .span-3, .span-4, .span-6, .span-12 { grid-column: span 1; }

    /* Stats: single column */
    .stats-grid { grid-template-columns: 1fr; }

    /* Tighter content padding */
    .content-area { padding: 12px; }

    /* Page header: icon hidden on very small screens */
    .page-header-icon { display: none; }

    /* Topbar: hide nav links text, keep as icon-only pill buttons */
    .topbar-nav-links a {
        font-size: 0;        /* hide text */
        padding: 7px 10px;   /* keep tap target */
        border-radius: 50%;
    }
    /* Show the emoji icon which is part of the text — re-reveal via ::first-letter trick
       (won't work on all browsers) — simpler: just hide the whole text node and show emoji */
    .topbar-title { font-size: .9rem; }

    /* Topbar right: reduce gap */
    .topbar-right { gap: 8px; }

    /* Login card: reduce side padding */
    .login-card-body { padding: 20px 18px; }

    /* Card: tighter padding */
    .card { padding: 14px; }

    /* Stat card: reduce number size slightly */
    .stat-card span { font-size: 1.5rem; }

    /* Buttons: full-width by default inside form-actions already; standalone btns keep inline */
    .btn { min-height: 40px; }

    /* Form control: larger touch target */
    .form-control { padding: 11px; font-size: 1rem; }

    /* Topbar brand title truncation */
    .topbar-brand { max-width: calc(100vw - 140px); overflow: hidden; }
    .topbar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ── Very small phones (320px) ── */
@media (max-width: 380px) {
    .topbar { padding: 0 12px; }
    .content-area { padding: 10px; }
    .page-header { padding: 12px; }
    .stat-card { padding: 14px; }
}
