:root {
  --bg: #EEF2F1;
  --surface: #FFFFFF;
  --sunken: #F5F8F7;
  --ink: #14242B;
  --muted: #5B6B70;
  --line: #D6DFDD;
  --jade: #0E7C66;
  --jade-ink: #0A5C4C;
  --jade-soft: #DCEFEA;
  --gold: #A87B12;
  --gold-soft: #F6EBD0;
  --red: #B83A2E;
  --red-soft: #F7DEDA;
  --focus: #1F8FFF;
  --radius-s: 6px;
  --radius-m: 10px;
  --font: 'Be Vietnam Pro', system-ui, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1719; --surface: #152226; --sunken: #111C1F; --ink: #E4ECEA; --muted: #93A6A8;
    --line: #25363A; --jade: #3DBA9A; --jade-ink: #7FD8C1; --jade-soft: #173A33;
    --gold: #D9AE4B; --gold-soft: #3A3018; --red: #E8766A; --red-soft: #3D1F1B;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.55 var(--font); font-feature-settings: 'tnum' 1;
}
a { color: var(--jade-ink); }
code, .mid { font-family: var(--mono); font-size: 13.5px; letter-spacing: .02em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ── Thanh trên ── */
.top {
  display: flex; align-items: center; gap: 28px; padding: 0 28px; height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 17px; }
.seal {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--jade); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: -.02em;
}
.brand-sub { color: var(--muted); font-weight: 400; font-size: 14px; }
#nav { display: flex; gap: 4px; flex: 1; }
#nav a {
  text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: var(--radius-s); font-weight: 500;
}
#nav a:hover { color: var(--ink); background: var(--sunken); }
#nav a[aria-current="page"] { color: var(--jade-ink); background: var(--jade-soft); }
#who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.role { color: var(--gold); font-weight: 600; }

/* ── Trang ── */
main { max-width: 1120px; margin: 0 auto; padding: 32px 28px 120px; }
.loading { color: var(--muted); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 26px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 36px 0 12px; font-weight: 600; }
.lede { color: var(--muted); margin: 6px 0 0; max-width: 62ch; }

/* ── Kho seat + thanh chia (điểm nhấn) ── */
.pool {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 22px 24px 20px; margin-bottom: 28px;
}
.pool-figures { display: flex; gap: 40px; flex-wrap: wrap; align-items: baseline; }
.fig { display: flex; flex-direction: column; }
.fig b { font-size: 30px; font-weight: 700; line-height: 1.1; }
.fig span { color: var(--muted); font-size: 13.5px; }
.fig.warn b { color: var(--red); }
.alloc { margin-top: 18px; }
.alloc-bar {
  display: flex; height: 22px; border-radius: 6px; overflow: hidden; background:
    repeating-linear-gradient(135deg, var(--sunken) 0 6px, var(--line) 6px 7px);
  border: 1px solid var(--line);
}
.alloc-seg { height: 100%; min-width: 3px; border-right: 2px solid var(--surface); transition: flex-basis .25s ease; }
.alloc-seg:last-child { border-right: 0; }
.alloc-seg.over { background: var(--red) !important; }
.alloc-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 13.5px; color: var(--muted); }
.alloc-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.alloc-legend b { color: var(--ink); font-weight: 600; }

/* ── Form ── */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 9px 12px;
}
.grant input, .grant select, .grant .btn, .addbar input, .addbar .btn { height: 42px; }
input:hover, select:hover { border-color: color-mix(in srgb, var(--line), var(--ink) 25%); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13.5px; font-weight: 500; color: var(--muted); }
.addbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.addbar input[name="machine_id"] { flex: 1 1 340px; font-family: var(--mono); letter-spacing: .04em; }
.addbar input[name="label"] { flex: 0 1 200px; }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; border-radius: var(--radius-s); cursor: pointer;
  padding: 9px 16px; border: 1px solid transparent; background: var(--jade); color: #fff; white-space: nowrap;
}
.btn:hover { background: var(--jade-ink); }
.btn.ghost { background: transparent; color: var(--jade-ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--sunken); }
.btn.danger { background: transparent; color: var(--red); border-color: transparent; }
.btn.danger:hover { background: var(--red-soft); }
.btn.gold { background: var(--gold); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Bảng ── */
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--sunken); white-space: nowrap;
}
td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.dim td { color: var(--muted); }
td.num, th.num { text-align: right; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; }
td .mid, td.nowrap { white-space: nowrap; }
.sub { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.label-edit {
  border: 1px solid transparent; background: transparent; padding: 2px 6px; margin: -2px -6px;
  font-weight: 600; width: 100%; max-width: 220px;
}
.label-edit:hover, .label-edit:focus { border-color: var(--line); background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 12.5px; padding: 1px 8px; border-radius: 99px; background: var(--jade-soft); color: var(--jade-ink); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.active { color: var(--jade); }
.pill.pending { color: var(--gold); }
.pill.revoked { color: var(--red); }

.stepper { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.stepper button { width: 32px; border: 0; background: var(--sunken); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.stepper button:hover { background: var(--jade-soft); }
.stepper input { width: 56px; border: 0; border-radius: 0; text-align: center; padding: 6px 4px; }
.stepper.changed { border-color: var(--jade); }
.eff { font-size: 12.5px; color: var(--red); display: block; margin-top: 4px; }

/* Thanh lưu thay đổi — chỉ hiện khi có chỉnh sửa chưa lưu */
.savebar {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%);
  display: flex; align-items: center; gap: 16px; padding: 12px 14px 12px 20px;
  background: var(--ink); color: var(--bg); border-radius: 12px; box-shadow: 0 8px 30px rgba(10,30,30,.25);
  transition: transform .2s ease, visibility .2s; z-index: 20; max-width: calc(100% - 32px); visibility: hidden;
}
.savebar.show { transform: translate(-50%, 0); visibility: visible; }
.savebar .btn.ghost { color: var(--bg); border-color: color-mix(in srgb, var(--bg), transparent 60%); }
.savebar .btn.ghost:hover { background: transparent; border-color: var(--bg); }
.savebar.over { background: var(--red); }

/* ── Tab quản trị ── */
.tabs { display: flex; gap: 2px; box-shadow: inset 0 -1px 0 var(--line); margin: 8px 0 22px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a {
  text-decoration: none; color: var(--muted); padding: 10px 14px; font-weight: 500; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--jade); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 99px; font-size: 12px; text-align: center; background: var(--line); color: var(--ink); }
.count.hot { background: var(--gold); color: #fff; }

.grant { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 18px; }
.grant .field select, .grant .field input { min-width: 90px; }
.grant .field.grow { flex: 1 1 200px; }

.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ── Đăng nhập ── */
.auth { display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: start; padding-top: 24px; }
.auth > section { min-width: 0; overflow-wrap: anywhere; }
.auth h1 { font-size: 32px; }
.steps { list-style: none; padding: 0; margin: 28px 0 0; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 0 0 22px 46px; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: -2px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--jade-soft); color: var(--jade-ink);
}
.steps b { display: block; }
.steps span { color: var(--muted); font-size: 14px; }
.authcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.authcard form { display: flex; flex-direction: column; gap: 14px; }
.authcard .switch { margin-top: 14px; font-size: 14px; color: var(--muted); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--jade-ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }

.narrow { max-width: 420px; }
.narrow form { display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 22px; }

/* ── Thông báo ── */
#flash { position: fixed; top: 72px; right: 20px; z-index: 30; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100% - 40px)); }
.flash { padding: 11px 16px; border-radius: 10px; background: var(--red); color: #fff; font-weight: 500; box-shadow: 0 6px 20px rgba(10,30,30,.18); }
.flash.ok { background: var(--jade); }

@media (max-width: 760px) {
  .top { padding: 0 16px; gap: 12px; height: auto; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .brand-sub { display: none; }
  #nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  main { padding: 22px 16px 120px; }
  .auth { grid-template-columns: 1fr; gap: 28px; }
  .authcard { order: -1; }
  .pool-figures { gap: 24px; }
  .hide-m { display: none; }
}
