:root {
  --bg: #fdf6f8;
  --surface: #ffffff;
  --surface-2: #fff9fb;
  --border: #f2e3e8;
  --text: #2a2140;
  --muted: #7d7392;
  --primary: #f2557a;
  --primary-2: #ff7d9b;
  --primary-soft: #ffe9ef;
  --green: #16a34a; --green-soft: #e6f8ed; --green-bar: #34d399;
  --red: #e11d48; --red-soft: #fde7ec;
  --orange: #e8780c; --orange-soft: #fff1e0;
  --blue: #2563eb; --blue-soft: #e8f0ff;
  --purple: #7c3aed; --purple-soft: #f1eaff;
  --gray: #6b6b80; --gray-soft: #f2f1f6;
  --shadow: 0 1px 2px rgba(42, 33, 64, .04), 0 4px 16px rgba(242, 85, 122, .05);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ico { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ico svg { width: 100%; height: 100%; }
.ico.pink { color: var(--primary); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: linear-gradient(180deg, #fff 0%, #fff6f9 100%);
  border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-logo { width: 42px; height: 42px; border-radius: 12px; background: var(--primary-soft); display: grid; place-items: center; font-size: 24px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #4a4060; cursor: pointer; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 6px; }
.sidebar-backdrop { display: none; }
.side-card { margin-top: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: center; }
.side-cat { font-size: 40px; }
.side-card p { margin: 6px 0 0; color: #5a4f70; }

.main { min-width: 0; padding: 14px 24px 32px; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.icon-btn.menu-btn { display: none; }
.global-search { flex: 1; max-width: 620px; display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; height: 42px; }
.global-search input { border: 0; outline: 0; flex: 1; background: transparent; min-width: 0; }
.global-search kbd { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.icon-btn { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer; position: relative; }
.icon-btn:hover { background: var(--primary-soft); }
.bell .dot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.user { display: flex; align-items: center; gap: 10px; }
.user small { display: block; color: var(--muted); font-size: 12px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, #ffb3c6, #f2557a); color: #fff; display: grid; place-items: center; font-weight: 700; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 26px; }
.page-head p { margin: 4px 0 0; }
.head-actions { display: flex; gap: 10px; }

.btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: #fff; cursor: pointer; white-space: nowrap; }
.btn .ico { width: 16px; height: 16px; }
.btn:hover { border-color: #e9c9d3; }
.btn-primary { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; border-color: transparent; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.04); }
.btn-outline-green { color: var(--green); border-color: #bfe8cf; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 16px 0; }
.card-head h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { border-radius: var(--radius); padding: 14px; display: flex; gap: 12px; border: 1px solid var(--border); }
.kpi-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; }
.kpi-ico .ico { width: 20px; height: 20px; }
.kpi b.lbl { display: block; font-size: 12.5px; font-weight: 600; }
.kpi .val { font-size: 24px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; }
.kpi .val i { font-style: normal; font-size: 11.5px; font-weight: 600; padding: 2px 6px; border-radius: 6px; }
.kpi small { color: var(--muted); font-size: 12px; }
.k-pink { background: #fff1f4; } .k-pink .kpi-ico { background: var(--primary); } .k-pink i { background: #ffdbe4; color: var(--primary); }
.k-blue { background: #f1f6ff; } .k-blue .kpi-ico { background: #3b82f6; } .k-blue i { background: #dbe8ff; color: var(--blue); }
.k-purple { background: #f6f1ff; } .k-purple .kpi-ico { background: #8b5cf6; } .k-purple i { background: #e8ddff; color: var(--purple); }
.k-green { background: #effbf3; } .k-green .kpi-ico { background: #22c55e; } .k-green i { background: #d5f5e1; color: var(--green); }
.k-orange { background: #fff7ec; } .k-orange .kpi-ico { background: #f59e0b; } .k-orange i { background: #ffe8c7; color: var(--orange); }

/* ---------- table card / toolbar ---------- */
.table-card { padding: 0 0 6px; }
.mode-tabs { display: flex; gap: 4px; padding: 10px 14px 0; border-bottom: 1px solid var(--border); }
.mode-tab { border: 0; background: transparent; padding: 8px 12px 10px; cursor: pointer; color: var(--muted); font-weight: 600; display: inline-flex; gap: 6px; align-items: center; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.mode-tab .ico { width: 16px; height: 16px; }
.mode-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.toolbar { position: relative; display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 14px; align-items: center; }
.tb-period { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 12px; border: 1px solid var(--border); background: #fff; border-radius: 10px; cursor: pointer; text-align: left; }
.tb-period b { display: block; font-size: 13px; }
.tb-period small { display: block; font-size: 11px; color: var(--muted); }
.tb-period .chev { width: 14px; height: 14px; color: var(--muted); }
.tb-select { height: 38px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; background: #fff; max-width: 220px; }
.tb-search { flex: 1 1 200px; display: flex; align-items: center; gap: 8px; height: 38px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; background: #fff; min-width: 0; }
.tb-search input { border: 0; outline: 0; flex: 1; min-width: 0; background: transparent; }
.tb-search .ico { width: 16px; height: 16px; color: var(--muted); }
.btn-filter { font-weight: 600; position: relative; }
.btn-filter.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn-filter .badge { position: absolute; top: -7px; right: -7px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--primary); color: #fff; font-size: 11px; font-style: normal; display: grid; place-items: center; padding: 0 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 10px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 500; }
.chip button { border: 0; background: transparent; cursor: pointer; width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; color: inherit; padding: 0; }
.chip button:hover { background: rgba(0, 0, 0, .06); }
.chip .ico { width: 12px; height: 12px; }
.chip-time { background: var(--primary-soft); color: #c43a5e; }
.chip-product { background: var(--green-soft); color: #15803d; }
.chip-supplier { background: var(--blue-soft); color: var(--blue); }
.chip-status { background: var(--purple-soft); color: var(--purple); }
.chip-q { background: var(--gray-soft); color: var(--gray); }
.chip-clear { border: 0; background: transparent; color: var(--primary); cursor: pointer; font-weight: 600; font-size: 12.5px; }

.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); padding: 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid #f7edf1; white-space: nowrap; }
.tbl tr.row { cursor: pointer; }
.tbl tr.row:hover td { background: #fffafc; }
.tbl .num { text-align: right; }
.tbl .po-link { color: var(--primary); font-weight: 600; }
.tbl .po-link:hover { text-decoration: underline; }
.tbl .wrap { white-space: normal; min-width: 220px; }
.tbl tfoot td { font-weight: 600; background: var(--surface-2); }
.tbl-empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.po-mark { display: inline-block; width: 3px; height: 18px; border-radius: 2px; vertical-align: middle; margin-right: 8px; }

.pill { display: inline-block; padding: 3px 8px; border-radius: 7px; font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.t-green { background: var(--green-soft); color: var(--green); }
.t-red { background: var(--red-soft); color: var(--red); }
.t-orange { background: var(--orange-soft); color: var(--orange); }
.t-blue { background: var(--blue-soft); color: var(--blue); }
.t-purple { background: var(--purple-soft); color: var(--purple); }
.t-gray { background: var(--gray-soft); color: var(--gray); }
.bar-green { background: #22c55e; } .bar-red { background: #f43f5e; } .bar-orange { background: #f59e0b; } .bar-blue { background: #3b82f6; } .bar-purple { background: #8b5cf6; } .bar-gray { background: #a3a3b5; }

.progress { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.progress .track { flex: 1; height: 6px; background: #f1edf3; border-radius: 4px; overflow: hidden; }
.progress .fill { height: 100%; border-radius: 4px; }
.progress span { color: var(--muted); font-size: 11.5px; width: 34px; text-align: right; }

.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pager button { min-width: 30px; height: 30px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; }
.pager button.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager select { height: 30px; border-radius: 8px; border: 1px solid var(--border); margin-right: 8px; }

/* ---------- filter popover / drawer ---------- */
.filter-pop {
  position: absolute; top: calc(100% - 4px); z-index: 40; width: 560px; max-width: calc(100vw - 32px);
  background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 18px 50px rgba(42, 33, 64, .18);
  display: flex; flex-direction: column; max-height: min(78vh, 720px);
}
.fp-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.fp-body { overflow-y: auto; padding: 4px 16px 8px; }
.fp-section { padding: 12px 0; border-bottom: 1px dashed var(--border); }
.fp-section:last-child { border-bottom: 0; }
.fp-title { font-weight: 600; margin-bottom: 8px; }
.fp-title small { font-weight: 400; color: var(--muted); }
.fp-hint { margin-top: 8px; font-size: 12px; color: var(--muted); }
.fp-hint b { color: var(--text); }
.fp-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.spacer { flex: 1; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--gray-soft); border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.segmented button { border: 0; background: transparent; padding: 7px 4px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--muted); }
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.segmented button i { font-style: normal; font-size: 11px; background: var(--primary); color: #fff; border-radius: 8px; padding: 0 5px; margin-left: 4px; }
.opt-grid { display: grid; gap: 6px; }
.opt-grid.months { grid-template-columns: repeat(6, 1fr); }
.opt-grid.quarters { grid-template-columns: repeat(4, 1fr); }
.opt-grid.years { grid-template-columns: repeat(4, 1fr); }
.opt { border: 1px solid var(--border); background: #fff; border-radius: 9px; padding: 8px 4px; cursor: pointer; text-align: center; }
.opt small { display: block; font-size: 10.5px; color: var(--muted); }
.opt:hover { border-color: #f0b8c7; }
.opt.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.opt .cnt { display: block; font-size: 10.5px; color: var(--muted); font-weight: 400; }
.range-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.range-row input { height: 36px; border: 1px solid var(--border); border-radius: 9px; padding: 0 8px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-list:empty { display: none; }
.tag { border: 1px solid var(--border); background: #fff; border-radius: 20px; padding: 5px 12px; cursor: pointer; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.tag.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tag .ico { width: 12px; height: 12px; }
.fp-input { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; height: 38px; }
.fp-input input { border: 0; outline: 0; flex: 1; min-width: 0; }
.fp-input .ico { width: 16px; height: 16px; color: var(--muted); }
.fp-backdrop { position: fixed; inset: 0; background: rgba(42, 33, 64, .28); z-index: 35; }

/* ---------- autocomplete ---------- */
.ac-host { position: relative; }
.ac-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 60; background: #fff; border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 14px 40px rgba(42, 33, 64, .16); max-height: 380px; overflow-y: auto; padding: 6px; min-width: 280px;
}
.ac-group { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px 4px; }
.ac-item { display: flex; justify-content: space-between; gap: 12px; padding: 8px; border-radius: 8px; cursor: pointer; }
.ac-item.active, .ac-item:hover { background: var(--primary-soft); }
.ac-item b { display: block; font-weight: 600; }
.ac-item small { color: var(--muted); font-size: 11.5px; }
.ac-item .ac-meta { text-align: right; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.ac-item mark { background: #ffe08a; color: inherit; border-radius: 2px; }
.ac-empty { padding: 12px; color: var(--muted); font-size: 12.5px; }

/* ---------- alerts ---------- */
.alert-sum { padding: 14px 16px; }
.alert-sum h3 { margin: 0 0 10px; font-size: 15px; color: var(--red); display: flex; gap: 8px; align-items: center; }
.alert-sum .body { display: flex; gap: 14px; align-items: center; }
.alert-sum .big { background: var(--primary-soft); color: var(--primary); border-radius: 12px; padding: 10px 14px; font-size: 26px; font-weight: 700; white-space: nowrap; }
.alert-sum .big small { font-size: 15px; font-weight: 500; }
.alert-sum ul { list-style: none; margin: 0; padding: 0; font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
.alert-sum li::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--c); }
.alert-detail { padding: 14px 0 6px; }
.alert-detail .card-head { padding: 0 16px; }
.alert-tabs { display: flex; gap: 4px; padding: 10px 12px; flex-wrap: wrap; }
.alert-tabs button { border: 0; background: transparent; padding: 5px 8px; border-radius: 8px; font-size: 12px; cursor: pointer; color: var(--muted); }
.alert-tabs button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.alert-list { max-height: 420px; overflow-y: auto; }
.alert-item { display: flex; gap: 10px; padding: 10px 16px; border-top: 1px solid #f7edf1; cursor: pointer; font-size: 12.5px; }
.alert-item:hover { background: var(--surface-2); }
.alert-item .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 3px; flex: none; }
.alert-item b { display: block; font-size: 13px; }
.link-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.link-btn:hover { color: var(--primary); }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 16px; margin: 16px 0; }
.chart-card { padding: 14px 16px; }
.chart-card h3 { margin: 0 0 12px; font-size: 14.5px; display: flex; gap: 8px; align-items: center; }
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { width: 140px; height: 140px; border-radius: 50%; position: relative; flex: none; }
.donut::after { content: ''; position: absolute; inset: 20px; background: #fff; border-radius: 50%; }
.donut .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; z-index: 1; }
.donut .center b { font-size: 24px; }
.donut .center small { font-size: 11px; color: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 12px; flex: 1; min-width: 140px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend li i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend li b { margin-left: auto; }
.legend.row { flex-direction: row; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; border-bottom: 1px solid var(--border); padding-top: 6px; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; min-width: 0; }
.bars .col .seg { width: 100%; }
.bars .col .seg:first-child { border-radius: 4px 4px 0 0; }
.bars .col .tip { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.bars-x { display: flex; gap: 8px; margin-top: 6px; }
.bars-x span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); min-width: 0; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1.3fr) 1fr auto; gap: 10px; align-items: center; font-size: 12px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.hbar .name:hover { color: var(--primary); }
.hbar .track { height: 8px; background: #f3eef4; border-radius: 6px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #ff9db4, var(--primary)); }
.hbar .v { color: var(--muted); white-space: nowrap; }

/* ---------- product lookup ---------- */
#product-view { padding: 0 14px 14px; }
.lookup-search { display: flex; align-items: center; gap: 10px; height: 46px; border: 2px solid var(--primary-soft); border-radius: 12px; padding: 0 12px; margin-bottom: 14px; }
.lookup-search input { border: 0; outline: 0; flex: 1; min-width: 0; font-size: 15px; }
.lookup-search .ico { color: var(--primary); }
.lookup-empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.lookup-empty .big { font-size: 40px; }
.psum { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: linear-gradient(135deg, #fff, #fff6f9); }
.psum-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.psum-head h4 { margin: 0; font-size: 16px; }
.psum-head small { color: var(--muted); }
.psum-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-top: 12px; }
.psum-stats div { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.psum-stats small { display: block; color: var(--muted); font-size: 11.5px; }
.psum-stats b { font-size: 17px; }
.po-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.po-chips a { font-size: 12px; color: var(--primary); background: var(--primary-soft); border-radius: 6px; padding: 2px 8px; font-weight: 600; }

/* ---------- shipments ---------- */
.ship-card { padding-bottom: 4px; }
.ship-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.ship-tools .tb-search { min-width: 220px; }
.ship-note { padding: 0 16px; margin: 6px 0 8px; }

/* ---------- detail ---------- */
.detail-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 14px; }
.detail-head h1 { margin: 6px 0 4px; font-size: 24px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.back { color: var(--muted); font-size: 13px; }
.back:hover { color: var(--primary); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.detail-grid .card { padding: 12px 14px; }
.detail-grid small { display: block; color: var(--muted); font-size: 12px; }
.detail-grid b { font-size: 17px; }
.detail-section { margin-bottom: 16px; }
.detail-section .card-head { padding-bottom: 10px; }

/* ---------- inner pages ---------- */
#view-page { display: flex; flex-direction: column; gap: 16px; }
#view-page .page-head { margin-bottom: 0; }
.page-grid { display: grid; gap: 16px; }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.g-1-1 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pcard { padding-bottom: 6px; min-width: 0; }
.pcard-body { padding: 12px 16px 10px; }
.pcard-body .tbl-wrap { margin: 0 -16px; }
.pcard-body > p.small { margin: 10px 0 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .tb-search { flex: 0 1 220px; }
.seg-btns { display: inline-flex; background: var(--gray-soft); border-radius: 10px; padding: 3px; }
.seg-btns button { border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.seg-btns button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.mini-list { display: flex; flex-direction: column; }
.mini-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #f7edf1; cursor: pointer; font-size: 13px; }
.mini-row:first-child { border-top: 0; }
.mini-row:hover { background: var(--surface-2); }
.mini-row .grow { flex: 1; min-width: 0; }
.mini-row .qty { min-width: 60px; text-align: right; }
.date-badge { width: 74px; flex: none; text-align: center; border-radius: 10px; padding: 6px 4px; background: var(--blue-soft); color: var(--blue); }
.date-badge b { display: block; }
.date-badge small { font-size: 10.5px; }
.date-badge.soon { background: var(--orange-soft); color: var(--orange); }
.date-badge.late { background: var(--red-soft); color: var(--red); }
.date-group { margin-bottom: 14px; }
.date-group-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.date-group .mini-row { padding-left: 10px; padding-right: 10px; }
.wh-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.wh-card { text-align: left; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; font: inherit; }
.wh-card b { font-size: 17px; }
.wh-card .ico { width: 14px; height: 14px; vertical-align: -2px; }
.wh-card.on { border-color: var(--primary); background: var(--primary-soft); }
.tbl tr.sel td { background: var(--primary-soft); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.code { background: #2a2140; color: #ffe1ea; padding: 12px; border-radius: 10px; white-space: pre-wrap; word-break: break-all; font-size: 12.5px; }
.rules { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 1100px) { .g-2-1, .g-1-2, .g-1-1 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- auth ---------- */
body.booting .app { visibility: hidden; }
.auth-screen { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: radial-gradient(circle at 20% 10%, #ffe1ea 0, transparent 45%), radial-gradient(circle at 90% 90%, #e8ddff 0, transparent 40%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 20px 60px rgba(42, 33, 64, .12); padding: 26px; }
.auth-brand { padding: 0; margin-bottom: 18px; }
.auth-card h2 { margin: 0 0 12px; font-size: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.auth-field input { height: 42px; border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; font-size: 14px; }
.auth-field input:focus, .adm-form input:focus, .adm-form select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.auth-hint { font-size: 12px; color: var(--muted); margin: 0; }
.auth-error { color: var(--red); font-size: 13px; margin: 0; min-height: 1em; }
.auth-submit { height: 44px; justify-content: center; }
.auth-actions { display: flex; justify-content: flex-end; gap: 8px; }

.user { position: relative; }
.user-btn { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 12px; text-align: left; }
.user-btn:hover { background: var(--primary-soft); }
.user-text small { display: block; color: var(--muted); font-size: 11.5px; }
.user-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 80; width: 260px; background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 14px 40px rgba(42, 33, 64, .16); padding: 6px; display: flex; flex-direction: column; }
.user-menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.user-menu-head small { color: var(--muted); }
.user-menu button, .user-menu a { border: 0; background: transparent; text-align: left; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.user-menu button:hover, .user-menu a:hover { background: var(--surface-2); }
.user-menu .danger, .btn.danger { color: var(--red); }

/* ---------- PO detail widgets ---------- */
.widgets { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.widget { display: flex; gap: 14px; align-items: center; padding: 14px 16px; }
.widget small { display: block; color: var(--muted); font-size: 12px; }
.widget .w-big { display: block; font-size: 26px; line-height: 1.15; }
.widget .w-title { display: block; font-size: 17px; margin: 2px 0; }
.widget.w-red { border-color: #fbc4cf; background: #fff6f8; }
.widget.w-green { border-color: #bfe8cf; background: #f5fcf7; }
.w-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.w-ico .ico { width: 22px; height: 22px; }
.w-ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: none; display: grid; place-items: center; position: relative;
  background: conic-gradient(#22c55e calc(var(--p) * 1%), #f1edf3 0); }
.w-ring::after { content: ''; position: absolute; inset: 7px; background: #fff; border-radius: 50%; }
.w-ring b { position: relative; z-index: 1; font-size: 13px; }
.remain { color: var(--orange); }
.remain.late { color: var(--red); }

/* ---------- admin ---------- */
.forbidden { padding: 40px 20px; text-align: center; }
.forbidden .big { font-size: 44px; }
.adm-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.adm-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.adm-form input, .adm-form select { height: 38px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; color: var(--text); background: #fff; }
.adm-actions { display: flex; flex-wrap: wrap; gap: 4px; white-space: normal; min-width: 240px; }
.adm-actions .btn { height: 30px; padding: 0 8px; font-size: 12px; }
.reveal { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-color: #fcd34d; background: #fffbeb; flex-wrap: wrap; }
.reveal .grow { flex: 1; min-width: 220px; }
.reveal p { margin: 4px 0 8px; }
.temp-pw { display: inline-block; font-size: 18px; letter-spacing: .08em; background: #fff; border: 1px dashed #f59e0b; border-radius: 8px; padding: 6px 12px; user-select: all; }
.reveal-actions { display: flex; gap: 8px; }
.level { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; font-weight: 700; color: #fff; }
.level.l5 { background: #e11d48; } .level.l4 { background: #f97316; } .level.l3 { background: #8b5cf6; } .level.l2 { background: #3b82f6; } .level.l1 { background: #9ca3af; }
.perm-cell { text-align: center; }
.perm-cell .yes { color: var(--green); font-weight: 700; }
.perm-cell .no { color: #d4d0dc; }

.foot { text-align: center; margin-top: 18px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .col-side { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
}
@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 70; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .sidebar { transform: none; }
  .sidebar-backdrop { display: none; }
  .app.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(42, 33, 64, .3); }
  .icon-btn.menu-btn { display: inline-grid; }
}
@media (max-width: 768px) {
  .main { padding: 10px 16px 24px; }
  .user-text, .global-search kbd { display: none; }
  .page-head h1 { font-size: 21px; }
  .tb-select, .tb-period { flex: 1 1 140px; max-width: none; }
  .tb-search { flex-basis: 100%; }
  /* Drawer trên mobile */
  .filter-pop {
    position: fixed; left: 0 !important; right: 0; bottom: 0; top: auto; width: 100%; max-width: none;
    border-radius: 18px 18px 0 0; max-height: 88vh; z-index: 50; animation: up .2s ease-out;
  }
  .fp-head::before { content: ''; position: absolute; left: 50%; transform: translateX(-50%); top: 6px; width: 40px; height: 4px; border-radius: 2px; background: var(--border); }
  .fp-head { position: relative; }
  .opt-grid.months { grid-template-columns: repeat(4, 1fr); }
  .opt-grid.years { grid-template-columns: repeat(3, 1fr); }
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
