/* =====================================================================
   QL HỢP ĐỒNG - Giao diện
   Bảng màu và bố cục lấy đúng theo ảnh mẫu "Mau clone.png"
   ===================================================================== */

:root {
    --bg:            #eef2f7;
    --header:        #0f172a;
    --nav:           #1e293b;
    --nav-active:    #0f172a;
    --nav-text:      #cbd5e1;
    --accent:        #60a5fa;
    --primary:       #2563eb;
    --primary-d:     #1e3a8a;
    --primary-l:     #dbeafe;
    --card:          #ffffff;
    --text:          #0f172a;
    --text-2:        #334155;
    --muted:         #64748b;
    --border:        #e5e7eb;
    --border-2:      #eef2f7;
    --ok:            #16a34a;
    --ok-bg:         #dcfce7;
    --warn:          #d97706;
    --warn-bg:       #fef3c7;
    --danger:        #dc2626;
    --danger-bg:     #fee2e2;
    --info:          #0284c7;
    --info-bg:       #e0f2fe;
    --radius:        14px;
    --radius-sm:     8px;
    --shadow:        0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md:     0 8px 24px rgba(15, 23, 42, .10);
    --mono:          ui-monospace, SFMono-Regular, "Segoe UI Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    font-size: 13px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =====================================================================
   HEADER
   ===================================================================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    height: 50px;
    background: var(--header);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    color: #fff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .2px;
    white-space: nowrap;
}
.brand .logo-ico { font-size: 18px; }
.brand .badge-ver {
    background: #2f3c50;
    color: #cbd5e1;
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 6px;
    letter-spacing: .3px;
}

.company {
    flex: 1 1 auto;
    text-align: center;
    font-size: 12.5px;
    font-weight: 600;
    color: #e2e8f0;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--nav);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12.5px;
    color: #e2e8f0;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-chip:hover { background: #273449; text-decoration: none; color: #fff; }

.btn-logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 7px 16px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn-logout:hover { background: #1d4ed8; color: #fff; text-decoration: none; }

/* =====================================================================
   NAV TABS
   ===================================================================== */
.tabs {
    position: sticky;
    top: 50px;
    z-index: 55;
    background: var(--nav);
    display: flex;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}
.tabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-thumb { background: #334155; }

.tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 12px 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--nav-text);
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    background: transparent;
}
.tab:hover { color: #fff; background: rgba(255, 255, 255, .04); text-decoration: none; }
.tab.active {
    background: var(--nav-active);
    color: #fff;
    border-bottom-color: var(--accent);
}
.tab .ico { font-size: 14px; }

/* =====================================================================
   KHUNG NỘI DUNG
   ===================================================================== */
.wrap {
    max-width: 1700px;
    margin: 0 auto;
    padding: 0 20px 40px;
}

.crumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    padding: 12px 0 0;
}
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--primary); }
.crumb .sep { opacity: .55; }

/* Hero */
.hero {
    margin-top: 12px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--primary-d) 0%, var(--primary) 100%);
    color: #fff;
    padding: 24px 28px;
    box-shadow: var(--shadow-md);
}
.hero h1 {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: .2px;
}
.hero p {
    margin: 0;
    font-size: 13px;
    color: #bfdbfe;
}
.hero .hero-sep { opacity: .55; margin: 0 8px; }

/* =====================================================================
   HOME TILES
   ===================================================================== */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin: 20px 0 22px;
}

.tile {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 128px;
    padding: 16px 18px;
    border-radius: var(--radius);
    border: 1px solid rgba(15, 23, 42, .06);
    background: #fff;
    color: var(--text);
    cursor: pointer;
    transition: transform .12s ease, box-shadow .12s ease;
    text-align: left;
    font-family: inherit;
}
.tile:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: var(--text);
}
.tile .tile-ico { font-size: 28px; line-height: 1; }
.tile .tile-text { margin-top: 15px; }
.tile .tile-t { font-size: 13.5px; font-weight: 700; }
.tile .tile-s { font-size: 11.5px; color: #475569; margin-top: 4px; }

.t-blue   { background: linear-gradient(135deg, #eef6ff 0%, #dcebfe 100%); }
.t-amber  { background: linear-gradient(135deg, #fef3c5 0%, #fde68c 100%); }
.t-green  { background: linear-gradient(135deg, #dbfce7 0%, #bcf7d1 100%); }
.t-purple { background: linear-gradient(135deg, #f3e8ff 0%, #e9d5ff 100%); }
.t-white  { background: #ffffff; }

/* =====================================================================
   KPI
   ===================================================================== */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin: 18px 0;
}
.kpi {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.kpi .kpi-l {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .3px;
}
.kpi .kpi-v {
    font-size: 21px;
    font-weight: 700;
    margin-top: 6px;
    color: var(--text);
    line-height: 1.2;
}
.kpi .kpi-v small { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi.accent { background: linear-gradient(135deg, #1e3a8a, #2563eb); border-color: transparent; }
.kpi.accent .kpi-l { color: #bfdbfe; }
.kpi.accent .kpi-v { color: #fff; }

/* =====================================================================
   CARD / BẢNG
   ===================================================================== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 18px;
}
.card-h {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
}
.card-h h3 {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text);
}
.card-h .sub { font-size: 11.5px; color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.card-h .tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-b { padding: 16px 18px; }
.card-b.flush { padding: 0; }

.tbl-scroll { overflow-x: auto; }

table.tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}
table.tbl th {
    background: #f8fafc;
    color: var(--text-2);
    font-size: 11.5px;
    font-weight: 700;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}
table.tbl td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-2);
    color: #1e293b;
    vertical-align: top;
}
table.tbl tbody tr:hover td { background: #f8fafc; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl td.ctr, table.tbl th.ctr { text-align: center; }
table.tbl .code { font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--primary-d); }
table.tbl tr.grp td { background: #f1f5f9; font-weight: 700; color: var(--text); }
table.tbl tfoot td { background: #f8fafc; font-weight: 700; border-top: 2px solid var(--border); }

.empty {
    padding: 34px 18px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; opacity: .6; }

/* =====================================================================
   BADGE / TIẾN ĐỘ
   ===================================================================== */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    border: 1px solid transparent;
}
.badge.blue   { background: var(--primary-l); color: #1d4ed8; }
.badge.green  { background: var(--ok-bg);     color: #15803d; }
.badge.amber  { background: var(--warn-bg);   color: #b45309; }
.badge.red    { background: var(--danger-bg); color: #b91c1c; }
.badge.gray   { background: #f1f5f9;          color: #475569; }
.badge.cyan   { background: var(--info-bg);   color: #0369a1; }
.badge.purple { background: #f3e8ff;          color: #7e22ce; }

.pg {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 130px;
}
.pg-bar {
    flex: 1 1 auto;
    height: 7px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    min-width: 54px;
}
.pg-bar > i { display: block; height: 100%; border-radius: 999px; }
.pg-low  > .pg-bar > i { background: #ef4444; }
.pg-mid  > .pg-bar > i { background: #f59e0b; }
.pg-ok   > .pg-bar > i { background: #22c55e; }
.pg-txt  { font-size: 11.5px; font-weight: 700; color: var(--text-2); min-width: 42px; text-align: right; }

/* =====================================================================
   NÚT
   ===================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 12.5px;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    background: #f1f5f9;
    color: var(--text-2);
    white-space: nowrap;
    line-height: 1.3;
}
.btn:hover { background: #e2e8f0; text-decoration: none; color: var(--text); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; color: #fff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-ghost { background: #fff; border-color: #cbd5e1; color: var(--text-2); }
.btn-ghost:hover { background: #f8fafc; }
.btn-sm { padding: 4px 9px; font-size: 11.5px; border-radius: 6px; }
.btn-icon { padding: 4px 8px; font-size: 13px; background: transparent; border-color: transparent; }
.btn-icon:hover { background: #e2e8f0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* =====================================================================
   FORM
   ===================================================================== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 13px 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid .span2 { grid-column: span 2; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label {
    font-size: 11.5px;
    font-weight: 600;
    color: #475569;
    letter-spacing: .1px;
}
.field > label .req { color: var(--danger); margin-left: 3px; }
.field .hint { font-size: 11px; color: var(--muted); }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=email], input[type=tel], input[type=search],
input[type=file], select, textarea {
    width: 100%;
    padding: 8px 10px;
    font-size: 12.5px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
input[readonly], input:disabled, select:disabled, textarea[readonly] {
    background: #f1f5f9;
    color: #475569;
    cursor: not-allowed;
}
textarea { min-height: 68px; resize: vertical; line-height: 1.5; }
select { cursor: pointer; }

fieldset.fs {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px 16px;
    margin: 0 0 16px;
    background: #fcfdff;
}
fieldset.fs > legend {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-d);
    padding: 0 8px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.actions {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
    padding-top: 4px;
}
.actions .spacer { flex: 1 1 auto; }

/* Bảng nhập nhiều dòng (vật tư / khoản chi) */
table.grid-input { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.grid-input th {
    background: #f1f5f9;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-2);
    padding: 7px 8px;
    text-align: left;
    border: 1px solid var(--border);
    white-space: nowrap;
}
table.grid-input td { padding: 4px 5px; border: 1px solid var(--border); vertical-align: middle; }
table.grid-input input, table.grid-input select { padding: 6px 7px; font-size: 12px; }
table.grid-input td.idx { text-align: center; font-weight: 700; color: var(--muted); width: 42px; }
table.grid-input td.act { width: 46px; text-align: center; }

/* Bộ lọc */
.filters {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: #fbfcfe;
}
.filters .field { min-width: 150px; }
.filters .field.grow { flex: 1 1 240px; }
.filters .spacer { flex: 1 1 auto; }

/* Thông tin nhanh */
.info-box {
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 12px;
    border: 1px solid;
    margin-top: 8px;
    display: none;
}
.info-box.show { display: block; }
.info-box.ok   { background: var(--ok-bg);     border-color: #86efac; color: #166534; }
.info-box.err  { background: var(--danger-bg); border-color: #fca5a5; color: #991b1b; }
.info-box.warn { background: var(--warn-bg);   border-color: #fcd34d; color: #92400e; }
.info-box.info { background: var(--info-bg);   border-color: #7dd3fc; color: #075985; }

/* Autocomplete */
.ac-wrap { position: relative; }
.ac-list {
    position: absolute;
    z-index: 40;
    left: 0; right: 0;
    top: calc(100% + 2px);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 260px;
    overflow-y: auto;
    display: none;
}
.ac-list.show { display: block; }
.ac-item { padding: 8px 11px; cursor: pointer; font-size: 12.5px; border-bottom: 1px solid var(--border-2); }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.sel { background: #eff6ff; }
.ac-item .ac-code { font-family: var(--mono); font-weight: 700; color: var(--primary-d); }
.ac-item .ac-name { color: var(--text-2); }
.ac-item .ac-meta { font-size: 11px; color: var(--muted); }
.ac-item mark { background: #fde68a; padding: 0 1px; border-radius: 2px; }

/* Phân trang */
.pager {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
}
.pager .pl { color: var(--muted); margin-right: 6px; }
.pager a, .pager span.pg-n {
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-2);
    font-weight: 600;
}
.pager a:hover { background: #f1f5f9; text-decoration: none; }
.pager span.pg-n.cur { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager span.pg-n.dis { opacity: .45; }

/* Toast */
#toasts {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 9px;
    max-width: 380px;
}
.toast {
    border-radius: 10px;
    padding: 11px 15px;
    font-size: 12.5px;
    font-weight: 600;
    color: #fff;
    box-shadow: var(--shadow-md);
    animation: toastIn .18s ease;
}
.toast.ok  { background: #16a34a; }
.toast.err { background: #dc2626; }
.toast.info{ background: #2563eb; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Nút nổi về trang chủ */
.fab-home {
    position: fixed;
    left: 18px;
    bottom: 18px;
    z-index: 90;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    box-shadow: var(--shadow-md);
}
.fab-home:hover { background: #1d4ed8; color: #fff; text-decoration: none; }

/* Đăng nhập */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #2563eb 100%);
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(2, 6, 23, .45);
    padding: 30px 30px 26px;
}
.login-card .lc-logo { font-size: 30px; text-align: center; }
.login-card h1 { margin: 8px 0 2px; font-size: 19px; text-align: center; }
.login-card .lc-sub { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 20px; }
.login-card .field { margin-bottom: 13px; }
.login-card .btn { width: 100%; padding: 10px; font-size: 13.5px; }
.login-foot { text-align: center; margin-top: 16px; font-size: 11.5px; color: var(--muted); }

.alert {
    border-radius: var(--radius-sm);
    padding: 10px 13px;
    font-size: 12.5px;
    margin-bottom: 14px;
    border: 1px solid;
}
.alert.err  { background: var(--danger-bg); border-color: #fca5a5; color: #991b1b; }
.alert.ok   { background: var(--ok-bg);     border-color: #86efac; color: #166534; }
.alert.warn { background: var(--warn-bg);   border-color: #fcd34d; color: #92400e; }
.alert.info { background: var(--info-bg);   border-color: #7dd3fc; color: #075985; }

/* Tiện ích */
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 260px; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.strong { font-weight: 700; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.mb16 { margin-bottom: 16px; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.hidden { display: none !important; }
.txt-ok { color: var(--ok); }
.txt-err { color: var(--danger); }
.txt-warn { color: var(--warn); }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.pill-list { display: flex; gap: 6px; flex-wrap: wrap; }

/* Bảng báo cáo 2 tầng tiêu đề */
table.tbl thead tr.g2 th { top: 33px; }
table.tbl thead th.grp { text-align: center; background: #eef2f7; color: var(--primary-d); }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 1000px) {
    .company { display: none; }
    .tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
    .wrap { padding: 0 12px 32px; }
    .form-grid .span2 { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
    .topbar { padding: 0 12px; height: 46px; gap: 8px; }
    .tabs { top: 46px; }
    .tab { padding: 10px 12px; font-size: 12.5px; }
    .user-chip { display: none; }
    .hero { padding: 18px 18px; }
    .hero h1 { font-size: 18px; }
    .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
    .tile { min-height: 108px; padding: 12px; }
    .kpis { grid-template-columns: 1fr 1fr; }
    .filters { padding: 12px; }
    .filters .field { min-width: 130px; }
    .fab-home { width: 40px; height: 40px; font-size: 17px; left: 12px; bottom: 12px; }
}

/* Khối chỉ hiện khi in */
.print-only { display: none; }

/* =====================================================================
   IN ẤN
   ===================================================================== */
@media print {
    @page { size: A4 landscape; margin: 10mm; }
    body { background: #fff; font-size: 10pt; }
    .topbar, .tabs, .crumb, .filters, .pager, .actions, .fab-home, #toasts,
    .no-print, .card-h .tools { display: none !important; }
    .print-only { display: block !important; }
    .wrap { max-width: none; padding: 0; }
    .card { border: 0; box-shadow: none; margin: 0; }
    .card-h { padding: 0 0 6px; border-bottom: 1.5pt solid #000; }
    .card-h h3 { font-size: 13pt; }
    table.tbl { font-size: 8.5pt; }
    table.tbl th { background: #e8eefc !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    table.tbl th, table.tbl td { border: .5pt solid #64748b; padding: 3pt 4pt; }
    a { color: #000; text-decoration: none; }
    tr { page-break-inside: avoid; }
}
