/* THE ANY 168 — invoice system
   Palette and proportions follow the original Invoice System concept. */

:root {
  --bg:        #f4f5fb;
  --ink:       #1a1d2e;
  --ink-2:     #4a4f6e;
  --muted:     #7a7f9e;
  --muted-2:   #9aa0c0;
  --line:      #e4e6f2;
  --line-2:    #f0f1f8;
  --card:      #ffffff;
  --navy:      #14172b;
  --navy-2:    #565d85;
  --navy-3:    #8b91b8;
  --primary:   #3b4bd8;
  --primary-d: #2a36a8;
  --primary-l: #eef0fb;
  --green:     #0e8f62;
  --orange:    #d8722b;
  --red:       #d84b4b;
  --mono:      'Space Grotesk', ui-monospace, sans-serif;
  --sans:      'Kantumruy Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius:    14px;
}

* { box-sizing: border-box; }

/* Class rules below set `display`, which would otherwise beat the UA's
   `[hidden] { display: none }` and leave the splash covering the app. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-d); }
input, select, button, textarea { font-family: inherit; font-size: 14px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── boot / login ───────────────────────────────────────────────────────── */

.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--navy); z-index: 100;
}
.boot-mark {
  font-family: var(--mono); font-weight: 700; font-size: 34px; color: #fff;
  letter-spacing: .08em; animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #23294a 0%, var(--navy) 60%);
  padding: 24px; z-index: 90;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card);
  border-radius: 18px; padding: 30px 28px 26px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
  display: flex; flex-direction: column; gap: 16px;
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 4px; }
.login-logo {
  width: 46px; height: 46px; flex: none; border-radius: 12px;
  background: var(--navy); color: #fff; display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: 16px; letter-spacing: .04em;
}
.login-name { font-family: var(--mono); font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.login-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.login-error {
  background: #fdecec; color: #a62b2b; border-radius: 9px;
  padding: 9px 12px; font-size: 13px;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid #d6d9ea; border-radius: 8px; padding: 9px 11px;
  background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus,
.cell:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,75,216,.12);
}

/* ── shell ──────────────────────────────────────────────────────────────── */

.shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 230px; flex: none; background: var(--navy);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 4px;
  z-index: 30;
}
.brand { padding: 8px 12px 22px; }
.brand-name {
  font-family: var(--mono); font-weight: 700; font-size: 17px;
  color: #fff; letter-spacing: .02em; word-break: break-word;
}
.brand-sub { font-size: 12.5px; color: var(--navy-3); margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  padding: 10px 12px; border-radius: 9px; cursor: pointer;
  color: var(--muted-2); font-size: 14px; font-weight: 500;
  display: flex; flex-direction: column; gap: 1px;
  border: none; background: transparent; text-align: left; width: 100%;
}
.nav-item:hover { filter: brightness(1.35); background: rgba(255,255,255,.05); }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 700; }
.nav-item small { font-size: 11.5px; opacity: .65; font-weight: 400; }

.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid #242844; }
.who { font-size: 12px; color: var(--navy-2); line-height: 1.5; margin-bottom: 6px; }
.who b { color: #c9cde8; font-weight: 600; }
.btn-link {
  background: none; border: none; color: var(--navy-3); cursor: pointer;
  padding: 0; font-size: 12.5px;
}
.btn-link:hover { color: #fff; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 26px;
  border-bottom: 1px solid var(--line); background: #fff; flex: none;
}
.topbar-titles { flex: 1; min-width: 0; }
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-sub { font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.view { flex: 1; overflow: auto; padding: 24px 26px 40px; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.scrim { display: none; }
.only-mobile { display: none; }

/* ── buttons ────────────────────────────────────────────────────────────── */

.btn {
  border-radius: 9px; padding: 9px 17px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; border: 1px solid #d6d9ea; background: #fff; color: var(--ink-2);
  white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: #f6f7fd; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-l); }
.btn-danger { color: var(--red); border-color: #f0cdcd; }
.btn-danger:hover { background: #fdecec; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 9px;
  width: 36px; height: 36px; cursor: pointer; font-size: 16px; color: var(--ink-2);
}

/* ── cards, tables, chips ───────────────────────────────────────────────── */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px;
}
.card-tight { padding: 0; overflow: hidden; }
.card-title { font-weight: 700; font-size: 14.5px; margin-bottom: 14px; }

.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px 19px; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-value { font-family: var(--mono); font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi-sub { font-size: 12px; color: var(--muted-2); margin-top: 2px; }

.split { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; align-items: start; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid #d6d9ea; background: #fff; color: var(--ink-2);
  border-radius: 99px; padding: 7px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:hover { background: #f6f7fd; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.table { width: 100%; }
.thead, .trow, .tfoot {
  display: flex; gap: 12px; align-items: center; padding: 12px 18px;
}
.thead {
  background: #f8f9fd; border-bottom: 1px solid var(--line);
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.trow { border-bottom: 1px solid var(--line-2); font-size: 14px; }
.trow.clickable { cursor: pointer; }
.trow.clickable:hover { background: #f6f7fd; }
.tfoot { background: #f8f9fd; font-size: 14px; }
.tnum { text-align: right; font-family: var(--mono); }
.tgrow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-no { font-family: var(--mono); font-weight: 600; color: var(--primary); }
.pos { color: var(--green); font-weight: 600; }
.dim { color: var(--muted-2); }
.soft { color: var(--muted); }

.tag {
  display: inline-block; border-radius: 99px; padding: 2px 9px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tag-paid   { background: #e3f6ee; color: var(--green); }
.tag-unpaid { background: #fdf0e4; color: var(--orange); }
.tag-void   { background: #f1f1f5; color: var(--muted); }
.tag-quotation { background: var(--primary-l); color: var(--primary); }

.empty { padding: 44px 20px; text-align: center; color: var(--muted-2); font-size: 14px; }

/* ── revenue chart ──────────────────────────────────────────────────────── */

.bars { display: flex; align-items: flex-end; gap: 14px; height: 168px; padding: 0 4px; }
.bar-col {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; height: 100%; justify-content: flex-end;
}
.bar-amt { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.bar {
  width: 100%; max-width: 46px; background: #dfe2f3;
  border-radius: 6px 6px 2px 2px; transition: background .15s, height .3s;
  min-height: 4px;
}
.bar-col:hover .bar { background: #c6ccec; }
.bar-col.active .bar { background: var(--primary); }
.bar-label { font-size: 12px; color: var(--muted-2); }
.bar-col.active .bar-label { color: var(--primary); font-weight: 700; }

/* ── invoice editor ─────────────────────────────────────────────────────── */

.editor { max-width: 980px; }
.editor-head { display: grid; grid-template-columns: 110px 1fr 1fr 155px 185px; gap: 12px; }
.lines-head, .line {
  display: flex; gap: 8px; align-items: center;
}
.lines-head {
  margin-top: 22px; padding: 0 2px 2px; font-size: 11.5px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.line { margin-top: 8px; }
.line .idx { width: 28px; font-family: var(--mono); color: var(--muted-2); font-size: 13px; flex: none; }
.cell {
  border: 1px solid #d6d9ea; border-radius: 8px; padding: 8px 10px;
  background: #fff; color: var(--ink); min-width: 0;
}
.cell.desc { flex: 1; min-width: 90px; }
.cell.qty { width: 66px; flex: none; font-family: var(--mono); }
.cell.price { width: 96px; flex: none; font-family: var(--mono); }
.cell.disc { width: 86px; flex: none; font-family: var(--mono); color: var(--orange); }
.cell.cost { width: 96px; flex: none; font-family: var(--mono); color: var(--muted); border-style: dashed; }
.line .total { width: 88px; flex: none; text-align: right; font-family: var(--mono); font-weight: 600; }
.line .kill {
  width: 26px; flex: none; text-align: center; color: #c4c8de; cursor: pointer;
  font-size: 17px; background: none; border: none; line-height: 1;
}
.line .kill:hover { color: var(--red); }
.h-desc { flex: 1; } .h-qty { width: 66px; } .h-price { width: 96px; }
.h-disc { width: 86px; } .h-cost { width: 96px; } .h-total { width: 88px; text-align: right; }
.h-idx { width: 28px; } .h-kill { width: 26px; }

.totals { width: 310px; display: flex; flex-direction: column; gap: 8px; margin-left: auto; margin-top: 20px; }
.totals .row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted-2); }
.totals .row.big { font-size: 14.5px; color: var(--ink); }
.totals .row.big b { font-family: var(--mono); font-size: 18px; }
.totals .row.income {
  color: var(--green); font-weight: 600;
  border-top: 1px solid var(--line); padding-top: 8px;
}
.editor-actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;
  border-top: 1px solid var(--line-2); padding-top: 17px;
}

.suggest {
  position: absolute; z-index: 40; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 30px rgba(20,23,43,.14);
  max-height: 260px; overflow: auto; min-width: 260px; padding: 4px;
}
.suggest button {
  display: flex; width: 100%; gap: 10px; align-items: center; text-align: left;
  background: none; border: none; padding: 8px 10px; border-radius: 7px; cursor: pointer;
}
.suggest button:hover, .suggest button.on { background: var(--primary-l); }
.suggest .s-desc { flex: 1; min-width: 0; }
.suggest .s-price { font-family: var(--mono); font-size: 13px; color: var(--muted); }

/* ── printable invoice ──────────────────────────────────────────────────── */

.print-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.print-bar { display: flex; gap: 10px; width: 100%; max-width: 680px; align-items: center; }

.sheet {
  width: 100%; max-width: 680px; background: #fff; border: 1px solid var(--line);
  border-radius: 4px; padding: 42px 46px; box-shadow: 0 10px 30px rgba(20,23,43,.08);
}
.sheet-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 20px;
  border-bottom: 3px solid var(--navy); padding-bottom: 16px;
}
.sheet-shop { font-family: var(--mono); font-weight: 700; font-size: 19px; }
.sheet-shop-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.sheet-kind { text-align: right; }
.sheet-kind .km { font-size: 21px; font-weight: 700; }
.sheet-kind .en { font-size: 12px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }
.sheet-kind .no { font-family: var(--mono); font-weight: 700; color: var(--primary); font-size: 16px; margin-top: 4px; }
.sheet-meta { display: flex; flex-wrap: wrap; gap: 10px 30px; padding: 15px 0; font-size: 13.5px; }
.sheet-meta .k { color: var(--muted-2); }
.sheet-items-head {
  display: flex; gap: 10px; padding: 9px 10px; background: var(--navy);
  color: #fff; font-size: 12px; font-weight: 600; border-radius: 4px;
}
.sheet-item {
  display: flex; gap: 10px; padding: 9px 10px;
  border-bottom: 1px solid var(--line-2); font-size: 13.5px;
}
.si-idx { width: 30px; color: var(--muted-2); font-family: var(--mono); }
.si-qty { width: 48px; text-align: right; font-family: var(--mono); }
.si-price { width: 86px; text-align: right; font-family: var(--mono); }
.si-total { width: 92px; text-align: right; font-family: var(--mono); font-weight: 600; }
.sheet-total-wrap { display: flex; justify-content: flex-end; margin-top: 16px; }
.sheet-total { width: 270px; }
.sheet-total .grand {
  display: flex; justify-content: space-between; font-size: 15px; font-weight: 700;
  background: var(--primary-l); border-radius: 6px; padding: 10px 12px;
}
.sheet-total .riel {
  display: flex; justify-content: space-between; font-size: 12.5px;
  color: var(--muted-2); padding: 7px 12px 0;
}
.sheet-sign {
  margin-top: 34px; display: flex; justify-content: space-between; gap: 24px;
  font-size: 12.5px; color: var(--muted);
}
.sheet-thanks { text-align: center; margin-top: 26px; font-size: 12px; color: var(--muted-2); }

/* ── misc layout helpers ────────────────────────────────────────────────── */

.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.toolbar .search { flex: 1 1 240px; min-width: 180px; max-width: 340px; }
.toolbar input, .toolbar select {
  border: 1px solid #d6d9ea; border-radius: 9px; padding: 8px 12px; background: #fff;
}
.toolbar input { width: 100%; }
.toolbar select { width: auto; min-width: 170px; flex: 0 0 auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.hint { font-size: 12.5px; color: var(--muted-2); line-height: 1.6; }
.mt { margin-top: 16px; }
.rowline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 13.5px; z-index: 200; box-shadow: 0 12px 30px rgba(0,0,0,.25); max-width: 90vw;
}
.toast.bad { background: #a62b2b; }

/* ── responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .editor-head { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.4);
  }
  .shell.menu-open .sidebar { transform: none; }
  .shell.menu-open .scrim {
    display: block; position: fixed; inset: 0; background: rgba(10,12,24,.5); z-index: 20;
  }
  .view { padding: 16px 14px 40px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  .topbar-titles { flex: 1 1 auto; min-width: 0; }
  .topbar-title { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-sub { display: none; }
  .topbar-actions { flex: 0 0 auto; }
  .sheet { padding: 26px 20px; }
  .thead { display: none; }
  .trow {
    display: flex; flex-wrap: wrap; gap: 3px 10px;
    padding: 12px 14px; align-items: baseline;
  }
  .trow > * { width: auto !important; text-align: left !important; flex: 0 0 auto; }
  .trow .tgrow { flex: 1 1 100%; }
  .trow .tnum { text-align: left; }
  /* Cost is the least useful figure on a phone; income and total stay. */
  .col-cost { display: none; }
  .tfoot { flex-wrap: wrap; }
  .line { flex-wrap: wrap; }
  .cell.desc { flex-basis: 100%; }
  .totals { width: 100%; }
  .editor-head { grid-template-columns: 1fr; }
}

/* ── print ──────────────────────────────────────────────────────────────── */

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .sidebar, .topbar, .print-bar, .toast, .scrim { display: none !important; }
  .shell, .main, .view { display: block; height: auto; overflow: visible; padding: 0; }
  .print-wrap { display: block; }
  .sheet {
    max-width: none; width: 100%; border: none; box-shadow: none;
    padding: 0; border-radius: 0;
  }
  .sheet-items-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-total .grand { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
