/* ==========================================================================
   CBO Portal — hệ thống giao diện dựng theo bộ màn hình mẫu trong tài liệu
   đề xuất giải pháp (Hình 4 đến Hình 11).
   ========================================================================== */

:root {
    --green-900: #123a2c;
    --green-800: #14532d;
    --green-700: #166534;
    --green-500: #4faf62;
    --green-50: #f0fdf4;
    --green-100: #dcfce7;

    --ink: #111827;
    --ink-soft: #374151;
    --muted: #6b7280;
    --muted-light: #9ca3af;
    --line: #e5e7eb;
    --line-soft: #f3f4f6;
    --surface: #ffffff;
    --surface-alt: #f9fafb;

    --red: #b91c1c;
    --red-bg: #fee2e2;
    --amber: #92400e;
    --amber-bg: #fef3c7;
    --amber-line: #f59e0b;
    --blue: #1d4ed8;
    --blue-bg: #dbeaff;

    --mono: ui-monospace, "Cascadia Mono", "Consolas", "Courier New", monospace;
    --radius: 5px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    font-family: "Segoe UI", "Inter", -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1560px; margin: 0 auto; padding: 0 16px; }

/* ---------------------------------------------------------------- Thanh trên */

.topbar { background: var(--green-900); color: #fff; }

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 12px 16px 0;
    max-width: 1560px;
    margin: 0 auto;
    flex-wrap: wrap;
}

.brand { font-size: 17px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand .mk { color: var(--green-500); }
.brand .sep { color: rgba(255,255,255,.4); margin: 0 6px; font-weight: 400; }

.mainnav { display: flex; gap: 22px; flex: 1; flex-wrap: wrap; }

.mainnav a {
    color: rgba(255,255,255,.82);
    font-size: 14px;
    padding-bottom: 12px;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.mainnav a:hover { color: #fff; text-decoration: none; }
.mainnav a.on { color: #fff; font-weight: 600; border-bottom-color: var(--green-500); }

.topmeta {
    color: rgba(255,255,255,.66);
    font-size: 12px;
    padding-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.topmeta .dot { opacity: .5; }
.topmeta form { display: inline; }

.linkbtn {
    background: none;
    border: 0;
    color: rgba(255,255,255,.66);
    font: inherit;
    cursor: pointer;
    padding: 0;
}

.linkbtn:hover { color: #fff; text-decoration: underline; }

/* ---------------------------------------------------------------- Thanh trạng thái */

.statusbar {
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    font-size: 12.5px;
    color: var(--muted);
}

.statusbar-inner {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 16px;
    max-width: 1560px;
    margin: 0 auto;
    flex-wrap: wrap;
}

.statusbar b { color: var(--ink-soft); }
.status-ok { color: var(--green-700); font-weight: 600; }
.status-warn { color: var(--amber); font-weight: 600; }
.status-bad { color: var(--red); font-weight: 600; }

/* ---------------------------------------------------------------- Bộ lọc */

.filterbar {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin: 14px 0;
    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 130px; }

.field > label {
    font-size: 10.5px;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}

select, input[type=text], input[type=number], input[type=date], input[type=password], textarea {
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 7px 9px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--ink);
    background: #fff;
    min-height: 34px;
}

select:focus, input:focus, textarea:focus { outline: 2px solid var(--green-500); outline-offset: -1px; }
textarea { resize: vertical; min-height: 72px; }

.btn {
    border-radius: 4px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    font-family: inherit;
    min-height: 34px;
    white-space: nowrap;
}

.btn-primary { background: var(--green-800); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn-outline { background: #fff; color: var(--ink); border-color: #d1d5db; }
.btn-outline:hover { background: var(--surface-alt); }
.btn-accent { background: #b5502a; color: #fff; }
.btn-accent:hover { background: #9d4423; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; min-height: 28px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------- Thẻ số liệu */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }

.kpi {
    border: 1px solid var(--line);
    border-left: 4px solid var(--muted);
    border-radius: var(--radius);
    padding: 12px 14px;
}

.kpi .k-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .6px;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 6px;
}

.kpi .k-value { font-size: 27px; font-weight: 700; line-height: 1.15; letter-spacing: -.5px; }
.kpi .k-note { font-size: 12px; color: var(--muted); margin-top: 5px; }

.kpi.blue { border-left-color: #2563eb; } .kpi.blue .k-label { color: #2563eb; }
.kpi.red { border-left-color: #dc2626; } .kpi.red .k-label { color: #dc2626; }
.kpi.green { border-left-color: var(--green-700); } .kpi.green .k-label { color: var(--green-700); }
.kpi.amber { border-left-color: var(--amber-line); } .kpi.amber .k-label { color: var(--amber); }
.kpi.gray { border-left-color: var(--muted-light); }

/* ---------------------------------------------------------------- Khối nội dung */

.grid { display: grid; gap: 16px; align-items: start; }
.grid.split { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.grid.split-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.side-left { grid-template-columns: minmax(0, .62fr) minmax(0, 1.38fr); }

@media (max-width: 1180px) {
    .grid.split, .grid.split-even, .grid.side-left { grid-template-columns: minmax(0, 1fr); }
}

.card { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.card > h2 {
    margin: 0;
    padding: 13px 15px;
    font-size: 14px;
    font-weight: 700;
    border-bottom: 1px solid var(--line);
}
.card > h2 .sub { font-weight: 400; color: var(--muted); font-size: 13px; }
.card-body { padding: 14px 15px; }
.card-foot { padding: 12px 15px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Bảng */

.table-scroll { overflow-x: auto; }

table.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }

table.grid-table th {
    text-align: left;
    font-size: 10.5px;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
    background: var(--surface-alt);
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

table.grid-table td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid-table tbody tr:hover { background: #fcfdfc; }
table.grid-table tbody tr:last-child td { border-bottom: 0; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mid { text-align: center; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.strong { font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* Ba cột nền xanh nhạt là kết quả trung gian của Engine (Hình 5). */
.engine-col { background: #eff6f1; }
th.engine-col { background: #e6efe9; }

/* Cột Q_Final — con số duy nhất được dùng để đặt hàng. */
.qfinal { background: var(--green-800); color: #fff; font-weight: 700; text-align: right; }
.qfinal a { color: #fff; text-decoration: underline; }

.delta-up { color: #b45309; font-weight: 600; }
.delta-down { color: #b91c1c; font-weight: 600; }

/* ---------------------------------------------------------------- Nhãn trạng thái */

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-green { background: var(--green-100); color: var(--green-700); }
.badge-green-solid { background: var(--green-800); color: #fff; }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: var(--line-soft); color: #4b5563; }
.badge-purple { background: #f3e8ff; color: #7e22ce; }

.chip-green { color: var(--green-700); font-weight: 600; }
.chip-amber { color: var(--amber); font-weight: 600; }
.chip-red { color: var(--red); font-weight: 600; }
.chip-blue { color: var(--blue); font-weight: 600; }

/* ---------------------------------------------------------------- Hộp ghi chú */

.note { border-radius: 4px; padding: 11px 13px; font-size: 12.5px; line-height: 1.55; margin: 0 0 14px; }
.note b { font-weight: 700; }
.note-amber { background: #fffbeb; border-left: 3px solid var(--amber-line); color: var(--amber); }
.note-green { background: var(--green-50); border-left: 3px solid #16a34a; color: #14532d; }
.note-blue { background: #eff6ff; border-left: 3px solid #3b82f6; color: #1e40af; }
.note-red { background: #fef2f2; border-left: 3px solid #ef4444; color: var(--red); }

.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-soft); align-items: center; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------------------------------------------------------------- Bảng khoá — giá trị */

table.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.kv th {
    text-align: left;
    font-weight: 500;
    color: var(--muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--line-soft);
    width: 44%;
    vertical-align: top;
}
table.kv td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); font-weight: 600; }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: 0; }
table.kv tr.hl th { background: var(--green-800); color: #fff; font-weight: 600; }
table.kv tr.hl td { background: var(--green-800); color: #fff; font-size: 17px; text-align: right; }

/* ---------------------------------------------------------------- Truy vết */

tr.trace-final td { background: var(--green-800); color: #fff; font-weight: 600; }
tr.trace-final .badge { background: #fde68a; color: #78350f; }
.src { font-size: 10.5px; font-weight: 700; letter-spacing: .3px; }

/* ---------------------------------------------------------------- Biểu đồ cột */

.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding: 8px 2px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 22px; }
.bar-oos { background: #b91c1c; border-radius: 2px 2px 0 0; }
.bar-in { background: var(--green-800); }
.bar-label { text-align: center; font-size: 10px; color: var(--muted); margin-top: 5px; }

/* ---------------------------------------------------------------- Đăng nhập */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--green-900) 0%, #0b241c 100%);
    padding: 24px;
}

.login-card {
    background: #fff;
    border-radius: 8px;
    width: 100%;
    max-width: 940px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, .9fr);
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
}

@media (max-width: 820px) { .login-card { grid-template-columns: minmax(0, 1fr); } }

.login-left { padding: 38px 34px; }
.login-left h1 { font-size: 21px; margin: 0 0 6px; }
.login-left p.lead { color: var(--muted); font-size: 13.5px; margin: 0 0 24px; }
.login-form .field { min-width: 0; margin-bottom: 14px; }
.login-form input { width: 100%; }

.remember { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 2px 0 18px; }
.remember input { width: 15px; height: 15px; min-height: 0; margin: 0; flex: none; }
.remember span { white-space: nowrap; }

.login-right { background: var(--surface-alt); border-left: 1px solid var(--line); padding: 30px 28px; }
.login-right h3 { font-size: 13px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.login-right table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.login-right td { padding: 6px 0; border-bottom: 1px solid var(--line); }
.login-right tr:last-child td { border-bottom: 0; }

/* ---------------------------------------------------------------- Khác */

.page-alert { margin: 14px 0 0; }
.pager { display: flex; gap: 8px; align-items: center; padding: 12px 15px; font-size: 13px; color: var(--muted); }
.checkbox-cell { width: 30px; text-align: center; }
.required::after { content: " *"; color: #dc2626; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
h1.page-title { font-size: 18px; margin: 16px 0 4px; }
footer.site-foot { padding: 22px 16px 32px; color: var(--muted-light); font-size: 12px; text-align: center; }
