:root {
    --blue: #1266d6;
    --blue-dark: #0c3d82;
    --line: #dbe5f4;
    --soft: #f5f8fc;
    --text: #1d2b3a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Sarabun", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    color: var(--text);
    background: #eef4fb;
}

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 270px;
    background: #fff;
    border-right: 1px solid var(--line);
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
    z-index: 1030;
    transition: transform .2s ease;
}

.brand {
    min-height: 72px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    font-weight: 700;
    color: var(--blue-dark);
    border-bottom: 1px solid var(--line);
}

.brand i {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--blue);
    color: #fff;
    border-radius: 8px;
}

.sidebar .nav { padding: 12px; }

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 42px;
    color: #42566f;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 4px;
    font-weight: 500;
}

.sidebar .nav-link i { width: 20px; text-align: center; color: #7b90aa; }
.sidebar .nav-link.active, .sidebar .nav-link:hover { background: #eaf2ff; color: var(--blue-dark); }
.sidebar .nav-link.active i, .sidebar .nav-link:hover i { color: var(--blue); }

.main { margin-left: 270px; width: calc(100% - 270px); }

.sidebar-collapsed .sidebar { transform: translateX(-100%); }
.sidebar-collapsed .main { margin-left: 0; width: 100%; }

.topbar {
    min-height: 72px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; color: var(--blue-dark); }
.topbar p { margin: 3px 0 0; color: #6d7c8e; }

.content { padding: 24px; }

.panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}

.panel-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--blue-dark);
    margin-bottom: 14px;
}

.metric {
    background: linear-gradient(180deg, #ffffff 0%, #f4f8ff 100%);
    border: 1px solid #bfd3ef;
    border-radius: 8px;
    padding: 16px;
    height: 100%;
    box-shadow: 0 10px 26px rgba(18, 102, 214, .08);
    position: relative;
    overflow: hidden;
}

.metric::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: var(--blue);
}

.metric.is-green { border-color: #acd8c2; background: linear-gradient(180deg, #ffffff, #f0fbf5); }
.metric.is-green::before { background: #25a55f; }
.metric.is-orange { border-color: #f2d2a9; background: linear-gradient(180deg, #ffffff, #fff7ed); }
.metric.is-orange::before { background: #e58a17; }
.metric.is-red { border-color: #efbfc7; background: linear-gradient(180deg, #ffffff, #fff3f5); }
.metric.is-red::before { background: #d6405a; }

.metric .label { color: #607187; margin-bottom: 8px; }
.metric .value { font-size: 24px; font-weight: 700; color: var(--blue-dark); }
.row.g-3.mb-3 > .col-md-3:nth-child(2) .metric { border-color: #acd8c2; background: linear-gradient(180deg, #ffffff, #f0fbf5); }
.row.g-3.mb-3 > .col-md-3:nth-child(2) .metric::before { background: #25a55f; }
.row.g-3.mb-3 > .col-md-3:nth-child(3) .metric { border-color: #f2d2a9; background: linear-gradient(180deg, #ffffff, #fff7ed); }
.row.g-3.mb-3 > .col-md-3:nth-child(3) .metric::before { background: #e58a17; }
.row.g-3.mb-3 > .col-md-3:nth-child(4) .metric { border-color: #efbfc7; background: linear-gradient(180deg, #ffffff, #fff3f5); }
.row.g-3.mb-3 > .col-md-3:nth-child(4) .metric::before { background: #d6405a; }

.btn { border-radius: 8px; font-weight: 600; }
.btn-primary { background: var(--blue); border-color: var(--blue); }
.btn-light { border-color: var(--line); background: #fff; }
.icon-btn { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 0; }

.form-control, .form-select { border-radius: 8px; border-color: #cfd9e8; min-height: 40px; }
.form-label { font-weight: 600; color: #34455c; }

.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100% !important; min-width: 960px; vertical-align: middle; }
.table thead th { background: #f3f7fd; color: #28425f; white-space: nowrap; }
.table td, .table th { white-space: nowrap; }
.dataTables_wrapper, .dataTables_scroll, .dataTables_scrollHead, .dataTables_scrollBody { width: 100% !important; }
.dataTables_scrollHeadInner { width: 100% !important; }
.dataTables_scrollHeadInner table { width: 100% !important; }

.user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f2f6fc;
    border: 1px solid var(--line);
    border-radius: 999px;
}
.user-pill a { color: #cc2b2b; }

.app-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.72);
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #eef6ff, #ffffff);
}

.login-box {
    width: min(430px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 18px 60px rgba(23, 79, 141, .12);
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main { width: 100%; margin-left: 0; }
    .topbar { padding: 12px 16px; }
    .content { padding: 16px; }
    .user-pill span { display: none; }
}

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main { margin: 0; width: 100%; }
    .content { padding: 0; }
    .panel { border: 0; }
}
