/* ============================================================
   KIM MÔN ERP — STYLES
   Toàn bộ hệ thống thiết kế (design tokens) + các thành phần giao diện.
   ============================================================ */
:root{
  --bg:#eef1f4;
  --surface:#ffffff;
  --surface-2:#f4f6f8;
  --surface-3:#e8ecf0;
  --border:#d7dde3;
  --border-strong:#c1c9d2;
  --text:#182028;
  --text-muted:#5c6b78;
  --text-faint:#8996a3;
  --accent:#1f6f6b;
  --accent-strong:#175652;
  --accent-soft:#e3f0ef;
  --accent-contrast:#ffffff;
  --focus:#2f8f89;
  --danger:#b5372f;
  --danger-soft:#fbe9e7;
  --st-plan:#4c63c9;
  --st-plan-soft:#e7eafb;
  --st-progress:#a9800a;
  --st-progress-soft:#faf1c9;
  --st-done:#2c8a52;
  --st-done-soft:#e2f3e7;
  --st-off:#b1454a;
  --st-off-soft:#fae3e3;
  --shadow: 0 1px 2px rgba(20,30,40,.06), 0 4px 14px rgba(20,30,40,.06);
  --radius: 7px;
  --radius-sm: 5px;
  --font-ui: 'IBM Plex Sans', system-ui, sans-serif;
  --font-head: 'IBM Plex Sans Condensed', 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#0f1418;
    --surface:#171e24;
    --surface-2:#1c242b;
    --surface-3:#232c34;
    --border:#2b343c;
    --border-strong:#39434c;
    --text:#e8edf1;
    --text-muted:#9aa8b3;
    --text-faint:#6c7a86;
    --accent:#43b3ac;
    --accent-strong:#5cc4be;
    --accent-soft:#163330;
    --accent-contrast:#08201e;
    --focus:#5cc4be;
    --danger:#e2857e;
    --danger-soft:#3a2220;
    --st-plan:#8fa1f2;
    --st-plan-soft:#232a4a;
    --st-progress:#e8c53f;
    --st-progress-soft:#3a3210;
    --st-done:#6cc98d;
    --st-done-soft:#193826;
    --st-off:#ea9490;
    --st-off-soft:#3a2020;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"]{
  --bg:#0f1418;
  --surface:#171e24;
  --surface-2:#1c242b;
  --surface-3:#232c34;
  --border:#2b343c;
  --border-strong:#39434c;
  --text:#e8edf1;
  --text-muted:#9aa8b3;
  --text-faint:#6c7a86;
  --accent:#43b3ac;
  --accent-strong:#5cc4be;
  --accent-soft:#163330;
  --accent-contrast:#08201e;
  --focus:#5cc4be;
  --danger:#e2857e;
  --danger-soft:#3a2220;
  --st-plan:#8fa1f2;
  --st-plan-soft:#232a4a;
  --st-progress:#e8c53f;
  --st-progress-soft:#3a3210;
  --st-done:#6cc98d;
  --st-done-soft:#193826;
  --st-off:#ea9490;
  --st-off-soft:#3a2020;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
}

*,*::before,*::after{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:var(--font-ui); font-size:14px; line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3,h4{font-family:var(--font-head); font-weight:600; margin:0; text-wrap:balance; letter-spacing:.1px}
button,input,select,textarea{font-family:inherit; font-size:inherit; color:inherit}
a{color:var(--accent)}
table{border-collapse:collapse}
::selection{background:var(--accent-soft)}
:focus-visible{outline:2px solid var(--focus); outline-offset:1px}
.mono{font-family:var(--font-mono); font-variant-numeric:tabular-nums}
.scrollx{overflow-x:auto}
code{font-family:var(--font-mono); background:var(--surface-2); padding:1px 5px; border-radius:4px; font-size:.92em}

/* ---------- shell ---------- */
#app{display:flex; min-height:100vh}
.sidebar{
  width:212px; flex:0 0 212px; background:var(--surface); border-right:1px solid var(--border);
  display:flex; flex-direction:column; position:sticky; top:0; height:100vh; z-index:20;
}
.brand{padding:18px 16px 14px; border-bottom:1px solid var(--border)}
.brand .co{font-family:var(--font-head); font-weight:700; font-size:15px; letter-spacing:.2px}
.brand .sub{font-size:11px; color:var(--text-faint); margin-top:2px; text-transform:uppercase; letter-spacing:.6px}
.nav{padding:10px; flex:1; overflow-y:auto}
.nav-group{margin-bottom:14px}
.nav-label{font-size:10.5px; text-transform:uppercase; letter-spacing:.8px; color:var(--text-faint); padding:8px 10px 4px; font-weight:600}
.nav-item{
  display:flex; align-items:center; gap:9px; padding:8px 10px; border-radius:var(--radius-sm);
  color:var(--text-muted); text-decoration:none; cursor:pointer; font-size:13.3px; font-weight:500;
  border:1px solid transparent;
}
.nav-item:hover{background:var(--surface-2); color:var(--text)}
.nav-item.active{background:var(--accent-soft); color:var(--accent-strong); border-color:transparent; font-weight:600}
.nav-item .ic{width:16px; height:16px; flex:0 0 16px; display:inline-flex}
.nav-item .ic svg{width:100%; height:100%}
.sidebar-foot{padding:12px 14px 14px; border-top:1px solid var(--border); font-size:11px; color:var(--text-faint)}

.main{flex:1; min-width:0; display:flex; flex-direction:column}
.topbar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:14px 22px; border-bottom:1px solid var(--border); background:var(--surface);
  position:sticky; top:0; z-index:10;
}
.topbar h1{font-size:19px}
.topbar .crumb{font-size:11.5px; color:var(--text-faint); text-transform:uppercase; letter-spacing:.6px; margin-bottom:2px}
.topbar-actions{display:flex; gap:8px; align-items:center}
.content{padding:20px 22px 60px; flex:1}

.banner{
  display:flex; align-items:center; gap:10px; padding:9px 14px; font-size:12.5px;
  border-bottom:1px solid var(--border);
}
.banner.warn{background:var(--st-progress-soft); color:var(--st-progress)}
.banner.info{background:var(--accent-soft); color:var(--accent-strong)}
.banner.err{background:var(--danger-soft); color:var(--danger)}
.toast-wrap{position:fixed; right:18px; bottom:18px; z-index:100; display:flex; flex-direction:column; gap:8px}
.toast{background:var(--text); color:var(--bg); padding:9px 14px; border-radius:var(--radius-sm); font-size:12.5px; box-shadow:var(--shadow); opacity:.96}

/* ---------- buttons / inputs ---------- */
.btn{
  display:inline-flex; align-items:center; gap:6px; padding:8px 14px; border-radius:var(--radius-sm);
  border:1px solid var(--border-strong); background:var(--surface); color:var(--text);
  cursor:pointer; font-size:13px; font-weight:500; line-height:1.2; white-space:nowrap;
}
.btn:hover{background:var(--surface-2)}
.btn.primary{background:var(--accent); border-color:var(--accent); color:var(--accent-contrast); font-weight:600}
.btn.primary:hover{background:var(--accent-strong); border-color:var(--accent-strong)}
.btn.ghost{border-color:transparent; background:transparent}
.btn.ghost:hover{background:var(--surface-2)}
.btn.danger{color:var(--danger); border-color:var(--danger)}
.btn.danger:hover{background:var(--danger-soft)}
.btn.sm{padding:5px 10px; font-size:12px}
.btn:disabled{opacity:.45; cursor:not-allowed}
.ic{width:14px; height:14px; display:inline-flex; vertical-align:-2px}
.ic svg{width:100%; height:100%}
.btn .ic{width:14px;height:14px;display:inline-flex}
.btn .ic svg{width:100%;height:100%}

.field{display:flex; flex-direction:column; gap:5px}
.field label{font-size:12px; font-weight:600; color:var(--text-muted)}
.field .hint{font-size:11px; color:var(--text-faint)}
input[type=text],input[type=number],input[type=date],input[type=datetime-local],input[type=time],
input[type=email],input[type=password],select,textarea{
  padding:8px 10px; border:1px solid var(--border-strong); border-radius:var(--radius-sm);
  background:var(--surface); color:var(--text); width:100%;
}
textarea{resize:vertical; min-height:56px; font-family:inherit}
input:focus,select:focus,textarea:focus{border-color:var(--focus)}
.grid{display:grid; gap:14px}
.g2{grid-template-columns:1fr 1fr}
.g3{grid-template-columns:1fr 1fr 1fr}
.g4{grid-template-columns:1fr 1fr 1fr 1fr}
@media (max-width:860px){.g2,.g3,.g4{grid-template-columns:1fr}}

.card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow)}
.card .card-head{display:flex; align-items:center; justify-content:space-between; gap:10px; padding:13px 16px; border-bottom:1px solid var(--border)}
.card .card-head h3{font-size:14.5px}
.card .card-body{padding:16px}
.section-gap{display:flex; flex-direction:column; gap:16px}

/* ---------- data table ---------- */
.dtable{width:100%; border-collapse:collapse; font-size:13px; min-width:640px}
.dtable thead th{
  text-align:left; font-size:11px; text-transform:uppercase; letter-spacing:.4px; color:var(--text-faint);
  font-weight:600; padding:9px 12px; border-bottom:1px solid var(--border); background:var(--surface-2); white-space:nowrap;
  position:sticky; top:0;
}
.dtable tbody td{padding:10px 12px; border-bottom:1px solid var(--border); vertical-align:middle}
.dtable tbody tr{cursor:pointer}
.dtable tbody tr:hover{background:var(--surface-2)}
.dtable tbody tr.nohover{cursor:default}
.dtable tbody tr.nohover:hover{background:transparent}
.dtable .num{text-align:right; font-family:var(--font-mono); font-variant-numeric:tabular-nums}
.row-actions{display:flex; gap:4px; justify-content:flex-end}

.pill{display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:99px; font-size:11.5px; font-weight:600; white-space:nowrap}
.pill::before{content:""; width:6px; height:6px; border-radius:99px; background:currentColor}
.pill.plan{background:var(--st-plan-soft); color:var(--st-plan)}
.pill.progress{background:var(--st-progress-soft); color:var(--st-progress)}
.pill.done{background:var(--st-done-soft); color:var(--st-done)}
.pill.off{background:var(--st-off-soft); color:var(--st-off)}

.empty{padding:40px 20px; text-align:center; color:var(--text-faint)}
.empty .ic{width:34px; height:34px; margin:0 auto 10px; opacity:.5}
.kpis{display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:12px}
.kpi{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:13px 15px}
.kpi .lbl{font-size:11px; text-transform:uppercase; letter-spacing:.4px; color:var(--text-faint); font-weight:600}
.kpi .val{font-family:var(--font-mono); font-size:22px; font-weight:600; margin-top:4px}
.kpi .val small{font-size:12px; color:var(--text-faint); font-weight:500; font-family:var(--font-ui)}

.searchbar{display:flex; gap:8px; align-items:center; flex-wrap:wrap}
.searchbar input[type=text]{max-width:260px}
.searchbar select{width:auto; max-width:170px}

/* ---------- dashboard gantt ---------- */
.gantt-toolbar{display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:10px; margin-bottom:14px}
.seg{display:inline-flex; border:1px solid var(--border-strong); border-radius:var(--radius-sm); overflow:hidden}
.seg button{border:none; background:var(--surface); padding:6px 12px; font-size:12.5px; cursor:pointer; color:var(--text-muted); border-right:1px solid var(--border-strong)}
.seg button:last-child{border-right:none}
.seg button.active{background:var(--accent); color:var(--accent-contrast); font-weight:600}
.datewalk{display:flex; align-items:center; gap:6px}
.datewalk .lbl{font-family:var(--font-mono); font-size:13px; min-width:150px; text-align:center; font-weight:600}
.legend{display:flex; gap:14px; flex-wrap:wrap; font-size:12px; color:var(--text-muted)}
.legend span{display:inline-flex; align-items:center; gap:6px}
.legend i{width:9px; height:9px; border-radius:2px; display:inline-block}

.gantt{border:1px solid var(--border); border-radius:var(--radius); background:var(--surface); overflow:hidden}
.gantt-scroll{overflow-x:auto}
.gantt-grid{display:grid; min-width:760px}
.gantt-head{display:flex; border-bottom:1px solid var(--border); background:var(--surface-2); position:sticky; top:0}
.gantt-head .rowlabel-col{width:150px; flex:0 0 150px; padding:8px 12px; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.4px; color:var(--text-faint); border-right:1px solid var(--border)}
.gantt-head .col{flex:1; padding:8px 6px; font-size:11.5px; text-align:center; color:var(--text-muted); border-right:1px solid var(--border); font-family:var(--font-mono)}
.gantt-head .col.today{color:var(--accent-strong); font-weight:700; background:var(--accent-soft)}
.gantt-row{display:flex; border-bottom:1px solid var(--border)}
.gantt-row:last-child{border-bottom:none}
.gantt-row .rowlabel-col{width:150px; flex:0 0 150px; padding:3px 12px; border-right:1px solid var(--border); background:var(--surface-2); display:flex; align-items:center; gap:6px}
.gantt-row .rowlabel-col .code{font-family:var(--font-mono); font-weight:700; font-size:11.5px}
.gantt-row .rowlabel-col .ty{font-size:10px; color:var(--text-faint)}
.gantt-track{flex:1; position:relative; min-height:26px; background-image:repeating-linear-gradient(to right, transparent, transparent calc(100%/var(--cols) - 1px), var(--border) calc(100%/var(--cols) - 1px), var(--border) calc(100%/var(--cols)))}
.gantt-bar{
  position:absolute; top:3px; bottom:3px; border-radius:4px; padding:0 6px; display:flex; align-items:center;
  font-size:10px; font-weight:600; overflow:hidden; white-space:nowrap; cursor:pointer; border:1px solid rgba(0,0,0,.08);
}
.gantt-bar span{overflow:hidden; text-overflow:ellipsis}
.gantt-bar.plan{background:var(--st-plan-soft); color:var(--st-plan); border-color:var(--st-plan)}
.gantt-bar.progress{background:var(--st-progress-soft); color:var(--st-progress); border-color:var(--st-progress)}
.gantt-bar.done{background:var(--st-done-soft); color:var(--st-done); border-color:var(--st-done)}
.gantt-bar.off{background:var(--st-off-soft); color:var(--st-off); border-color:var(--st-off)}
.gantt-bar:hover{filter:brightness(0.96); box-shadow:0 0 0 2px var(--focus) inset}

/* ---------- order detail / logs ---------- */
.info-grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(160px,1fr)); gap:12px 22px}
.info-item .k{font-size:11px; text-transform:uppercase; letter-spacing:.4px; color:var(--text-faint); font-weight:600}
.info-item .v{font-size:14px; margin-top:3px; font-weight:600}
.info-item .v.mono{font-family:var(--font-mono)}
.progressbar{height:8px; border-radius:99px; background:var(--surface-3); overflow:hidden}
.progressbar > i{display:block; height:100%; background:var(--accent); border-radius:99px}

.inline-form{display:flex; gap:8px; flex-wrap:wrap; align-items:end; padding:12px 16px; background:var(--surface-2); border-top:1px solid var(--border)}
.inline-form .field{flex:1; min-width:110px}
.inline-form .field.narrow{flex:0 0 90px; min-width:90px}
.inline-form .field.wide{flex:1.6; min-width:150px}
.entry-by{font-size:10.5px; color:var(--text-faint)}

/* ---------- modal ---------- */
.modal-backdrop{position:fixed; inset:0; background:rgba(15,20,25,.5); display:flex; align-items:center; justify-content:center; z-index:60; padding:20px}
.modal{background:var(--surface); border-radius:var(--radius); width:min(420px,100%); box-shadow:var(--shadow); border:1px solid var(--border)}
.modal .mh{padding:15px 18px; border-bottom:1px solid var(--border); font-weight:600; font-size:15px}
.modal .mb{padding:16px 18px; font-size:13.5px; color:var(--text-muted)}
.modal .mf{padding:12px 18px 16px; display:flex; justify-content:flex-end; gap:8px}

.form-footer{display:flex; justify-content:space-between; align-items:center; padding-top:6px}
.badge-count{background:var(--surface-3); color:var(--text-muted); padding:1px 7px; border-radius:99px; font-size:11px; font-family:var(--font-mono)}

/* ---------- catalog reorder ---------- */
.reorder-cell{background:var(--surface-2)}
.drag-handle:active{cursor:grabbing}
.drag-over{box-shadow:inset 0 2px 0 var(--accent)}
.mopt-row{align-items:end; border-bottom:1px dashed var(--border); padding-bottom:12px; margin-bottom:2px}

/* ---------- permission checkboxes ---------- */
.chk{display:inline-flex; align-items:center; gap:4px; margin:0 6px; cursor:pointer}
.chk input{width:auto; cursor:pointer}

/* ---------- print sheet ---------- */
.print-only{display:none}
@media print{
  .sidebar,.topbar,.banner,.toast-wrap,.no-print{display:none !important}
  .content{padding:0 !important}
  body{background:#fff !important; color:#000 !important}
  .print-only{display:block}
  .print-sheet{width:100%}
  .ps-page{padding:14mm; page-break-after:always}
  .ps-page:last-child{page-break-after:auto}
}
.print-sheet{font-family:var(--font-ui); color:#111}
.ps-page{border:1px solid #999; margin:0 auto 18px; max-width:900px; padding:16px 20px; background:#fff; color:#111}
.ps-titlebar{display:flex; justify-content:space-between; align-items:flex-start; border-bottom:2px solid #111; padding-bottom:8px; margin-bottom:10px}
.ps-titlebar .co{font-size:11px; line-height:1.4}
.ps-titlebar h2{font-family:var(--font-head); font-size:22px; letter-spacing:.5px}
.ps-table{width:100%; border-collapse:collapse; font-size:12px; margin-bottom:14px}
.ps-table th,.ps-table td{border:1px solid #888; padding:4px 7px}
.ps-table th{background:#eee; font-weight:700; text-align:left}
.ps-hdr-table td{border:1px solid #888; padding:5px 8px; font-size:12px}
.ps-hdr-table .k{color:#444; width:150px}
.ps-hdr-table .v{font-weight:700}
.ps-note{font-size:11px; color:#555; margin-top:4px}

.sidebar-toggle{display:none}
@media (max-width:760px){
  .sidebar{position:fixed; left:-220px; transition:left .18s ease; box-shadow:var(--shadow)}
  .sidebar.open{left:0}
  .sidebar-toggle{display:inline-flex}
  .content{padding:16px}
  .topbar{padding:12px 14px}
}

/* ---------- auth screens ---------- */
.authwrap{min-height:100vh; width:100%; display:flex; align-items:center; justify-content:center; padding:24px; background:var(--bg)}
.authcard{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow); width:min(380px,100%); padding:28px 26px}
.auth-brand{text-align:center; margin-bottom:20px}
.auth-logo{width:44px; height:44px; margin:0 auto 10px; border-radius:99px; background:var(--accent-soft); color:var(--accent-strong); display:flex; align-items:center; justify-content:center}
.auth-logo .ic{width:22px; height:22px}
.auth-brand h1{font-size:18px}
.auth-sub{font-size:12px; color:var(--text-faint); margin-top:4px}
.authcard p{font-size:13px; color:var(--text-muted); line-height:1.55}
.auth-switch{text-align:center; font-size:12.5px; color:var(--text-muted)}

/* ---------- home / module launcher ---------- */
.module-grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(210px,1fr)); gap:14px}
.module-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow);
  padding:18px 16px; display:flex; flex-direction:column; gap:10px; align-items:flex-start;
}
.module-card.clickable{cursor:pointer}
.module-card.clickable:hover{border-color:var(--accent); box-shadow:0 0 0 1px var(--accent), var(--shadow)}
.module-card.disabled{opacity:.62}
.module-ic{width:38px; height:38px; border-radius:var(--radius-sm); background:var(--accent-soft); color:var(--accent-strong); display:flex; align-items:center; justify-content:center}
.module-ic .ic{width:20px; height:20px}
.module-label{font-family:var(--font-head); font-weight:600; font-size:15px}
.tag{display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:99px; font-size:11px; font-weight:600}
.tag.soon{background:var(--surface-3); color:var(--text-faint)}
.tag.locked{background:var(--danger-soft); color:var(--danger)}
.tag.ready{background:var(--st-done-soft); color:var(--st-done)}

/* ---------- sidebar user chip ---------- */
.user-chip{display:flex; align-items:center; gap:9px}
.user-chip .ic{width:30px; height:30px; flex:0 0 30px; border-radius:99px; background:var(--surface-3); color:var(--text-muted); padding:6px}
.u-name{font-size:12.5px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:130px}
.u-role{font-size:10.5px; color:var(--text-faint)}
