/* ============================ App UI ============================ */
:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f2f4f7;
  --border: #e4e7ec;
  --border-2: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;
  --primary: #1d4ed8;
  --primary-2: #1e40af;
  --primary-soft: #eef3ff;
  --primary-ring: rgba(29, 78, 216, .2);
  --good: #067647; --good-soft: #ecfdf3; --good-line: #abefc6;
  --warn: #b54708; --warn-soft: #fffaeb; --warn-line: #fedf89;
  --bad: #b42318; --bad-soft: #fef3f2; --bad-line: #fecdca;
  --info: #175cd3; --info-soft: #eff8ff; --info-line: #b2ddff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, .16), 0 4px 10px rgba(16, 24, 40, .06);
  --side-w: 244px;
  --font: "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body.modal-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text); }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden, [hidden] { display: none !important; }
.ic { width: 18px; height: 18px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 40px; text-align: center; }

/* spinner / boot */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; min-height: 50vh; }

/* ---------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-2); background: var(--surface); color: var(--text-2);
  font: 600 13.5px/1 var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05); transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: #b9c0cb; }
.btn:focus-visible, .icon-btn:focus-visible, .nav a:focus-visible, .nav-btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary-ring); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: #912018; }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.link { background: none; border: 0; box-shadow: none; color: var(--primary); padding: 0 4px; height: auto; font-weight: 600; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; }
.btn.xs { height: 26px; padding: 0 9px; font-size: 12px; gap: 5px; border-radius: 6px; }
.btn.xs .ic { width: 14px; height: 14px; }
.btn.block { display: flex; width: 100%; }
.btn .ic { width: 17px; height: 17px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.bordered { border-color: var(--border-2); background: var(--surface); }
.icon-btn.sm { width: 30px; height: 30px; }
.btn-group { display: inline-flex; }
.btn-group .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 0 9px; border-left-color: rgba(255, 255, 255, .35); }

/* ---------------------------------------------------------- forms */
.f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.f > span:first-child, .f-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.f .hint { font-size: 12px; color: var(--muted); }
.req::after { content: " *"; color: var(--bad); }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=month], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-width: 0; height: 38px; padding: 0 11px; border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 400 14px/1.4 var(--font); transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
select { padding-right: 30px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; background-size: 16px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
input.upper { text-transform: uppercase; }
input.mono, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .02em; }
.invalid, input.invalid, select.invalid, textarea.invalid { border-color: var(--bad) !important; box-shadow: 0 0 0 3px rgba(180, 35, 24, .12) !important; }
.field-err { font-size: 12px; color: var(--bad); font-weight: 500; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; color: var(--text-2); user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.ok-text { color: var(--good); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 13px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-ring); }

/* ---------------------------------------------------------- layout */
.shell { display: flex; min-height: 100vh; }
.side {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 14px; z-index: 30; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; text-decoration: none !important; }
.brand-mark, .login-mark {
  width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #1d4ed8, #1f3a5f); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 14px; letter-spacing: .02em; flex: none;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; color: var(--text); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-btn {
  display: flex; align-items: center; gap: 11px; height: 38px; padding: 0 11px; border-radius: var(--radius-sm); color: var(--text-2);
  font-weight: 550; text-decoration: none !important; border: 0; background: none; font: 550 14px var(--font); cursor: pointer; width: 100%; text-align: left;
}
.nav a .ic, .nav-btn .ic { color: var(--faint); }
.nav a:hover, .nav-btn:hover { background: var(--surface-3); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a.active .ic { color: var(--primary); }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }
.side-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; }
.main { flex: 1; min-width: 0; margin-left: var(--side-w); display: flex; flex-direction: column; }
.topbar { display: none; }
.content { flex: 1; padding: 26px 30px 60px; max-width: 1440px; width: 100%; margin: 0 auto; outline: none; }
.side-scrim { display: none; }

@media (max-width: 960px) {
  .side { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.side-open .side { transform: none; }
  body.side-open .side-scrim { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 25; }
  .main { margin-left: 0; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: 8px 14px; }
  .topbar-title { font-weight: 700; flex: 1; }
  .content { padding: 18px 16px 70px; }
}

/* ---------------------------------------------------------- page bits */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.back .ic { width: 16px; height: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { font-size: 15px; }
.card-body { padding: 18px 20px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px; border: 1px solid; margin-bottom: 16px; flex-wrap: wrap; }
.banner .ic { width: 20px; height: 20px; }
.banner .grow { flex: 1; min-width: 200px; }
.banner.info { background: var(--info-soft); border-color: var(--info-line); color: #194185; }
.banner.warn { background: var(--warn-soft); border-color: var(--warn-line); color: #93370d; }
.banner.bad { background: var(--bad-soft); border-color: var(--bad-line); color: #912018; }
.banner.good { background: var(--good-soft); border-color: var(--good-line); color: #05603a; }

/* badges: status always = dot + text, never color alone */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: var(--good-line); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }
.badge.gray { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 11.5px; font-weight: 700; background: var(--surface-3); color: var(--text-2); letter-spacing: .02em; }
.tag.b2b { background: #eef3ff; color: #1e40af; }
.tag.b2c { background: #f4f3ff; color: #5925dc; }
.tag.export { background: #ecfdf3; color: #05603a; }

/* ---------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover td { background: #f8faff; }
.tbl .r { text-align: right; }
.tbl .strong { font-weight: 600; color: var(--text); }
.tbl .sub { font-size: 12px; color: var(--muted); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border); }
.tbl.compact td, .tbl.compact th { padding: 8px 12px; }
.tbl.nowrap-cells td { white-space: nowrap; }
.tbl.nowrap-cells td:first-child { white-space: normal; min-width: 220px; }
.cell-actions { width: 1%; white-space: nowrap; text-align: right; }

@media (max-width: 760px) {
  .tbl.responsive thead { display: none; }
  .tbl.responsive, .tbl.responsive tbody, .tbl.responsive tr, .tbl.responsive td { display: block; width: 100%; }
  .tbl.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--border); position: relative; }
  .tbl.responsive td { padding: 2px 0; border: 0; text-align: left !important; }
  .tbl.responsive td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: 12px; }
  .tbl.responsive td.cell-actions { position: absolute; top: 8px; right: 8px; width: auto; }
  .tbl.responsive tfoot { display: block; }
}

.empty-state { text-align: center; padding: 56px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--surface-3); display: grid; place-items: center; color: var(--muted); }
.empty-icon .ic { width: 24px; height: 24px; }

/* ---------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a, .tabs button { display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; font-weight: 600; font-size: 13.5px; color: var(--muted); border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; text-decoration: none !important; font-family: var(--font); }
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { background: var(--surface-3); color: var(--text-2); border-radius: 999px; padding: 0 7px; font-size: 11.5px; line-height: 18px; }
.tabs .active .count { background: var(--primary-soft); color: var(--primary); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .f { flex: 0 1 auto; }
.filters .grow { flex: 1 1 240px; }
.search-input { position: relative; }
.search-input .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search-input input { padding-left: 36px; }
.sumline { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.sumline b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .kpis { grid-template-columns: minmax(0, 1fr); } }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 550; }
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; color: var(--text); line-height: 1.2; }
.kpi-hero .kpi-value { font-size: 34px; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }

/* chart */
.chart { position: relative; padding: 8px 4px 0; }
.chart svg { display: block; width: 100%; height: 210px; overflow: visible; }
.chart .grid line { stroke: #e9ebef; stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar { fill: #9db7f5; transition: fill .12s; pointer-events: none; }
.chart text { pointer-events: none; }
.chart .bar.current { fill: var(--primary); }
.chart .bar-hit { fill: transparent; cursor: default; }
.chart .bar-hit:hover + .bar, .chart .bar.hover { fill: #5b84ea; }
.chart .bar.current.hover { fill: var(--primary-2); }
.chart-tip { position: absolute; pointer-events: none; background: #101828; color: #fff; font-size: 12px; padding: 7px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -100%); box-shadow: var(--shadow-lg); z-index: 5; }
.chart-tip b { display: block; font-size: 13px; }
details.table-view { margin-top: 8px; }
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 4px 0; }

/* ---------------------------------------------------------- modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 60; overflow-y: auto; animation: fade .12s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; display: flex; flex-direction: column; max-height: none; }
.modal.wide { max-width: 720px; }
.modal.xwide { max-width: 960px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 6px 22px; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 10px 22px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); flex-wrap: wrap; background: var(--surface-2); border-radius: 0 0 14px 14px; }
.confirm-text { color: var(--text-2); line-height: 1.6; }
.confirm-text p + p { margin-top: 8px; }

/* popup menu */
.popmenu { position: fixed; z-index: 70; min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px; }
.popmenu button { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; background: none; border-radius: 7px; font: 500 13.5px var(--font); color: var(--text-2); cursor: pointer; text-align: left; }
.popmenu button:hover:not([disabled]), .popmenu button:focus-visible { background: var(--surface-3); outline: none; color: var(--text); }
.popmenu button.danger { color: var(--bad); }
.popmenu button.danger:hover { background: var(--bad-soft); }
.popmenu button[disabled] { opacity: .45; cursor: not-allowed; }
.popmenu .ic { width: 16px; height: 16px; color: inherit; opacity: .85; }
.popmenu-sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* toasts */
.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 80; max-width: min(420px, calc(100vw - 32px)); pointer-events: none; }
@media (max-width: 960px) { .toasts { top: 62px; left: 16px; right: 16px; align-items: center; max-width: none; } }
.toast { display: flex; align-items: center; gap: 10px; background: #101828; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; animation: rise .18s ease; }
.toast .ic { width: 18px; height: 18px; }
.toast-ok .ic { color: #75e0a7; }
.toast-bad { background: #7a271a; }
.toast-warn .ic { color: #fec84b; }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, #dfe8ff, transparent), radial-gradient(900px 500px at 110% 110%, #e3ecf7, transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 30px 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 21px; }
.login-mark { width: 46px; height: 46px; font-size: 17px; border-radius: 13px; }
.login-error { background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad-line); padding: 9px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; }
.login-foot { font-size: 12px; text-align: center; }

/* ---------------------------------------------------------- invoice paper host */
.paper-host { position: relative; width: 100%; overflow: hidden; }
.paper-scale { transform-origin: top left; }
.paper-scale .iv-paper { box-shadow: 0 1px 4px rgba(16, 24, 40, .12), 0 8px 24px rgba(16, 24, 40, .08); margin: 0; }
.paper-frame { background: #e9edf2; border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); }

/* ---------------------------------------------------------- editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 560px); gap: 22px; align-items: start; }
.editor-form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.editor-preview { position: sticky; top: 16px; }
.editor-preview .paper-frame { max-height: calc(100vh - 110px); overflow-y: auto; }
.preview-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.preview-toggle { display: none; }
@media (max-width: 1280px) {
  .preview-toggle { display: inline-flex; }
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor-preview { position: static; display: none; }
  .editor.show-preview .editor-preview { display: block; }
}
.sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.sec-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sec-head h2 { font-size: 15px; display: flex; align-items: center; gap: 9px; }
.sec-num { width: 22px; height: 22px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.sec-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.taxline { display: flex; align-items: center; gap: 10px; padding: 10px 13px; border-radius: 9px; background: var(--surface-2); border: 1px dashed var(--border-2); font-size: 13px; color: var(--text-2); flex-wrap: wrap; }
.taxline b { color: var(--text); }
.gst-hint { font-size: 12.5px; }

.cust-pick { position: relative; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 15; max-height: 300px; overflow-y: auto; padding: 4px; }
.suggest button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left; font-family: var(--font); }
.suggest button:hover, .suggest button.hl { background: var(--primary-soft); }
.suggest .s-name { font-weight: 600; color: var(--text); font-size: 13.5px; }
.suggest .s-sub { font-size: 12px; color: var(--muted); }

.items { display: flex; flex-direction: column; gap: 10px; container-type: inline-size; }
.item { padding: 8px 12px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); min-width: 0; }
.item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.item-num { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.item-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 10px 8px; align-items: end; }
.item-grid .f-desc { grid-column: span 9; }
.item-grid .f-sac { grid-column: span 3; }
.item-grid .f-qty { grid-column: span 2; }
.item-grid .f-unit { grid-column: span 2; }
.item-grid .f-rate { grid-column: span 3; }
.item-grid .f-gst { grid-column: span 2; }
.item-grid .f-amt { grid-column: span 3; }
@container (min-width: 820px) {
  .item-grid { grid-template-columns: minmax(0, 3.2fr) minmax(0, 1.1fr) minmax(0, .8fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, .9fr) minmax(0, 1.3fr); }
  .item-grid > .f { grid-column: auto !important; }
}
@container (max-width: 440px) {
  .item-grid .f-desc { grid-column: span 12; }
  .item-grid .f-sac, .item-grid .f-rate, .item-grid .f-gst { grid-column: span 6; }
  .item-grid .f-qty, .item-grid .f-unit { grid-column: span 3; }
  .item-grid .f-amt { grid-column: span 12; }
}
.item-grid .f > span:first-child { font-size: 11.5px; }
.item-grid input[list]::-webkit-calendar-picker-indicator { display: none !important; }
.item-grid input, .item-grid select { height: 36px; font-size: 13.5px; padding: 0 9px; }
.item-grid select { padding-right: 26px; background-position: right 6px center; }
.item-amt { height: 36px; display: flex; align-items: center; justify-content: flex-end; font-weight: 650; font-variant-numeric: tabular-nums; padding: 0 4px; white-space: nowrap; }
.item-extra { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; align-items: flex-start; }
.item-extra .f { flex: 1 1 260px; }
.item-extra textarea { min-height: 56px; font-size: 13px; }
.item-extra .disc { display: flex; gap: 6px; align-items: flex-end; flex: 0 1 260px; }
.item-extra .disc input { width: 110px; }
.item-extra .disc select { width: 90px; }
.totals { margin-left: auto; width: min(100%, 360px); display: flex; flex-direction: column; }
.incl-check { align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-weight: 400; }
.incl-check input { margin-top: 2px; }
.incl-check b { color: var(--text); }

/* signature pad */
.sigpad-wrap { position: relative; border: 1px dashed var(--border-2); border-radius: 10px; background: #fff; margin: 12px 0 10px; overflow: hidden; }
.sigpad { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.sigpad-line { position: absolute; left: 7%; right: 7%; bottom: 54px; border-bottom: 1.5px solid #cfd5de; pointer-events: none; }
.sigpad-x { position: absolute; left: 7%; bottom: 60px; font-size: 18px; color: #b7c0cc; pointer-events: none; }
.sigpad-hint { position: absolute; left: 7%; bottom: 30px; font-size: 12px; color: var(--faint); pointer-events: none; }
.totals .t-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 13.5px; color: var(--text-2); }
.totals .t-row span:last-child { font-variant-numeric: tabular-nums; }
.totals .t-grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 700; color: var(--text); }
.err-box { border: 1px solid var(--bad-line); background: var(--bad-soft); color: #912018; border-radius: 10px; padding: 12px 16px; }
.err-box ul { margin: 6px 0 0; padding-left: 18px; }
.err-box li { margin: 2px 0; }
.sticky-actions { position: sticky; bottom: 0; z-index: 12; display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; padding: 12px 16px; background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 -4px 18px rgba(16, 24, 40, .08); }
.sticky-actions .grand { margin-right: auto; font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.sticky-actions .grand small { display: block; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.num-pill { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px dashed var(--border-2); background: var(--surface-2); font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- invoice page */
.inv-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 1180px) { .inv-layout { grid-template-columns: minmax(0, 1fr); } }
.inv-side { display: flex; flex-direction: column; gap: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 550; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.tl-ic { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.tl-ic .ic { width: 15px; height: 15px; }
.tl-ic.blue { background: var(--info-soft); color: var(--info); }
.tl-ic.green { background: var(--good-soft); color: var(--good); }
.tl-ic.red { background: var(--bad-soft); color: var(--bad); }
.tl-ic.amber { background: var(--warn-soft); color: var(--warn); }
.tl-title { font-weight: 600; font-size: 13.5px; }
.tl-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.changes { margin: 6px 0 0; padding: 0; list-style: none; font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.changes li { display: block; border: 0; padding: 0; color: var(--text-2); overflow-wrap: anywhere; }
.changes .from { color: var(--bad); text-decoration: line-through; text-decoration-color: rgba(180, 35, 24, .45); }
.changes .to { color: var(--good); font-weight: 600; }
.changes .fld { color: var(--muted); }

/* ---------------------------------------------------------- calendar */
.cal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.cal-title { font-size: 18px; font-weight: 700; min-width: 170px; }
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .cal-layout { grid-template-columns: minmax(0, 1fr); } }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow { padding: 9px 10px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.cal-day { min-height: 104px; padding: 7px 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; display: flex; flex-direction: column; gap: 4px; background: var(--surface); border-top: 0; border-left: 0; text-align: left; font-family: var(--font); min-width: 0; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day:hover { background: #f8faff; }
.cal-day.out { background: var(--surface-2); }
.cal-day.out .cal-num { color: var(--faint); }
.cal-day.sel { box-shadow: inset 0 0 0 2px var(--primary); }
.cal-num { font-size: 12.5px; font-weight: 600; color: var(--text-2); width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .cal-num { background: var(--primary); color: #fff; }
.cal-chip { font-size: 11.5px; font-weight: 600; border-radius: 6px; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.cal-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.cal-chip.billed { background: var(--info-soft); color: #1849a9; }
.cal-chip.due { background: var(--warn-soft); color: var(--warn); }
.cal-chip.overdue { background: var(--bad-soft); color: var(--bad); }
.cal-amt { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding-left: 2px; }
@media (max-width: 640px) {
  .cal-day { min-height: 62px; padding: 4px; }
  .cal-chip { font-size: 10px; padding: 1px 4px; }
  .cal-chip::before { display: none; }
  .cal-amt { display: none; }
  .cal-dow { padding: 6px 4px; font-size: 11px; }
}
.day-list { display: flex; flex-direction: column; }
.day-item { display: flex; justify-content: space-between; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border); text-decoration: none !important; color: inherit; }
.day-item:last-child { border-bottom: 0; }
.day-item:hover .di-no { color: var(--primary); }
.di-no { font-weight: 650; color: var(--text); }
.di-sub { font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------- settings */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 900px) { .settings-layout { grid-template-columns: minmax(0, 1fr); } }
.settings-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 16px; }
@media (max-width: 900px) { .settings-nav { position: static; flex-direction: row; overflow-x: auto; } }
.settings-nav button { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; border-radius: 8px; border: 0; background: none; font: 550 13.5px var(--font); color: var(--text-2); cursor: pointer; text-align: left; white-space: nowrap; }
.settings-nav button:hover { background: var(--surface-3); }
.settings-nav button.active { background: var(--primary-soft); color: var(--primary); }
.settings-nav .ic { width: 17px; height: 17px; }
.brand-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.brand-img { width: 180px; height: 96px; border: 1px dashed var(--border-2); border-radius: 10px; display: grid; place-items: center; background: repeating-conic-gradient(#f2f4f7 0 25%, #fff 0 50%) 0 0 / 16px 16px; overflow: hidden; }
.brand-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.color-input { width: 56px; height: 38px; padding: 3px; border: 1px solid var(--border-2); border-radius: 8px; background: var(--surface); cursor: pointer; }
.info-list { margin: 0; padding-left: 18px; color: var(--text-2); display: flex; flex-direction: column; gap: 5px; }

/* report */
.report-sec + .report-sec { margin-top: 16px; }
.pill-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-nav button { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-2); background: var(--surface); font: 600 12.5px var(--font); color: var(--text-2); cursor: pointer; }
.pill-nav button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.gap-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* ---------------------------------------------------------- print */
#print-root { display: none; }
@media print {
  /* Zero page margin leaves the browser no room for its own header/footer (date, title, URL, page no.).
     The 10mm margin is rebuilt inside the page: a frame table whose thead/tfoot spacers repeat on every page. */
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; margin: 0 !important; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  #print-root .print-frame { width: 100%; border-collapse: collapse; border: 0; }
  #print-root .print-frame > thead { display: table-header-group; }
  #print-root .print-frame > tfoot { display: table-footer-group; }
  #print-root .print-frame > * > tr > td { padding: 0; border: 0; vertical-align: top; }
  #print-root .print-gap { height: 10mm; }
  #print-root .iv-paper { width: auto; min-height: 0; padding: 0 10mm; margin: 0; box-shadow: none; overflow: visible; }
  #print-root .print-page + .print-page { break-before: page; page-break-before: always; }
}
