@font-face {
    font-family: 'Battambang';
    src: url('../fonts/Battambang-Regular.ttf') format('truetype');
    font-weight: 400;
}

@font-face {
    font-family: 'Battambang';
    src: url('../fonts/Battambang-Bold.ttf') format('truetype');
    font-weight: 700;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto-Regular.ttf') format('truetype');
    font-weight: 400;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto-Medium.ttf') format('truetype');
    font-weight: 500;
}

@font-face {
    font-family: 'Roboto';
    src: url('../fonts/Roboto-Bold.ttf') format('truetype');
    font-weight: 700;
}

/* ─── TOKENS (CSS variables) ─── */
:root {
    --font-body: 'Roboto', 'Battambang', sans-serif;
    --font-head: 'Roboto', 'Battambang', sans-serif;
    --radius: 10px;
    --radius-sm: 6px;
    --sidebar-w: 228px;
    --transition: 200ms ease;

    /* Light theme */
    --bg: #f7f7f6;
    --surface: #ffffff;
    --surface-2: #f2f2f0;
    --border: #e5e5e2;
    --border-2: #d8d8d4;
    --text: #1a1a18;
    --text-2: #5c5c58;
    --text-3: #9b9b96;
    --accent: #1B75BC;
    --accent-bg: #e8f3fb;
    --accent-text: #1260a0;
    --sidebar-bg: #17192e;
    --sidebar-text: #c8c8c2;
    --sidebar-active: #ffffff;
    --sidebar-active-bg: rgba(255, 255, 255, 0.08);
    --sidebar-hover: rgba(255, 255, 255, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.1);
}

/* ─── DARK THEME ─── */
[data-theme="dark"] {
    --bg: #111110;
    --surface: #1c1c1a;
    --surface-2: #242422;
    --border: #2d2d2a;
    --border-2: #383835;
    --text: #eeeee8;
    --text-2: #a0a09a;
    --text-3: #606060;
    --accent: #29ABE2;
    --accent-bg: rgba(41, 171, 226, 0.1);
    --accent-text: #29ABE2;
    --sidebar-bg: #0f1020;
    --sidebar-text: #888880;
    --sidebar-active: #eeeee8;
    --sidebar-active-bg: rgba(255, 255, 255, 0.07);
    --sidebar-hover: rgba(255, 255, 255, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ─── RESET ─── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-size: 18px;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    display: flex;
    overflow: hidden;
    transition: background var(--transition), color var(--transition);
}

a {
    text-decoration: none;
    color: inherit;
}

/* ─── LAYOUT ─── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ─── SIDEBAR ─── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.04);
    transition: background var(--transition);
    position: relative;
    z-index: 10;
}

.sidebar-logo {
    padding: 14px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-logo-text {
    font-family: var(--font-head);
    font-size: 0.8rem;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 0.02em;
}

.sidebar-logo-sub {
    font-size: 0.625rem;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 10px 8px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 6px;
}

.nav-section-label {
    padding: 6px 8px 4px;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.2);
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 8px;
    border-radius: 7px;
    cursor: pointer;
    color: var(--sidebar-text);
    font-size: 0.8rem;
    font-weight: 400;
    transition: all var(--transition);
    margin-bottom: 1px;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #c8c8c2;
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active);
    font-weight: 500;
}

.nav-icon {
    width: 16px;
    text-align: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.nav-badge {
    margin-left: auto;
    background: rgba(41, 171, 226, 0.18);
    color: #29ABE2;
    font-size: 0.625rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 9px;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 0.69rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 0.75rem;
    color: #c8c8c2;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.625rem;
    color: var(--sidebar-text);
}

/* ─── THEME TOGGLE ─── */
.theme-btn {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.06);
    border: none;
    cursor: pointer;
    color: var(--sidebar-text);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.theme-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #c8c8c2;
}

/* ─── TOPBAR ─── */
.topbar {
    height: 52px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}

.topbar-title {
    font-family: var(--font-head);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ─── BUTTONS ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: #1562a0;
    color: white;
}

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-danger {
    background: #fee2e2;
    color: #991b1b;
}

.btn-danger:hover {
    background: #fecaca;
    color: #7f1d1d;
}

.btn-success {
    background: #dcfce7;
    color: #166534;
}

.btn-success:hover {
    background: #bbf7d0;
    color: #14532d;
}

.btn-warning {
    background: #fef9c3;
    color: #854d0e;
}

.btn-warning:hover {
    background: #fef08a;
    color: #713f12;
}

/* ─── BADGES (status) ─── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 0.719rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    display: inline-block;
}

.badge-new {
    background: #f0f0ee;
    color: #666660;
}

.badge-new::before {
    background: #aaa;
}

.badge-clarify, .badge-clarification_needed, .badge-clarification {
    background: #fefbe8;
    color: #7c6a00;
}

.badge-clarify::before, .badge-clarification_needed::before, .badge-clarification::before {
    background: #d4a800;
}

.badge-queued {
    background: #eef4ff;
    color: #2255cc;
}

.badge-queued::before {
    background: #3b82f6;
}

.badge-approved {
    background: #e6f8f5;
    color: #0e7a66;
}

.badge-approved::before {
    background: #14b8a6;
}

.badge-scheduled {
    background: #eff1ff;
    color: #3730a3;
}

.badge-scheduled::before {
    background: #6366f1;
}

.badge-inprogress, .badge-in_progress {
    background: #fff4ed;
    color: #9a3b12;
}

.badge-inprogress::before, .badge-in_progress::before {
    background: #f97316;
}

.badge-done {
    background: #e8faf0;
    color: #166534;
}

.badge-done::before {
    background: #22c55e;
}

.badge-delayed {
    background: #fffbeb;
    color: #92400e;
}

.badge-delayed::before {
    background: #f59e0b;
}

.badge-rejected {
    background: #fef2f2;
    color: #991b1b;
}

.badge-rejected::before {
    background: #ef4444;
}

.badge-impossible {
    background: #fef2f2;
    color: #991b1b;
}

.badge-impossible::before {
    background: #ef4444;
}

/* dark badge overrides */
[data-theme="dark"] .badge-new {
    background: rgba(255, 255, 255, 0.05);
    color: #888880;
}

[data-theme="dark"] .badge-clarify,
[data-theme="dark"] .badge-clarification_needed,
[data-theme="dark"] .badge-clarification {
    background: rgba(212, 168, 0, 0.1);
    color: #d4a800;
}

[data-theme="dark"] .badge-queued {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
}

[data-theme="dark"] .badge-approved {
    background: rgba(20, 184, 166, 0.1);
    color: #2dd4bf;
}

[data-theme="dark"] .badge-scheduled {
    background: rgba(99, 102, 241, 0.1);
    color: #a5b4fc;
}

[data-theme="dark"] .badge-inprogress,
[data-theme="dark"] .badge-in_progress {
    background: rgba(249, 115, 22, 0.1);
    color: #fb923c;
}

[data-theme="dark"] .badge-done {
    background: rgba(34, 197, 94, 0.1);
    color: #4ade80;
}

[data-theme="dark"] .badge-delayed {
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
}

[data-theme="dark"] .badge-rejected,
[data-theme="dark"] .badge-impossible {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

/* ─── PRIORITY ─── */
.prio {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.69rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.prio-l, .prio-n {
    background: var(--surface-2);
    color: var(--text-3);
}

.prio-u, .prio-h {
    background: #fff4ed;
    color: #c2410c;
}

[data-theme="dark"] .prio-u,
[data-theme="dark"] .prio-h {
    background: rgba(249, 115, 22, 0.12);
    color: #fb923c;
}

/* ─── TABLE ─── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: background var(--transition), border-color var(--transition);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead tr {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

th {
    padding: 10px 16px;
    text-align: left;
    font-size: 0.719rem;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-2);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    cursor: pointer;
    transition: background var(--transition);
}

tbody tr:hover td {
    background: var(--surface-2);
    color: var(--text);
}

.jo-number {
    font-family: var(--font-head);
    font-size: 0.75rem;
    color: var(--text-3);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.jo-title {
    color: var(--text);
    font-weight: 500;
}

.jo-dept {
    font-size: 0.75rem;
    color: var(--text-3);
}

/* ─── CARDS / STATS ─── */
.stats-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--border-2);
}

.stat-label {
    font-size: 0.69rem;
    color: var(--text-3);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.stat-value {
    font-family: var(--font-head);
    font-size: 1.625rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-sub {
    font-size: 0.69rem;
    color: var(--text-3);
    margin-top: 4px;
}

.stat-accent {
    color: var(--accent);
}

/* ─── FILTER BAR ─── */
.filter-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-select, .filter-input {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.8rem;
    outline: none;
    transition: border-color var(--transition);
    appearance: none;
    cursor: pointer;
}

.filter-select:focus, .filter-input:focus {
    border-color: var(--accent);
}

.filter-input {
    min-width: 220px;
}

.filter-input::placeholder {
    color: var(--text-3);
}

.filter-spacer {
    flex: 1;
}

/* ─── FORMS ─── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px 24px;
    max-width: 760px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full {
    grid-column: 1 / -1;
}

.form-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-2);
    letter-spacing: 0.01em;
}

.form-label span {
    color: var(--accent);
    margin-left: 2px;
}

.form-control {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.844rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.form-control::placeholder {
    color: var(--text-3);
}

textarea.form-control {
    resize: vertical;
    min-height: 90px;
}

select.form-control {
    appearance: none;
    cursor: pointer;
}

.form-hint {
    font-size: 0.719rem;
    color: var(--text-3);
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 8px;
    margin-top: 4px;
}

.section-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0 20px;
    grid-column: 1 / -1;
}

.section-divider-line {
    flex: 1;
    height: 1px;
    background: var(--border);
}

.section-divider-text {
    font-size: 0.69rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-3);
    text-transform: uppercase;
}

/* ─── EMPTY STATE ─── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-3);
}

.empty-icon {
    font-size: 2.25rem;
    margin-bottom: 12px;
}

.empty-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
}

/* ─── PAGINATION ─── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-3);
}

.page-btns {
    display: flex;
    gap: 4px;
}

.page-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-2);
    font-size: 0.75rem;
    font-family: var(--font-body);
    transition: all var(--transition);
}

.page-btn:hover, .page-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ─── TOAST ─── */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    background: #1e1e1c;
    color: #eee;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateY(-10px);
    opacity: 0;
    transition: all 300ms cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: 10px;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
    .stats-strip {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group.full {
        grid-column: 1;
    }
}

@media (max-width: 680px) {
    .sidebar {
        display: none;
    }

    .stats-strip {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ─── MODAL ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 20px;
    min-width: 260px;
    max-width: 90vw;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-3);
    font-size: 1.125rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}


/* ── CHARTS ─────────────────────────────────────────────── */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}

.chart-card--wide {
    grid-column: 1 / -1;
}

.chart-card-title {
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-3);
    margin-bottom: 1rem;
}

canvas {
    max-height: 280px;
}


/* ── LOGIN ───────────────────────────────────────────────── */
.login-page {
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-wrap {
    width: 100%;
    max-width: 380px;
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo-sub {
    font-size: .8rem;
    color: var(--text-3);
    margin-top: 2px;
}

.login-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: .6rem .9rem;
    font-size: .85rem;
    margin-bottom: 1rem;
}

[data-theme="dark"] .login-error {
    background: #3b1a1a;
    color: #f87171;
    border-color: #7f1d1d;
}

.form-group {
    margin-bottom: 1rem;
}

.login-logo-img {
    width: 100%;
    max-width: 300px;
    height: auto;
    display: block;
    margin: 0 auto .75rem;
}

.login-btn {
    width: 100%;
    margin-top: .5rem;
    text-align: center;
    justify-content: center;
}

.form-add-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: .8rem;
    cursor: pointer;
    padding: .25rem 0;
    margin-top: .25rem;
    display: inline-block;
}

.form-add-link:hover {
    text-decoration: underline;
}

/* ── FLATPICKR DARK THEME ─── */
[data-theme="dark"] .flatpickr-calendar {
    background: var(--surface);
    border-color: var(--border);
    box-shadow: var(--shadow-md);
}

[data-theme="dark"] .flatpickr-day {
    color: var(--text);
}

[data-theme="dark"] .flatpickr-day:hover,
[data-theme="dark"] .flatpickr-day.today {
    background: var(--surface-2);
    border-color: var(--border);
}

[data-theme="dark"] .flatpickr-day.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

[data-theme="dark"] .flatpickr-months,
[data-theme="dark"] .flatpickr-weekdays,
[data-theme="dark"] .flatpickr-weekday {
    background: var(--surface);
    color: var(--text-2);
}

[data-theme="dark"] .flatpickr-current-month,
[data-theme="dark"] .flatpickr-current-month .cur-month,
[data-theme="dark"] .numInputWrapper input {
    color: var(--text);
}

[data-theme="dark"] .flatpickr-day.flatpickr-disabled,
[data-theme="dark"] .flatpickr-day.prevMonthDay,
[data-theme="dark"] .flatpickr-day.nextMonthDay {
    color: var(--text-3);
}