/* =====================================================================
   MSX — Hệ thống Quản lý Sản xuất Phụ tùng Cấp nước
   Design system / theme  (light + dark, mobile-first)
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  --font-sans: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --bg:            #f5f7fa;
  --bg-pattern:    #eef1f6;
  --surface:       #ffffff;
  --surface-2:     #f2f4f8;
  --surface-3:     #e9edf3;
  --border:        #e2e6ec;
  --border-strong: #ccd2dc;
  --overlay:       rgba(19, 26, 38, .44);

  --text:        #171b22;
  --text-muted:  #5a6472;
  --text-subtle: #8b94a3;
  --text-invert: #ffffff;

  --primary:        #2f6fed;
  --primary-hover:  #2159c9;
  --primary-active: #1c4db0;
  --primary-soft:   #e9f0fe;
  --primary-border: #b9d0fb;

  --accent:  #e07b39;          /* gang nóng chảy */
  --accent-soft: #fdeede;

  --success: #16915a; --success-soft: #e2f4ea; --success-border:#a9dcc2;
  --warning: #b7791f; --warning-soft: #fbf0da; --warning-border:#ecca8c;
  --danger:  #cf3040; --danger-soft:  #fbe6e8; --danger-border:#f0b3ba;
  --info:    #2c82b8; --info-soft:    #e2f1f8; --info-border:#a9d6ea;
  --neutral-soft: #eceff3;

  --shadow-xs: 0 1px 2px rgba(16,24,40,.06);
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 2px 6px rgba(16,24,40,.06);
  --shadow-md: 0 6px 16px rgba(16,24,40,.10), 0 2px 6px rgba(16,24,40,.06);
  --shadow-lg: 0 18px 44px rgba(16,24,40,.18);
  --ring: 0 0 0 3px rgba(47,111,237,.28);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius:    11px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --content-max: 1360px;

  --ease: cubic-bezier(.2,.7,.2,1);
  --dur: .18s;
}

:root[data-theme="dark"] {
  --bg:            #0d1017;
  --bg-pattern:    #12161f;
  --surface:       #161b24;
  --surface-2:     #1c222d;
  --surface-3:     #232b38;
  --border:        #262e3b;
  --border-strong: #364150;
  --overlay:       rgba(3, 6, 12, .6);

  --text:        #e7eaf0;
  --text-muted:  #9aa4b3;
  --text-subtle: #6b7482;
  --text-invert: #0d1017;

  --primary:        #5b95ff;
  --primary-hover:  #77a8ff;
  --primary-active: #8fb7ff;
  --primary-soft:   #16233c;
  --primary-border: #29406b;

  --accent: #f0904e; --accent-soft: #33210f;

  --success: #3cbd82; --success-soft:#122a1f; --success-border:#1f4f3a;
  --warning: #dca94e; --warning-soft:#2c2410; --warning-border:#574722;
  --danger:  #e5697a; --danger-soft: #2e1519; --danger-border:#5c2b32;
  --info:    #56b0dd; --info-soft:   #10222c; --info-border:#204a5e;
  --neutral-soft:#212936;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.4);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.35);
  --shadow-md: 0 8px 20px rgba(0,0,0,.5), 0 2px 8px rgba(0,0,0,.4);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.62);
  --ring: 0 0 0 3px rgba(91,149,255,.34);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0d1017; --bg-pattern:#12161f; --surface:#161b24; --surface-2:#1c222d;
    --surface-3:#232b38; --border:#262e3b; --border-strong:#364150;
    --overlay:rgba(3,6,12,.6);
    --text:#e7eaf0; --text-muted:#9aa4b3; --text-subtle:#6b7482; --text-invert:#0d1017;
    --primary:#5b95ff; --primary-hover:#77a8ff; --primary-active:#8fb7ff;
    --primary-soft:#16233c; --primary-border:#29406b;
    --accent:#f0904e; --accent-soft:#33210f;
    --success:#3cbd82; --success-soft:#122a1f; --success-border:#1f4f3a;
    --warning:#dca94e; --warning-soft:#2c2410; --warning-border:#574722;
    --danger:#e5697a; --danger-soft:#2e1519; --danger-border:#5c2b32;
    --info:#56b0dd; --info-soft:#10222c; --info-border:#204a5e;
    --neutral-soft:#212936;
    --shadow-xs:0 1px 2px rgba(0,0,0,.4);
    --shadow-sm:0 1px 2px rgba(0,0,0,.4),0 2px 6px rgba(0,0,0,.35);
    --shadow-md:0 8px 20px rgba(0,0,0,.5),0 2px 8px rgba(0,0,0,.4);
    --shadow-lg:0 20px 48px rgba(0,0,0,.62);
    --ring:0 0 0 3px rgba(91,149,255,.34);
  }
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-xs); }
::selection { background: color-mix(in srgb, var(--primary) 26%, transparent); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); background-clip: padding-box; }

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--dur) var(--ease);
}
#app[data-nav="collapsed"] .app-shell,
:root[data-nav="collapsed"] .app-shell { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
}
.sidebar__brand {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px 0 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 700; letter-spacing: -.01em;
}
.sidebar__brand .logo {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: var(--shadow-sm);
}
.sidebar__brand .brand-sub { font-size: 11px; font-weight: 500; color: var(--text-subtle); letter-spacing: .02em; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 12px 20px; }
.nav-group { margin-top: 14px; }
.nav-group:first-child { margin-top: 2px; }
.nav-group__label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-subtle);
  padding: 8px 10px 6px;
}
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
  white-space: nowrap; cursor: pointer;
  transition: background var(--dur), color var(--dur);
}
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link.is-active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--primary);
}
.nav-link__badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--danger-soft); color: var(--danger);
  padding: 1px 7px; border-radius: 999px;
}
.sidebar__foot { flex: none; border-top: 1px solid var(--border); padding: 10px 12px; }

/* collapsed */
:root[data-nav="collapsed"] .sidebar__brand .brand-text,
:root[data-nav="collapsed"] .nav-group__label,
:root[data-nav="collapsed"] .nav-link span,
:root[data-nav="collapsed"] .nav-link__badge,
:root[data-nav="collapsed"] .sidebar__foot .u-hide-collapsed { display: none; }
:root[data-nav="collapsed"] .nav-link { justify-content: center; padding: 10px; }
:root[data-nav="collapsed"] .nav-link.is-active::before { left: -12px; }
:root[data-nav="collapsed"] .nav-link:hover::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 10px);
  background: var(--text); color: var(--surface); font-size: 12px; font-weight: 600;
  padding: 5px 9px; border-radius: 6px; white-space: nowrap; z-index: 60;
  box-shadow: var(--shadow-md);
}

/* ---------- Main column ---------- */
.main-col { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__progress {
  position: absolute; left: 0; top: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: 0; transition: width .2s var(--ease), opacity .3s;
}
.topbar__progress.is-active { opacity: 1; }
.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn__dot {
  position: absolute; top: 6px; right: 6px; width: 7px; height: 7px;
  background: var(--danger); border-radius: 999px; border: 2px solid var(--surface);
}
.topbar__crumb { display: flex; align-items: center; gap: 7px; min-width: 0; }
.topbar__crumb .mod { color: var(--text-subtle); font-size: 13px; }
.topbar__crumb .sep { color: var(--text-subtle); }
.topbar__crumb .cur { font-weight: 650; letter-spacing: -.01em; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__spacer { flex: 1; }
.searchbtn {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px 0 11px; min-width: 220px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-subtle); cursor: pointer;
  transition: border-color var(--dur), background var(--dur);
}
.searchbtn:hover { border-color: var(--border-strong); }
.searchbtn svg { width: 16px; height: 16px; flex: none; }
.searchbtn kbd {
  margin-left: auto; font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 5px; color: var(--text-muted);
}
.pos-rel { position: relative; }

/* ---------- View / layout primitives ---------- */
.view { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 24px; }
@media (min-width: 1100px) { .view { padding: 28px 32px 56px; } }
.view-transition { view-transition-name: view; }

.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head__text h1 { font-size: 21px; font-weight: 700; letter-spacing: -.02em; }
.page-head__text p { color: var(--text-muted); margin-top: 3px; max-width: 62ch; }
.page-head__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.cluster { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grid { display: grid; gap: 16px; }
/* Ô lưới mặc định không co nhỏ hơn nội dung → bảng rộng đẩy cả trang cuộn ngang. Cho co lại để bảng tự cuộn trong khung của nó. */
.grid > * { min-width: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-auto { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
@media (max-width: 1080px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 760px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-xs);
}
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card__head h3 { font-size: 14px; font-weight: 650; }
.card__head .card__actions { margin-left: auto; display: flex; gap: 6px; }
.card__body { padding: 16px; }
.card__body.flush { padding: 0; }
.card__foot { padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 13px; }

/* ---------- KPI ---------- */
.kpi { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.kpi__top { display: flex; align-items: center; gap: 10px; }
.kpi__ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.kpi__ic svg { width: 18px; height: 18px; }
.kpi__label { color: var(--text-muted); font-size: 12.5px; font-weight: 500; }
.kpi__value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.kpi__value small { font-size: 13px; font-weight: 600; color: var(--text-subtle); }
.kpi__delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.kpi__delta svg { width: 14px; height: 14px; }
.kpi__delta.up { color: var(--success); }
.kpi__delta.down { color: var(--danger); }
.kpi__delta.flat { color: var(--text-subtle); }
a.kpi { transition: box-shadow var(--dur), transform var(--dur); }
a.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi.tone-warn .kpi__ic { background: var(--warning-soft); color: var(--warning); }
.kpi.tone-danger .kpi__ic { background: var(--danger-soft); color: var(--danger); }
.kpi.tone-success .kpi__ic { background: var(--success-soft); color: var(--success); }
.kpi.tone-accent .kpi__ic { background: var(--accent-soft); color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur), border-color var(--dur), box-shadow var(--dur), transform var(--dur);
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(.95); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--subtle { border-color: transparent; background: var(--surface-2); }
.btn--sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: var(--radius-xs); }
.btn--lg { height: 42px; padding: 0 20px; font-size: 15px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--neutral-soft); color: var(--text-muted);
  border: 1px solid transparent;
}
.chip .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.chip svg { width: 13px; height: 13px; }
.chip--success { background: var(--success-soft); color: var(--success); }
.chip--warning { background: var(--warning-soft); color: var(--warning); }
.chip--danger  { background: var(--danger-soft);  color: var(--danger); }
.chip--info    { background: var(--info-soft);    color: var(--info); }
.chip--primary { background: var(--primary-soft); color: var(--primary); }
.chip--accent  { background: var(--accent-soft);  color: var(--accent); }
.chip--outline { background: transparent; border-color: var(--border-strong); color: var(--text-muted); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--text-subtle); }
.field .err { font-size: 12px; color: var(--danger); font-weight: 600; }
.input, .select, .textarea {
  height: 38px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); width: 100%;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b94a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.field.invalid .input, .field.invalid .select, .field.invalid .textarea { border-color: var(--danger); }
.input-group { display: flex; align-items: center; gap: 8px; }
.input-affix { position: relative; }
.input-affix .suffix { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); font-size: 12.5px; font-weight: 600; pointer-events: none; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .col-span-2 { grid-column: span 2; }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } .form-grid .col-span-2 { grid-column: auto; } }
.switch { position: relative; width: 40px; height: 23px; flex: none; }
.switch input { position: absolute; opacity: 0; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background var(--dur); }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 999px; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(17px); }
.segmented { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.segmented button { height: 28px; padding: 0 12px; border: 0; background: transparent; border-radius: 6px; font-weight: 600; font-size: 12.5px; color: var(--text-muted); cursor: pointer; }
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* ---------- Toolbar / filter bar ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.toolbar .search-input { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.toolbar .search-input svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-subtle); }
.toolbar .search-input input { height: 34px; padding-left: 32px; }
.toolbar__right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- Data table ---------- */
.dt-wrap { width: 100%; overflow-x: auto; }
table.dt { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dt thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-weight: 650; color: var(--text-muted);
  font-size: 11.5px; letter-spacing: .03em; text-transform: uppercase;
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.dt thead th.sortable { cursor: pointer; user-select: none; }
table.dt thead th.sortable:hover { color: var(--text); }
table.dt thead th .arrow { opacity: .35; margin-left: 4px; display: inline-flex; width: 12px; height: 12px; line-height: 0; vertical-align: middle; }
table.dt thead th .arrow svg { width: 12px; height: 12px; display: block; }
table.dt thead th[aria-sort="ascending"] .arrow,
table.dt thead th[aria-sort="descending"] .arrow { opacity: 1; color: var(--primary); }
table.dt tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.dt td svg { width: 14px; height: 14px; vertical-align: -2px; }
table.dt tbody tr { transition: background var(--dur); }
table.dt tbody tr[data-clickable] { cursor: pointer; }
table.dt tbody tr:hover { background: var(--surface-2); }
table.dt .num { text-align: right; font-variant-numeric: tabular-nums; }
/* Ô tích của ma trận phân quyền: chữ tắt vai trò và dấu tích cùng canh giữa, cột đều nhau */
table.dt th.acl-o, table.dt td.acl-o { text-align: center; width: 64px; padding-left: 4px; padding-right: 4px; }
table.dt td.acl-o input[type=checkbox] { display: block; margin: 0 auto; }
table.dt .nowrap { white-space: nowrap; }
.cell-strong { font-weight: 650; }
.cell-mono { font-family: var(--font-mono); font-size: 12.5px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* Bảng gọn: dùng cho bảng có ô nhập / nút thao tác ngay trong hàng, giữ chiều cao sát bảng chữ thường */
table.dt.dt--compact tbody td { padding: 4px 14px; }
table.dt.dt--compact thead th { padding: 8px 14px; }
table.dt.dt--compact .icon-btn { width: 28px; height: 28px; }
table.dt.dt--compact .icon-btn svg { width: 16px; height: 16px; }
.input.input--cell { height: 28px; padding: 0 8px; font-size: 12.5px; text-align: right; }
.row-actions .icon-btn { width: 30px; height: 30px; }
.row-actions .icon-btn svg { width: 16px; height: 16px; }

/* Cột nút thao tác luôn dính mép phải — bảng nhiều cột không làm nút bị đẩy khuất */
/* DataTable gắn .row-actions thẳng lên <td>. .row-actions có display:flex nên ô bị mất
   chiều cao của hàng → nút dồn lên đầu ở những hàng cao. Giữ ô là table-cell, canh giữa dọc. */
table.dt td.row-actions {
  display: table-cell;
  vertical-align: middle;
  text-align: right;
  white-space: nowrap;
}
table.dt td.row-actions > .icon-btn { display: inline-grid; vertical-align: middle; }
table.dt td.row-actions > .icon-btn + .icon-btn { margin-left: 2px; }

table.dt td.row-actions,
table.dt th.row-actions-th { position: sticky; right: 0; }
table.dt td.row-actions { background: var(--surface); box-shadow: -6px 0 6px -6px rgba(0,0,0,.18); }
table.dt th.row-actions-th { background: var(--surface-2); z-index: 2; box-shadow: -6px 0 6px -6px rgba(0,0,0,.18); }
table.dt tbody tr:hover td.row-actions { background: var(--surface-2); }
@media (max-width: 720px) {
  table.dt td.row-actions, table.dt th.row-actions-th { position: static; box-shadow: none; }
}

.dt-foot { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12.5px; }
.dt-foot .pager { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.dt-foot .pager button { width: 30px; height: 30px; border: 1px solid var(--border); background: var(--surface); border-radius: 7px; cursor: pointer; display: grid; place-items: center; color: var(--text-muted); }
.dt-foot .pager button:hover:not([disabled]) { background: var(--surface-2); color: var(--text); }
.dt-foot .pager button[disabled] { opacity: .4; cursor: default; }

@media (max-width: 720px) {
  table.dt, table.dt tbody, table.dt tr, table.dt td { display: block; width: 100%; }
  table.dt thead { display: none; }
  table.dt tbody tr { border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 10px 12px; padding: 4px 2px; background: var(--surface); }
  table.dt tbody td { border: 0; display: flex; justify-content: space-between; gap: 16px; padding: 8px 14px; text-align: right; }
  table.dt tbody td::before { content: attr(data-label); font-weight: 650; color: var(--text-muted); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
  table.dt .num { text-align: right; }
  .row-actions { justify-content: flex-end; }
}

/* ---------- Ô chọn có tìm kiếm (combo) ----------
   Danh sách nằm TRONG dòng chảy, không dùng position:absolute — vì .modal__body có
   overflow-y:auto sẽ cắt mất danh sách thả xuống. */
.combo { position: relative; }
.combo__list {
  margin-top: 4px; max-height: 216px; overflow-y: auto;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); box-shadow: var(--shadow-md);
}
.combo__item {
  padding: 7px 10px; cursor: pointer; font-size: 13px;
  display: flex; align-items: baseline; gap: 8px; border-bottom: 1px solid var(--border);
}
.combo__item:last-child { border-bottom: 0; }
.combo__item:hover, .combo__item.is-active { background: var(--surface-2); }
.combo__item .code { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); flex: none; }
.combo__item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo__more { padding: 6px 10px; font-size: 11.5px; color: var(--text-subtle); background: var(--surface-2); }
.combo__picked { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-muted); padding-top: 4px; }

/* ---------- Empty / skeleton ---------- */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .ic { width: 46px; height: 46px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; margin: 0 auto 12px; color: var(--text-subtle); }
.empty-state .ic svg { width: 22px; height: 22px; }
.toast .ic svg { width: 20px; height: 20px; }
.avatar svg { width: 15px; height: 15px; }
.banner svg { width: 18px; height: 18px; }
.empty-state h4 { font-size: 15px; color: var(--text); font-weight: 650; }
.empty-state p { margin: 4px 0 16px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 6px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Modal ---------- */
.scrim { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(2px); z-index: 90; opacity: 0; transition: opacity var(--dur); }
.scrim.is-open { opacity: 1; }
.modal {
  position: fixed; z-index: 91; left: 50%; top: 50%;
  transform: translate(-50%, -46%); opacity: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  transition: opacity var(--dur), transform var(--dur);
}
.modal.is-open { opacity: 1; transform: translate(-50%, -50%); }
.modal--lg { width: min(760px, calc(100vw - 32px)); }
.modal--sm { width: min(420px, calc(100vw - 32px)); }
.modal__head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal__head h3 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.modal__head .icon-btn { margin-left: auto; }
.modal__body { padding: 18px; overflow-y: auto; }
.modal__foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }
@media (max-width: 560px) {
  .modal { left: 0; right: 0; bottom: 0; top: auto; width: 100%; transform: translateY(100%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; }
  .modal.is-open { transform: translateY(0); }
  .modal__foot { position: sticky; bottom: 0; background: var(--surface); }
  .modal__foot .btn { flex: 1; }
}

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; z-index: 91; top: 0; right: 0; height: 100vh;
  width: min(460px, 100vw); transform: translateX(100%); opacity: 1;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transition: transform var(--dur) var(--ease);
}
.drawer.is-open { transform: translateX(0); }
.drawer--wide { width: min(640px, 100vw); }
.drawer--xl { width: min(1080px, calc(100vw - 48px)); }
.drawer__head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer__head .icon-btn { margin-left: auto; }
.drawer__title { font-size: 16px; font-weight: 700; }
.drawer__sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.drawer__body { padding: 18px; overflow-y: auto; flex: 1; }
.drawer__foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
@media (max-width: 560px) {
  .drawer { width: 100vw; transform: translateY(100%); top: auto; bottom: 0; height: 90vh; border-left: 0; border-top: 1px solid var(--border); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .drawer.is-open { transform: translateY(0); }
}

/* ---------- Definition list (detail views) ---------- */
.dl { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 0; }
.dl > dt { color: var(--text-muted); font-size: 12.5px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.dl > dd { font-weight: 550; padding: 9px 0; border-bottom: 1px solid var(--border); text-align: right; }
.dl > dt:last-of-type, .dl > dd:last-of-type { border-bottom: 0; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; z-index: 120; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
  transform: translateY(10px); opacity: 0; transition: transform var(--dur), opacity var(--dur);
}
.toast.is-open { transform: none; opacity: 1; }
.toast .ic { width: 20px; height: 20px; flex: none; }
.toast--success .ic { color: var(--success); }
.toast--danger .ic { color: var(--danger); }
.toast--info .ic { color: var(--info); }
.toast--warning .ic { color: var(--warning); }
.toast__msg { font-size: 13px; font-weight: 550; }
.toast__msg small { display: block; color: var(--text-muted); font-weight: 400; margin-top: 1px; }

/* ---------- Dropdown menu ---------- */
.menu {
  position: absolute; z-index: 95; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 6px;
  opacity: 0; transform: translateY(-4px); transition: opacity var(--dur), transform var(--dur);
}
.menu.is-open { opacity: 1; transform: none; }
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; background: transparent; border-radius: 6px;
  font-size: 13px; font-weight: 550; color: var(--text); cursor: pointer; text-align: left;
}
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu button svg, .menu a svg { width: 16px; height: 16px; color: var(--text-muted); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 2px; }
.menu .danger { color: var(--danger); }
.menu .danger svg { color: var(--danger); }
.menu__label { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-subtle); padding: 6px 10px 4px; }

/* ---------- Command palette ---------- */
.cmdk { position: fixed; z-index: 110; left: 50%; top: 12vh; transform: translateX(-50%) scale(.98); opacity: 0;
  width: min(600px, calc(100vw - 24px)); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; transition: opacity var(--dur), transform var(--dur); }
.cmdk.is-open { opacity: 1; transform: translateX(-50%) scale(1); }
.cmdk__input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.cmdk__input svg { width: 18px; height: 18px; color: var(--text-subtle); }
.cmdk__input input { border: 0; background: transparent; width: 100%; font-size: 15px; }
.cmdk__input input:focus { outline: none; }
.cmdk__list { max-height: 56vh; overflow-y: auto; padding: 8px; }
.cmdk__group-label { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-subtle); padding: 10px 10px 4px; }
.cmdk__item { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.cmdk__item svg { width: 17px; height: 17px; color: var(--text-muted); flex: none; }
.cmdk__item .sub { color: var(--text-subtle); font-size: 12px; margin-left: auto; }
.cmdk__item.is-active { background: var(--primary-soft); color: var(--primary); }
.cmdk__item.is-active svg { color: var(--primary); }
.cmdk__empty { padding: 28px; text-align: center; color: var(--text-subtle); }

/* ---------- Banner / alert ---------- */
.banner { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }
.banner svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.banner--warning { background: var(--warning-soft); border-color: var(--warning-border); color: color-mix(in srgb, var(--warning) 90%, var(--text)); }
.banner--danger { background: var(--danger-soft); border-color: var(--danger-border); }
.banner--info { background: var(--info-soft); border-color: var(--info-border); }
.banner__close { margin-left: auto; }

/* ---------- Stepper / timeline ---------- */
.stepper { display: flex; flex-direction: column; }
.step { display: grid; grid-template-columns: 34px 1fr; gap: 14px; }
.step__rail { display: flex; flex-direction: column; align-items: center; }
.step__dot { width: 26px; height: 26px; border-radius: 999px; display: grid; place-items: center; font-size: 12px; font-weight: 700; border: 2px solid var(--border-strong); background: var(--surface); color: var(--text-subtle); flex: none; }
.step__line { flex: 1; width: 2px; background: var(--border); margin: 4px 0; min-height: 16px; }
.step:last-child .step__line { display: none; }
.step__body { padding-bottom: 20px; }
.step__body h4 { font-size: 13.5px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.step__body .meta { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; }
.step__body .meta svg { width: 12px; height: 12px; vertical-align: -2px; }
.step__dot svg { width: 14px; height: 14px; }
.step.done .step__dot { background: var(--success); border-color: var(--success); color: #fff; }
.step.done .step__line { background: var(--success); }
.step.current .step__dot { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: var(--ring); }
.step.fail .step__dot { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 14px; scroll-snap-type: x proximity; }
.kanban__col { flex: none; width: 264px; scroll-snap-align: start; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: 72vh; }
.kanban__col-head { display: flex; align-items: center; gap: 8px; padding: 11px 12px; font-weight: 650; font-size: 12.5px; border-bottom: 1px solid var(--border); }
.kanban__col-head .count { margin-left: auto; font-size: 11px; background: var(--surface-3); color: var(--text-muted); border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.kanban__col-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; }
.kboard-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px; cursor: pointer; box-shadow: var(--shadow-xs); transition: box-shadow var(--dur), transform var(--dur); }
.kboard-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kboard-card__code { font-family: var(--font-mono); font-size: 12px; font-weight: 650; }
.kboard-card__title { font-size: 13px; font-weight: 600; margin: 3px 0 8px; }
.kboard-card__meta { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 11.5px; }
.kboard-card__meta svg { width: 13px; height: 13px; }
.kboard-card .btn svg { width: 14px; height: 14px; }

/* ---------- Charts (inline svg) ---------- */
.chart { width: 100%; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 62px; align-items: center; gap: 10px; padding: 5px 0; font-size: 12.5px; }
.bar-row .track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 999px; background: var(--primary); }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-muted); }

/* ---------- Misc utilities ---------- */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.right { text-align: right; }
.center { text-align: center; }
.strong { font-weight: 650; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.avatar { width: 30px; height: 30px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.avatar--sm { width: 24px; height: 24px; font-size: 10.5px; }
.pill-num { font-variant-numeric: tabular-nums; font-weight: 650; }
.linkish { color: var(--primary); font-weight: 600; cursor: pointer; }
.linkish:hover { text-decoration: underline; }
.tag-dn { font-family: var(--font-mono); font-size: 11px; font-weight: 700; background: var(--surface-3); color: var(--text-muted); padding: 1px 6px; border-radius: 5px; }

/* ---------- Mobile shell ---------- */
.topbar__menu { display: none; }
.sidebar__scrim { display: none; }
@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr !important; }
  .sidebar { position: fixed; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform var(--dur) var(--ease); }
  :root[data-nav-mobile="open"] .sidebar { transform: translateX(0); }
  :root[data-nav-mobile="open"] .sidebar__scrim { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 39; }
  :root[data-nav="collapsed"] .sidebar { width: 280px; }
  :root[data-nav="collapsed"] .nav-link span,
  :root[data-nav="collapsed"] .nav-group__label,
  :root[data-nav="collapsed"] .sidebar__brand .brand-text { display: revert; }
  :root[data-nav="collapsed"] .nav-link { justify-content: flex-start; padding: 9px 10px; }
  .topbar__menu { display: grid; }
  .searchbtn { min-width: 0; }
  .searchbtn .txt, .searchbtn kbd { display: none; }
  #tb-create .txt { display: none; }
  #tb-create { padding: 0 10px; }
  #tb-role .role-full { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar__crumb .mod, .topbar__crumb .sep { display: none; }
  .view { padding: 16px; }
  .page-head__actions { width: 100%; }
  .page-head__actions .btn { flex: 1; }
}
@media (max-width: 560px) {
  .searchbtn { width: 36px; padding: 0; justify-content: center; }
}

/* ---------- View transitions ---------- */
@view-transition { navigation: auto; }
::view-transition-old(view) { animation: vt-out .16s var(--ease) both; }
::view-transition-new(view) { animation: vt-in .22s var(--ease) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-6px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
