/* ==========================================================================
   HPS ERP - design system. Tokens first; components only use tokens.
   Identity follows the Automation Hub (docs/design/DESIGN-GUIDELINE.md):
   one deep pharmacy-green ramp, green-tinted neutrals, status hues with a
   fixed meaning. See docs/erp/design.md for the ERP-specific additions.
   ========================================================================== */
:root {
  --brand-950: #082416; --brand-900: #0d3722; --brand-800: #145030; --brand-700: #1f7a33;
  --brand-600: #2f9e41; --brand-500: #43b356; --brand-200: #bfe3c6; --brand-100: #dcefe0; --brand-50: #eef7f0;

  --bg: #f3f6f4; --surface: #ffffff; --surface-2: #f6f9f7; --surface-3: #edf2ee;
  --border: #e1e8e3; --border-2: #cfd9d2;
  --text: #13221a; --text-2: #3d4f45; --text-3: #66766d; --on-brand: #ffffff;

  --ok: #1f7a33; --ok-tint: #e3f3e6;
  --error: #b42318; --error-tint: #fdecea;
  --warn: #9a5b00; --warn-tint: #fdf3dc;
  --info: #1d5fa8; --info-tint: #e6f0fb;
  --skip: #5c6b63; --skip-tint: #eef1ef;

  --sidebar-bg: linear-gradient(180deg, #0f3d26 0%, #0a2d1b 100%);
  --sidebar-ink: #cfe3d5; --sidebar-ink-2: #8fb39c; --sidebar-hover: rgba(255,255,255,.07);
  --sidebar-active: rgba(67,179,86,.18);

  --font: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s7: 32px; --s8: 40px;
  --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16,40,26,.06);
  --shadow: 0 1px 2px rgba(16,40,26,.05), 0 4px 16px rgba(16,40,26,.06);
  --shadow-lg: 0 12px 40px rgba(10,30,18,.22);
  --ring: 0 0 0 3px rgba(47,158,65,.25);
  --sidebar-w: 260px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1511; --surface: #142019; --surface-2: #18261e; --surface-3: #1d2d24;
    --border: #24362b; --border-2: #2f4537;
    --text: #e6efe9; --text-2: #b7c7bd; --text-3: #8a9d91;
    --brand-700: #5cc06d; --brand-100: #1d3a26; --brand-50: #17291e;
    --ok: #5cc06d; --ok-tint: #173322; --error: #f0857b; --error-tint: #3a1c19;
    --warn: #e5b04a; --warn-tint: #352a12; --info: #7fb0ea; --info-tint: #16283d;
    --skip: #a3b2a9; --skip-tint: #1f2a24;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; }
a { color: var(--brand-700); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: var(--s2); }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- Layout -------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-ink); position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; padding: var(--s4) var(--s3); }
.brand { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s2) var(--s5);
  color: #fff; text-decoration: none !important; }
.brand img { width: 38px; height: 38px; border-radius: 10px; background: #fff; padding: 3px; }
.brand strong { display: block; font-size: 15px; letter-spacing: .2px; }
.brand small { display: block; color: var(--sidebar-ink-2); font-size: 11.5px; letter-spacing: .6px;
  text-transform: uppercase; }
.nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-sep { margin: var(--s4) var(--s3) var(--s1); font-size: 11px; font-weight: 600; letter-spacing: .8px;
  text-transform: uppercase; color: var(--sidebar-ink-2); }
.nav-item { display: flex; align-items: center; gap: var(--s3); padding: 9px var(--s3);
  border-radius: var(--r-sm); color: var(--sidebar-ink); font-weight: 500; text-decoration: none !important;
  transition: background .15s; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand-500); }
.nav-item .ico { display: inline-flex; opacity: .9; }
.sidebar-user { display: flex; align-items: center; gap: var(--s3); padding: var(--s3);
  border-radius: var(--r); background: rgba(255,255,255,.06); margin-top: var(--s3); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--brand-600); color: #fff; font-weight: 700; }
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user strong { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.sidebar-user small { color: var(--sidebar-ink-2); font-size: 11.5px; }
.sidebar-user .logout { color: var(--sidebar-ink-2); display: inline-flex; padding: 6px; border-radius: 8px; }
.sidebar-user .logout:hover { color: #fff; background: var(--sidebar-hover); }
.mobile-bar { display: none; }
.main { min-width: 0; }
.page { max-width: 1320px; margin: 0 auto; padding: var(--s6) var(--s7) var(--s8); }

/* ---- Page head ------------------------------------------------------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4);
  flex-wrap: wrap; margin-bottom: var(--s5); }
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12.5px;
  color: var(--text-3); margin-bottom: 6px; }
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--brand-700); }
.crumbs svg { opacity: .6; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -.2px; display: flex;
  align-items: center; gap: var(--s3); flex-wrap: wrap; }
.page-head .sub { color: var(--text-3); margin: 6px 0 0; max-width: 760px; }
.head-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---- Tabs ------------------------------------------------------------------- */
.tabs { display: flex; gap: 2px; box-shadow: inset 0 -1px 0 var(--border); margin-bottom: var(--s5);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a { padding: 10px var(--s4); color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap; text-decoration: none !important; display: inline-flex;
  align-items: center; gap: 6px; }
.tabs a { margin-bottom: 0; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--brand-700); border-color: var(--brand-600); }
.tabs .count { font-size: 11.5px; background: var(--surface-3); color: var(--text-3); border-radius: var(--r-pill);
  padding: 0 7px; font-weight: 600; }

/* ---- Cards / panels ------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); margin-bottom: var(--s5); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h2 { font-size: 15.5px; font-weight: 700; display: flex; align-items: center; gap: var(--s2); }
.panel-head .desc { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.panel-body { padding: var(--s5); }
.panel-foot { padding: var(--s3) var(--s5); border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg); display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s4);
  margin-bottom: var(--s5); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s4) var(--s5); display: flex; gap: var(--s4); align-items: center; box-shadow: var(--shadow-sm); }
.stat .ico { width: 42px; height: 42px; border-radius: 12px; background: var(--brand-50); color: var(--brand-700);
  display: grid; place-items: center; flex: none; }
.stat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { color: var(--text-3); font-size: 12.5px; }

.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3); box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .15s; color: inherit; text-decoration: none !important;
  position: relative; }
a.tile:hover { border-color: var(--brand-200); box-shadow: var(--shadow); transform: translateY(-1px); }
.tile-top { display: flex; align-items: flex-start; gap: var(--s3); }
.tile .tico { width: 40px; height: 40px; border-radius: 11px; background: var(--brand-50); color: var(--brand-700);
  display: grid; place-items: center; flex: none; }
.tile h3 { font-size: 15px; font-weight: 700; }
.tile p { margin: 0; color: var(--text-3); font-size: 13px; }
.tile-meta { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: auto; }
.tile .big { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Source block on the overview: a source and its databases */
.source { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface);
  margin-bottom: var(--s5); overflow: hidden; box-shadow: var(--shadow-sm); }
.source-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5);
  background: linear-gradient(90deg, var(--brand-50), var(--surface)); border-bottom: 1px solid var(--border);
  flex-wrap: wrap; }
.source-head h2 { font-size: 15.5px; }
.source-head .tico { width: 36px; height: 36px; border-radius: 10px; background: var(--surface); color: var(--brand-700);
  display: grid; place-items: center; border: 1px solid var(--border); }
.db-list { display: flex; flex-direction: column; }
.db-row { display: grid; grid-template-columns: minmax(220px, 1.4fr) 110px 110px minmax(200px, 2fr) 32px;
  gap: var(--s4); align-items: center; padding: 12px var(--s5); border-bottom: 1px solid var(--border);
  color: inherit; text-decoration: none !important; }
.db-row:last-child { border-bottom: 0; }
a.db-row:hover { background: var(--surface-2); }
.db-row .name { display: flex; align-items: center; gap: var(--s3); font-weight: 600; min-width: 0; }
.db-row .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-row .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.db-row.sub { padding-left: calc(var(--s5) + 34px); background: var(--surface-2); }
.db-row.sub .name { font-weight: 500; }
.db-row .go { color: var(--text-3); display: inline-flex; justify-content: flex-end; }
.tree-line { width: 14px; height: 14px; border-left: 2px solid var(--border-2); border-bottom: 2px solid var(--border-2);
  border-bottom-left-radius: 6px; margin-top: -8px; flex: none; }

/* ---- Chips / badges ---------------------------------------------------------- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; border: 1px solid var(--border-2); color: var(--text-2);
  background: var(--surface); white-space: nowrap; line-height: 18px; }
.chip.solid { background: var(--brand-900); color: #fff; border-color: var(--brand-900); }
.chip.brand { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-200); }
.chip.ok { background: var(--ok-tint); color: var(--ok); border-color: transparent; }
.chip.error { background: var(--error-tint); color: var(--error); border-color: transparent; }
.chip.warn { background: var(--warn-tint); color: var(--warn); border-color: transparent; }
.chip.info { background: var(--info-tint); color: var(--info); border-color: transparent; }
.chip.skip { background: var(--skip-tint); color: var(--skip); border-color: transparent; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.static { background: var(--surface-3); color: var(--text-2); border-color: transparent; }
.chip.dynamic { background: transparent; color: var(--text-2); border-style: dashed; }

/* ---- Buttons ----------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  font: 600 13.5px var(--font); cursor: pointer; text-decoration: none !important; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:focus-visible, .input:focus, select:focus, textarea:focus { outline: none; box-shadow: var(--ring);
  border-color: var(--brand-600); }
.btn-primary { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 32px; padding: 0; }
.btn.danger { color: var(--error); }
.btn.danger:hover { background: var(--error-tint); border-color: var(--error); }
.btn[disabled], .btn.is-busy { opacity: .55; pointer-events: none; }
.btn.is-busy::after { content: ""; width: 13px; height: 13px; border-radius: 50%; border: 2px solid currentColor;
  border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Forms ------------------------------------------------------------------- */
.input, select, textarea { height: 36px; border: 1px solid var(--border-2); border-radius: 9px; background: var(--surface);
  color: var(--text); font: 14px var(--font); padding: 0 11px; width: 100%; }
textarea { height: auto; min-height: 72px; padding: 9px 11px; resize: vertical; }
select { padding-right: 28px; }
.input-sm { height: 30px; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: 13px; color: var(--text-2); }
.field small { color: var(--text-3); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.form-grid .full { grid-column: 1 / -1; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search .input { padding-left: 34px; }
.toolbar { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; padding: var(--s3) var(--s5);
  border-bottom: 1px solid var(--border); }
.toolbar .search { width: 300px; max-width: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--brand-600); margin: 0; }
.switch { position: relative; display: inline-flex; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--border-2); border-radius: 22px; transition: .15s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: .15s; box-shadow: var(--shadow-sm); }
.switch input:checked + .slider { background: var(--brand-600); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:disabled + .slider { opacity: .6; cursor: not-allowed; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.seg a, .seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; font: 600 12.5px var(--font);
  color: var(--text-2); cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.seg .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.choice { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.choice label { border: 1px solid var(--border-2); border-radius: var(--r); padding: var(--s3); cursor: pointer;
  display: flex; flex-direction: column; gap: 2px; }
.choice label:has(input:checked) { border-color: var(--brand-600); box-shadow: var(--ring); background: var(--brand-50); }
.choice input { position: absolute; opacity: 0; }
.choice strong { font-size: 13.5px; }
.choice small { color: var(--text-3); font-size: 12px; }

/* ---- Tables --------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th { text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-3); background: var(--surface-2); padding: 10px var(--s4); border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.table td { padding: 11px var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .ts { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .w1 { width: 1%; white-space: nowrap; }
.table .row-actions { text-align: right; white-space: nowrap; width: 1%; }
.row-btns { display: inline-flex; gap: 4px; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--text-3); font-size: 12.5px; }
.table tr.rowlink { cursor: pointer; }
.pager { display: flex; align-items: center; gap: var(--s2); justify-content: space-between; padding: var(--s3) var(--s5);
  border-top: 1px solid var(--border); color: var(--text-3); font-size: 13px; flex-wrap: wrap; }
.trunc { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block;
  vertical-align: bottom; }

/* ---- Alerts / empty ------------------------------------------------------------ */
.alert { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r);
  border: 1px solid transparent; margin-bottom: var(--s4); }
.alert.info { background: var(--info-tint); color: var(--info); }
.alert.warn { background: var(--warn-tint); color: var(--warn); }
.alert.ok { background: var(--ok-tint); color: var(--ok); }
.alert.error { background: var(--error-tint); color: var(--error); }
.alert p { margin: 0; color: var(--text-2); }
.alert strong { color: inherit; }
.empty { text-align: center; padding: var(--s8) var(--s5); color: var(--text-3); }
.empty .ico { width: 54px; height: 54px; border-radius: 16px; background: var(--surface-3); display: grid; place-items: center;
  margin: 0 auto var(--s3); color: var(--text-3); }
.empty h3 { color: var(--text); font-size: 15px; margin-bottom: 4px; }
.empty p { margin: 0 auto var(--s4); max-width: 420px; }

/* ---- Dialog / toast ---------------------------------------------------------------- */
dialog.modal { border: 0; padding: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: min(620px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); max-height: calc(100vh - 48px); }
dialog.modal.wide { width: min(900px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(8,24,16,.45); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: var(--s5); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5);
  border-top: 1px solid var(--border); background: var(--surface-2); position: sticky; bottom: 0; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--brand-950); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-weight: 500; max-width: 420px; animation: slide .2s ease-out; display: flex; gap: 10px; align-items: center; }
.toast.error { background: #7a1810; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---- Picker (searchable list inside a dialog) ---------------------------------------- */
.pick-list { border: 1px solid var(--border); border-radius: var(--r); max-height: 340px; overflow-y: auto; margin-top: var(--s3); }
.pick-item { display: flex; gap: var(--s3); align-items: center; padding: 9px var(--s3); border-bottom: 1px solid var(--border);
  cursor: pointer; }
.pick-item:last-child { border-bottom: 0; }
.pick-item:hover, .pick-item.sel { background: var(--brand-50); }
.pick-item .code { font-family: var(--mono); font-size: 12px; color: var(--text-3); min-width: 80px; }

/* ---- Permission matrix ---------------------------------------------------------------- */
.role-layout { display: grid; grid-template-columns: 300px 1fr; gap: var(--s5); align-items: start; }
.role-list { display: flex; flex-direction: column; gap: 4px; padding: var(--s2); }
.role-item { display: flex; align-items: center; gap: var(--s3); padding: 10px var(--s3); border-radius: var(--r);
  color: inherit; text-decoration: none !important; border: 1px solid transparent; }
.role-item:hover { background: var(--surface-2); }
.role-item.active { background: var(--brand-50); border-color: var(--brand-200); }
.role-item .rico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3);
  color: var(--text-2); flex: none; }
.role-item.active .rico { background: var(--brand-600); color: #fff; }
.role-item .meta { min-width: 0; flex: 1; }
.role-item strong { display: block; font-size: 13.5px; }
.role-item small { color: var(--text-3); font-size: 12px; }
.perm-mod { border: 1px solid var(--border); border-radius: var(--r); margin-bottom: var(--s3); overflow: hidden; }
.perm-mod-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--surface-2);
  border-bottom: 1px solid var(--border); }
.perm-mod-head .tico { width: 30px; height: 30px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  display: grid; place-items: center; color: var(--brand-700); }
.perm-acts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.perm-act { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); cursor: pointer;
  border-right: 1px solid var(--border); }
.perm-act:last-child { border-right: 0; }
.perm-act input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--brand-600); }
.perm-act strong { display: block; font-size: 13.5px; }
.perm-act small { color: var(--text-3); font-size: 12px; }
.perm-act.implied strong::after { content: " (kèm theo)"; color: var(--text-3); font-weight: 500; font-size: 12px; }

/* ---- Group editor ----------------------------------------------------------------------- */
.group-card { border: 1px solid var(--border); border-radius: var(--r); padding: var(--s4); background: var(--surface);
  display: flex; flex-direction: column; gap: var(--s3); }
.group-card.default { border-style: dashed; }
.group-card-head { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.group-card-head .input { width: auto; }
.rule-row { display: grid; grid-template-columns: 200px 1fr 32px; gap: var(--s2); align-items: center; }
.rule-row.link { grid-template-columns: 1fr 1fr 1fr 32px; }
.order-btns { display: inline-flex; flex-direction: column; }
.gcount { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Link matrix ---------------------------------------------------------------------------- */
.pair { display: flex; align-items: center; gap: var(--s2); min-width: 220px; }
.pair .txt { min-width: 0; flex: 1; }
.pair .txt strong { display: block; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.pair .txt small { color: var(--text-3); font-size: 12px; font-family: var(--mono); }
.pair .none { color: var(--text-3); font-style: italic; }
.pair-edit { opacity: 0; transition: opacity .12s; }
tr:hover .pair-edit, .pair-edit:focus { opacity: 1; }
.link-flow { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.link-node { border: 1px solid var(--border); border-radius: var(--r); padding: var(--s2) var(--s3); background: var(--surface);
  display: flex; flex-direction: column; min-width: 160px; }
.link-node.anchor { border-color: var(--brand-600); background: var(--brand-50); }
.link-node small { color: var(--text-3); font-size: 11.5px; }
.link-node strong { font-size: 13.5px; }
.meter { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; display: flex; min-width: 120px; }
.meter i { display: block; height: 100%; }
.meter .m-rule { background: var(--brand-600); }
.meter .m-manual { background: var(--brand-900); }
.meter .m-amb { background: var(--warn); }
.legend { display: flex; gap: var(--s3); flex-wrap: wrap; font-size: 12px; color: var(--text-3); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

/* ---- Login ------------------------------------------------------------------------------------ */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: radial-gradient(1200px 600px at 10% 10%, #1b6b3a 0%, transparent 60%), var(--sidebar-bg);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-art h1 { font-size: 36px; line-height: 1.15; max-width: 480px; letter-spacing: -.5px; }
.login-art p { color: var(--sidebar-ink); max-width: 460px; font-size: 15px; }
.login-feats { display: grid; gap: 14px; margin-top: 28px; }
.login-feats div { display: flex; gap: 12px; align-items: center; color: var(--sidebar-ink); }
.login-feats .tico { width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.1); display: grid; place-items: center; color: #fff; }
.login-card { display: grid; place-items: center; padding: 40px; }
.login-card .box { width: min(400px, 100%); }
.login-card h2 { font-size: 22px; margin-bottom: 6px; }
.btn-ms { width: 100%; height: 44px; font-size: 14.5px; }

/* ---- Responsive ------------------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .role-layout { grid-template-columns: 1fr; }
  .db-row { grid-template-columns: minmax(180px, 1fr) 90px 90px 32px; }
  .db-row .hide-md { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: var(--sidebar-w); transform: translateX(-100%);
    transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  .mobile-bar { display: flex; align-items: center; gap: var(--s3); background: var(--brand-900); color: #fff; padding: 10px 16px;
    position: sticky; top: 0; z-index: 40; }
  .mobile-bar .brand { padding: 0; }
  .nav-toggle { background: transparent; border: 0; color: #fff; padding: 6px; display: inline-flex; }
  .nav-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 45; }
  .page { padding: var(--s4) 16px var(--s7); }
  .form-grid { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .rule-row, .rule-row.link { grid-template-columns: 1fr; }
}
.dico { width: 30px; height: 30px; border-radius: 8px; background: var(--brand-50); color: var(--brand-700);
  display: grid; place-items: center; flex: none; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-3);
  font-weight: 700; margin: var(--s6) 0 var(--s3); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px var(--s4); margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
pre.json { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s3);
  font: 12px/1.5 var(--mono); max-height: 360px; overflow: auto; margin: 0; white-space: pre-wrap; }
