/* =====================================================================
   KPI Dashboard — Kin Kin Logistics
   Internal ops dashboard: trust-first, data-dense, light theme locked.

   Design tokens
   - ONE accent: Kin Kin brand red #d63a45 (hover #c22f3a)
   - Neutral base: zinc grays on near-white canvas
   - Data colors (KPI scores / status ONLY): 4=#16a34a 3=#d97706 2=#ea580c 1=#dc2626
   - Radius scale: 10px cards / 8px inputs+buttons / pill badges
   - Motion: 150–200ms ease, prefers-reduced-motion respected
   ===================================================================== */

:root {
    /* Accent (UI interactive) */
    --accent:       #d63a45;
    --accent-hover: #c22f3a;
    --accent-bg:    rgba(214, 58, 69, 0.08);
    --accent-ring:  rgba(214, 58, 69, 0.22);

    /* Neutrals (zinc) */
    --ink:      #18181b;
    --ink-2:    #3f3f46;
    --muted:    #71717a;
    --faint:    #a1a1aa;
    --line:     #e4e4e7;
    --line-soft:#f1f1f3;
    --canvas:   #fafafa;
    --surface:  #ffffff;
    --well:     #f7f7f8;

    /* Data colors — KPI score badges 1–4 and status pills ONLY */
    --score-4: #16a34a;
    --score-3: #d97706;
    --score-2: #ea580c;
    --score-1: #dc2626;
    /* AA-safe text shades of the same families (for text on light bg) */
    --score-4-text: #15803d;
    --score-3-text: #b45309;
    --score-2-text: #c2410c;
    --score-1-text: #b91c1c;
    --score-4-bg: rgba(22, 163, 74, 0.10);
    --score-3-bg: rgba(217, 119, 6, 0.10);
    --score-2-bg: rgba(234, 88, 12, 0.10);
    --score-1-bg: rgba(220, 38, 38, 0.10);

    /* Radius scale (documented): cards 10 / controls 8 / badges pill */
    --r-card: 10px;
    --r-ctl:  8px;
    --r-pill: 999px;

    --nav-h: 64px;
    --content-max: 1400px;

    --shadow-card: 0 1px 2px rgba(24, 24, 27, 0.04);
    --shadow-modal: 0 20px 50px rgba(24, 24, 27, 0.22);

    --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --ease: cubic-bezier(0.25, 0.6, 0.3, 1);
}

/* === Reset / base === */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--canvas);
    padding-top: var(--nav-h);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; }
img { max-width: 100%; }
button { font-family: inherit; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* === Utilities (kept close to original JS templates) === */
.text-center  { text-align: center; }
.text-end     { text-align: right; }
.text-muted   { color: var(--muted); }
.text-faint   { color: var(--muted); }
.text-success { color: var(--score-4-text); }
.text-warning { color: var(--score-3-text); }
.text-danger  { color: var(--score-1-text); }
.small        { font-size: 12.5px; }
.fw-bold      { font-weight: 600; }
.num          { text-align: right; font-variant-numeric: tabular-nums; }

/* =====================================================================
   Top navbar — fixed, 64px, single line
   ===================================================================== */
.topnav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 100;
}
.topnav-inner {
    max-width: var(--content-max);
    height: 100%;
    margin: 0 auto;
    padding: 0 clamp(16px, 3vw, 32px);
    display: flex;
    align-items: center;
    gap: 20px;
}
.topnav-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
    color: var(--ink);
    white-space: nowrap;
}
.brand-mark {
    width: 30px; height: 30px;
    border-radius: var(--r-ctl);
    background: var(--accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.topnav-menu {
    display: flex;
    align-items: center;
    align-self: stretch;
    gap: 2px;
    min-width: 0;
}
.topnav-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 100%;
    padding: 0 13px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.topnav-link i { font-size: 14px; }
.topnav-link:hover { color: var(--ink); background: var(--well); }
.topnav-link.active { color: var(--accent); }
.topnav-link.active::after {
    content: "";
    position: absolute;
    left: 10px; right: 10px; bottom: -1px;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: var(--accent);
}

.topnav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}
.sync-chip {
    font-size: 12px;
    color: var(--muted);
    background: var(--well);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    padding: 4px 11px;
    font-variant-numeric: tabular-nums;
}

/* Language toggle — segmented */
.lang-toggle {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    overflow: hidden;
    background: var(--well);
}
.lang-btn {
    border: 0;
    background: transparent;
    padding: 5px 10px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.lang-btn:hover { color: var(--ink); }
.lang-btn.active { background: var(--ink); color: #fff; }

/* Hamburger (shown < 900px) */
.nav-toggle {
    display: none;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: var(--r-ctl);
    width: 36px; height: 36px;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--ink-2);
    cursor: pointer;
}

/* =====================================================================
   Page layout
   ===================================================================== */
.container {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 22px clamp(16px, 3vw, 32px) 48px;
}

.page-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 18px;
}
.page-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.015em;
}
.page-subtitle { font-size: 13px; color: var(--muted); }

.section-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 26px 0 12px;
}
.section-title:first-child { margin-top: 0; }

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.section-head .section-title { margin: 0; }

/* Section switching: one subtle fade/slide */
.page-section { animation: sectionIn 0.2s var(--ease) both; }
@keyframes sectionIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* =====================================================================
   Cards
   ===================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}
.card + .card, .card + .cards-row, .cards-row + .card { margin-top: 16px; }
.mb { margin-bottom: 16px; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--line-soft);
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink);
}
.card-header i { color: var(--muted); }
.card-body { padding: 16px; }
.card-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-top: 1px solid var(--line-soft);
    background: var(--surface);
}
.card-footer .ms-auto, .toolbar-count { margin-left: auto; }

/* Toolbar row inside a card (quick search) */
.card-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line-soft);
}
.card-toolbar > i { color: var(--faint); font-size: 14px; }
.toolbar-count { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* =====================================================================
   Grids
   ===================================================================== */
.filter-grid {
    display: grid;
    grid-template-columns: minmax(180px, 3fr) minmax(140px, 2fr) minmax(330px, 5.5fr) minmax(90px, 1.2fr);
    gap: 14px;
    align-items: end;
}
.mail-filter-grid {
    display: grid;
    grid-template-columns: minmax(300px, 5fr) minmax(90px, 1.2fr) minmax(160px, 2.5fr) minmax(200px, 2.8fr);
    gap: 14px;
    align-items: end;
}
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin: 16px 0;
}
.email-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
    gap: 16px;
    align-items: start;
    margin-top: 16px;
}
.email-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.sync-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 16px 0;
}
.help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.help-grid .card { margin: 0; }
.rules-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
}
.rules-grid .card { margin: 0; }

/* =====================================================================
   Forms
   ===================================================================== */
.field { min-width: 0; }
.field-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 5px;
}
.field-hint { color: var(--muted); font-weight: 400; }
.helper-text { font-size: 12px; color: var(--muted); margin-top: 5px; }

.input {
    width: 100%;
    height: 34px;
    padding: 6px 11px;
    font-family: var(--font);
    font-size: 13.5px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input::placeholder { color: var(--faint); }
.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}
select.input { cursor: pointer; }
textarea.input { height: auto; }
.input[type="number"] { font-variant-numeric: tabular-nums; }

.input-clearable { position: relative; }
.input-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--faint);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.15s var(--ease);
}
.input-clear:hover { color: var(--ink); }
.input-clearable .input { padding-right: 30px; }

.form-field { margin-bottom: 14px; }
.form-field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 5px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ink-2);
    cursor: pointer;
}
input[type="checkbox"] {
    width: 15px; height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
    margin: 0;
}

.status-line { font-size: 12.5px; margin-top: 8px; min-height: 18px; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    border: 1px solid transparent;
    border-radius: var(--r-ctl);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
                color 0.15s var(--ease), transform 0.1s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled, .btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-outline {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink-2);
}
.btn-outline:hover:not(:disabled) { background: var(--well); border-color: var(--faint); color: var(--ink); }

.btn-icon { padding: 6px 8px; }
.btn-danger-ghost { color: var(--score-1-text); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--score-1-bg); border-color: var(--score-1-text); color: var(--score-1-text); }

.btn-block { flex: 1 1 0; }

/* =====================================================================
   Month selector chips
   ===================================================================== */
.month-selector { display: flex; flex-wrap: wrap; gap: 4px; }
.month-btn {
    padding: 6px 0;
    width: 40px;
    text-align: center;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    cursor: pointer;
    font-variant-numeric: tabular-nums;
    transition: background 0.15s var(--ease), color 0.15s var(--ease),
                border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.month-btn:hover { background: var(--well); border-color: var(--faint); }
.month-btn:active { transform: scale(0.96); }
.month-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* =====================================================================
   Tables
   ===================================================================== */
.table-scroll { overflow-x: auto; }
.table-scroll-y { overflow-y: auto; }
.h-500 { max-height: 500px; }
.h-400 { max-height: 400px; }
.h-300 { max-height: 300px; }

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

thead th {
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    background: var(--canvas);
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
thead th.num { text-align: right; }

/* Sticky header inside vertical scroll containers */
.table-scroll-y thead th,
.modal-custom .table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

tbody td {
    padding: 9px 12px;
    font-size: 13.5px;
    color: var(--ink);
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s var(--ease); }
tbody tr:hover { background: var(--well); }
td.num, .tabular { font-variant-numeric: tabular-nums; }

/* Sortable headers */
.sortable { cursor: pointer; user-select: none; transition: color 0.15s var(--ease); }
.sortable::after { content: " \2195"; color: var(--faint); font-size: 10px; }
.sortable:hover { color: var(--ink); }
.sortable.active-asc, .sortable.active-desc { color: var(--accent); }
.sortable.active-asc::after  { content: " \25B2"; color: var(--accent); font-size: 9px; }
.sortable.active-desc::after { content: " \25BC"; color: var(--accent); font-size: 9px; }

/* KPI table rows are clickable */
#kpiTableBody tr[data-employee] { cursor: pointer; }
#kpiTableBody tr[data-employee]:hover { background: var(--accent-bg); }
#kpiTableBody tr.qs-hidden { display: none; }

/* =====================================================================
   Summary stat cards
   ===================================================================== */
.summary-card { padding: 16px 18px; }
.summary-label { font-size: 12px; color: var(--muted); }
.summary-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.15;
    margin-top: 4px;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.summary-value-sm { font-size: 16px; letter-spacing: -0.01em; padding-top: 8px; }

/* =====================================================================
   Badges & pills
   ===================================================================== */
.badge {
    display: inline-block;
    padding: 2px 9px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.6;
    border-radius: var(--r-pill);
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge-success { background: var(--score-4-bg); color: var(--score-4-text); }
.badge-high    { background: var(--score-1-bg); color: var(--score-1-text); }
.badge-info    { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.badge-pending { background: var(--line-soft); color: var(--muted); }
.badge-dark    { background: var(--ink); color: #fff; }

/* Task status pills (data colors only) */
.status-badge {
    display: inline-block;
    padding: 2px 9px;
    font-size: 11.5px;
    font-weight: 500;
    border-radius: var(--r-pill);
    white-space: nowrap;
}
.status-hoan-thanh     { background: var(--score-4-bg); color: var(--score-4-text); }
.status-dang-thuc-hien { background: var(--line-soft); color: var(--ink-2); }
.status-dang-danh-gia  { background: var(--line-soft); color: var(--muted); }
.status-khong-ht       { background: var(--score-1-bg); color: var(--score-1-text); }
.status-cho            { background: var(--score-2-bg); color: var(--score-2-text); }

/* KPI score badges 1–4 (data colors) */
.score-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 20px;
    padding: 0 6px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    border-radius: var(--r-pill);
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}
.score-badge.score-4 { background: var(--score-4); }
.score-badge.score-3 { background: var(--score-3); }
.score-badge.score-2 { background: var(--score-2); }
.score-badge.score-1 { background: var(--score-1); }
.score-badge.score-0 { background: var(--faint); }
.score-badge-lg {
    min-width: 40px;
    height: 30px;
    font-size: 16px;
    border-radius: var(--r-ctl);
}

/* Rate coloring (AA text shades) */
.rate-high { color: var(--score-4-text); font-weight: 600; }
.rate-mid  { color: var(--score-3-text); font-weight: 600; }
.rate-low  { color: var(--score-1-text); font-weight: 600; }

.rate-bar {
    height: 4px;
    background: var(--line-soft);
    border-radius: var(--r-pill);
    margin-top: 5px;
    overflow: hidden;
}
.rate-bar-fill {
    height: 100%;
    border-radius: var(--r-pill);
    transition: width 0.4s var(--ease);
}

.warn-badge { color: var(--score-3-text); font-size: 12px; font-weight: 600; white-space: nowrap; }

/* =====================================================================
   Pagination
   ===================================================================== */
.pagination {
    display: flex;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}
.page-link {
    display: block;
    min-width: 29px;
    padding: 4px 8px;
    text-align: center;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    text-decoration: none;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.page-link:hover { background: var(--well); border-color: var(--faint); }
.page-link.active-page { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-item.disabled .page-link { opacity: 0.45; pointer-events: none; }

/* =====================================================================
   Modals (custom — no framework)
   ===================================================================== */
.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 16px;
    background: rgba(24, 24, 27, 0.45);
    animation: fadeIn 0.15s var(--ease) both;
}
.modal-custom {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    box-shadow: var(--shadow-modal);
    animation: modalIn 0.2s var(--ease) both;
}
.modal-custom.modal-xl { max-width: 1140px; }

.modal-custom-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line-soft);
    flex-shrink: 0;
}
.modal-custom-header h3 { font-size: 15.5px; font-weight: 700; letter-spacing: -0.01em; }
.modal-custom-header-warning h3 { color: var(--score-2-text); }

.modal-close {
    font-size: 22px;
    line-height: 1;
    color: var(--faint);
    cursor: pointer;
    transition: color 0.15s var(--ease);
}
.modal-close:hover { color: var(--ink); }

.modal-custom-body { padding: 18px; overflow-y: auto; }
.modal-custom-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--line-soft);
    flex-shrink: 0;
}

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }

/* Detail modal summary cards */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.detail-summary-card {
    border: 1px solid var(--line);
    border-left: 3px solid var(--line);
    border-radius: var(--r-card);
    background: var(--surface);
    padding: 12px 14px;
    min-width: 0;
}
.detail-summary-card.blue   { border-left-color: var(--faint); }
.detail-summary-card.green  { border-left-color: var(--score-4); }
.detail-summary-card.orange { border-left-color: var(--score-2); }
.detail-summary-card.red    { border-left-color: var(--score-1); }
.detail-summary-label { font-size: 12px; color: var(--muted); }
.detail-summary-value {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 2px 0;
    font-variant-numeric: tabular-nums;
}
.detail-summary-sub { font-size: 12px; color: var(--muted); }

.task-row-warning td { background: rgba(217, 119, 6, 0.06); }
.task-row-overdue { color: var(--score-1-text); }

.detail-pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 12.5px;
}
.detail-pager-controls { display: flex; align-items: center; gap: 10px; }

/* =====================================================================
   Loading / empty / error states
   ===================================================================== */
.skeleton {
    display: inline-block;
    height: 12px;
    width: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--line-soft) 25%, #e7e7ea 45%, var(--line-soft) 65%);
    background-size: 200% 100%;
    animation: shimmer 1.3s linear infinite;
}
.skeleton-stat { height: 24px; width: 88px; border-radius: var(--r-ctl); margin-top: 6px; display: block; }
.skeleton-line { display: block; margin: 6px 0; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

tr.skeleton-row:hover { background: transparent; }
tr.skeleton-row td { padding-top: 12px; padding-bottom: 12px; }

.empty-state, .error-state {
    padding: 34px 16px;
    text-align: center;
}
.empty-state i, .error-state i { font-size: 26px; color: var(--faint); display: block; margin-bottom: 8px; }
.error-state i { color: var(--score-1-text); }
.empty-state-title { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.error-state .empty-state-title { color: var(--score-1-text); }
.empty-state-hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.empty-state-sm { padding: 20px 12px; }

.alert {
    padding: 11px 14px;
    border-radius: var(--r-card);
    font-size: 13px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.alert-danger {
    background: var(--score-1-bg);
    border-color: rgba(220, 38, 38, 0.25);
    color: var(--score-1-text);
}

.note {
    display: flex;
    gap: 8px;
    align-items: baseline;
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 10px;
}
.note i { flex-shrink: 0; }

/* =====================================================================
   Sync section
   ===================================================================== */
.sync-card { border-left: 3px solid var(--line); margin: 0; }
.sync-card.ok      { border-left-color: var(--score-4); }
.sync-card.err     { border-left-color: var(--score-1); }
.sync-card.running { border-left-color: var(--score-3); }
.sync-card .card-body { display: flex; flex-direction: column; gap: 2px; }
.sync-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.sync-card-title {
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.sync-records {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    margin: 3px 0 1px;
}
.sync-time { font-size: 12px; color: var(--muted); }
.sync-status { margin-top: 9px; min-height: 20px; }

.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }

.spinning { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   Email / schedule section
   ===================================================================== */
.btn-pair { display: flex; gap: 8px; }

.schedule-group-item {
    padding: 11px 16px;
    border-bottom: 1px solid var(--line-soft);
    transition: background 0.15s var(--ease);
}
.schedule-group-item:last-child { border-bottom: none; }
.schedule-group-item:hover { background: var(--well); }
.sched-item-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.sched-item-name { font-size: 13px; font-weight: 600; }
.sched-item-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.sched-item-last { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.sched-item-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Department / employee picker */
.dept-picker {
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    padding: 6px 10px;
    max-height: 180px;
    overflow-y: auto;
    font-size: 12.5px;
    background: var(--surface);
}
.dept-group-header {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 0;
    cursor: pointer;
}
.dept-group-header .dept-name { font-weight: 600; font-size: 12.5px; }
.dept-group-header .dept-count { margin-left: auto; font-size: 11px; color: var(--muted); }
.dept-arrow { font-size: 10px; color: var(--muted); transition: transform 0.15s var(--ease); }
.dept-arrow.open { transform: rotate(90deg); }
.dept-group-body {
    border-left: 2px solid var(--accent);
    margin-left: 7px;
    padding-left: 4px;
}
.dept-emp-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 3px 0 3px 14px;
    font-size: 12px;
}
.dept-emp-row .emp-email { margin-left: auto; font-size: 11px; color: var(--muted); }

/* =====================================================================
   KPI Rules section
   ===================================================================== */
.rule-rows { display: flex; flex-direction: column; gap: 8px; }
.rule-row {
    display: grid;
    grid-template-columns: 1fr 84px 34px;
    gap: 8px;
    align-items: center;
}
.rule-row-threshold { grid-template-columns: auto 84px auto 84px 34px; }
.rule-row-label { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.rule-cols {
    display: grid;
    grid-template-columns: 1fr 84px 34px;
    gap: 8px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 2px;
}
.rules-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}
.threshold-editor + .threshold-editor { margin-top: 18px; }
.threshold-editor-title { font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }
.rule-add { margin-top: 10px; }
.rule-divider { border: 0; border-top: 1px solid var(--line-soft); margin: 16px 0; }

/* =====================================================================
   Help section
   ===================================================================== */
.help-list { margin: 0; padding-left: 18px; }
.help-list li { margin-bottom: 8px; font-size: 13px; line-height: 1.55; }
.help-list li:last-child { margin-bottom: 0; }
#section-help table td { font-size: 13px; }
#section-help .card-header i { color: var(--accent); }
.help-formula { font-size: 13.5px; margin-bottom: 12px; }
.help-formula:last-child { margin-bottom: 0; }
.help-formula .sub { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.help-col-title { font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }

/* FAQ accordion (native <details>) */
.faq-item {
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    background: var(--surface);
    margin-bottom: 8px;
    overflow: hidden;
}
.faq-item summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    transition: color 0.15s var(--ease);
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
    content: "+";
    font-size: 18px;
    font-weight: 400;
    color: var(--faint);
    line-height: 1;
    flex-shrink: 0;
}
.faq-item[open] summary::after { content: "\2212"; }
.faq-item[open] summary, .faq-item summary:hover { color: var(--accent); }
.faq-body { padding: 0 16px 14px; font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.faq-body ul { margin: 0; padding-left: 18px; }
.faq-body li { margin-bottom: 4px; }
.faq-body li:last-child { margin-bottom: 0; }

/* =====================================================================
   Reveal-on-scroll (progressive enhancement, subtle)
   ===================================================================== */
.reveal { opacity: 1; transform: none; }
.anim .reveal {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
    transition-delay: var(--rd, 0s);
}
.anim .reveal.reveal-in { opacity: 1; transform: none; }

/* =====================================================================
   Reduced motion
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
    .reveal { opacity: 1 !important; transform: none !important; }
    .skeleton { animation: none; background: var(--line-soft); }
}

/* =====================================================================
   Responsive
   ===================================================================== */
/* Keep the 6-item nav on ONE line: drop link icons on narrower desktops */
@media (max-width: 1250px) {
    .topnav-link i { display: none; }
    .topnav-link { padding: 0 10px; }
}
@media (max-width: 1000px) {
    .sync-chip { display: none; }
}

@media (max-width: 1100px) {
    .filter-grid, .mail-filter-grid { grid-template-columns: 1fr 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .sync-grid { grid-template-columns: 1fr; }
    .email-grid { grid-template-columns: 1fr; }
    .help-grid, .rules-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    .nav-toggle { display: inline-flex; }
    .topnav-menu {
        display: none;
        position: fixed;
        top: var(--nav-h);
        left: 0; right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--line);
        box-shadow: 0 12px 24px rgba(24, 24, 27, 0.08);
        padding: 6px 10px 10px;
        z-index: 99;
    }
    .topnav.menu-open .topnav-menu { display: flex; animation: sectionIn 0.18s var(--ease) both; }
    .topnav-link { height: 44px; border-radius: var(--r-ctl); padding: 0 12px; }
    .topnav-link i { display: inline-block; } /* icons back in the dropdown */
    .topnav-link.active { background: var(--accent-bg); }
    .topnav-link.active::after { display: none; }
}

@media (max-width: 640px) {
    .filter-grid, .mail-filter-grid, .stat-grid, .form-row, .help-cols { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .brand-text { display: none; }
    .page-head { flex-wrap: wrap; }
    .section-head { flex-wrap: wrap; }
}

@media print {
    .topnav, .card-footer, .modal-backdrop-custom { display: none !important; }
    body { background: #fff; padding-top: 0; }
    .card { box-shadow: none; }
}
