/* Ali Books */
:root {
  --brand: #8f1d21;
  --brand-dark: #6e1418;
  --brand-soft: #f6e7e4;
  --ink: #1f1b18;
  --muted: #6f6861;
  --line: #e7e1d9;
  --line-strong: #d4ccc2;
  --bg: #f6f3ee;
  --card: #ffffff;
  --ok: #1d7146;
  --ok-soft: #e4f2ea;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 27, 24, .06), 0 4px 14px rgba(31, 27, 24, .04);
  --nav-h: 64px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button { font: inherit; color: inherit; }
small { font-size: 13px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.center { text-align: center; }
.block { display: block; }
.pad { padding: 12px; }
.lead { font-size: 17px; margin: 0 0 8px; }

/* ------------------------------------------------------------------ shell */
#top {
  position: sticky; top: 0; z-index: 20; height: var(--top-h);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 12px; padding-top: env(safe-area-inset-top, 0px);
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 14px; letter-spacing: .5px; flex: none;
}
.logo.big { width: 56px; height: 56px; border-radius: 14px; font-size: 22px; }
.top-right { display: flex; gap: 6px; align-items: center; flex: none; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 10px;
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.user { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.chip.sync.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.sync.busy { color: var(--muted); }
.chip.sync.wait, .chip.sync.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.chip.sync.off { color: var(--muted); background: #eee; border-color: transparent; }
.chip.sync.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }

#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
}
#nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
#nav a .ico { font-size: 18px; line-height: 1; height: 20px; font-weight: 800; }
#nav a.on { color: var(--brand); }
#nav a:hover { text-decoration: none; }
#view { padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 980px; margin: 0 auto; }

@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: var(--top-h) 1fr; min-height: 100vh; }
  #top { grid-column: 1 / -1; }
  #nav {
    position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); padding: 14px 10px;
    display: flex; flex-direction: column; gap: 4px; border-top: 0; border-right: 1px solid var(--line);
  }
  #nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 11px 14px; border-radius: 10px; }
  #nav a .ico { width: 24px; text-align: center; height: auto; }
  #nav a.on { background: var(--brand-soft); }
  #view { padding: 22px 28px 48px; width: 100%; }
}

/* ------------------------------------------------------------------ pages */
.page-head { display: flex; align-items: center; gap: 8px; margin: 2px 0 14px; min-height: 40px; }
.page-head h1 { font-size: 22px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.page-actions { display: flex; gap: 8px; flex: none; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow);
}
.card-title { font-size: 15px; margin: 0 0 10px; color: var(--muted); text-transform: none; font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; margin: 0; }
.who { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.note { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.big { font-weight: 700; font-size: 17px; }
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stats.small { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat {
  display: flex; flex-direction: column; gap: 2px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; color: var(--ink); box-shadow: var(--shadow); min-width: 0;
}
a.stat:hover { text-decoration: none; border-color: var(--line-strong); }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 20px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat small { color: var(--muted); }
.stat.hero { background: var(--brand); border-color: var(--brand); color: #fff; }
.stat.hero .stat-label, .stat.hero small { color: rgba(255, 255, 255, .8); }
.stat.warnish .stat-value { color: var(--bad); }

/* quick actions */
.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .quick { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { .quick { grid-template-columns: repeat(5, 1fr); } }
.quick-btn {
  display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 64px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px;
  color: var(--ink); box-shadow: var(--shadow);
}
.quick-btn b { font-size: 16px; }
.quick-btn small { color: var(--muted); }
.quick-btn:hover { text-decoration: none; border-color: var(--line-strong); }
.quick-btn.main { background: var(--brand); border-color: var(--brand); color: #fff; grid-column: span 2; }
.quick-btn.main small { color: rgba(255, 255, 255, .8); }
@media (min-width: 640px) { .quick-btn.main { grid-column: span 1; } }

/* lists */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow); }
.card .list { box-shadow: none; margin-bottom: 8px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); color: var(--ink); min-height: 56px; cursor: default;
}
.row:last-child { border-bottom: 0; }
a.row, .row[onclick], div.row:has(> .row-main[href]) { cursor: pointer; }
a.row:hover { background: #faf8f5; text-decoration: none; }
.row.dim { opacity: .55; }
.row-main { display: flex; flex-direction: column; min-width: 0; color: var(--ink); }
a.row-main:hover { text-decoration: none; }
.row-main b { font-weight: 600; overflow-wrap: anywhere; }
.row-main small { color: var(--muted); }
.row-right { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.row-right small { color: var(--muted); }
.nav-list .row { min-height: 60px; }

.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 6px 12px; margin: 0 0 6px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; margin: 6px 0; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl tfoot td { border-bottom: 0; }
.tbl tr.big td { font-weight: 700; font-size: 16px; }
.tbl.count .input { max-width: 110px; min-height: 40px; margin-left: auto; }
.card > .tbl, .page > .tbl { background: var(--card); }
.page > .tbl { border: 1px solid var(--line); border-radius: var(--radius); display: table; }
@media (max-width: 520px) { .tbl { font-size: 14px; } .tbl td, .tbl th { padding-left: 4px; padding-right: 4px; } }

/* ------------------------------------------------------------------ forms */
.field { display: block; margin: 0 0 12px; min-width: 0; }
.label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 5px; }
.hint { display: block; color: var(--muted); margin-top: 4px; }
.input {
  display: block; width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; outline: none; appearance: none; -webkit-appearance: none;
}
textarea.input { min-height: 60px; resize: vertical; }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.input:focus, .btn:focus-visible, .chooser:focus-visible, .seg button:focus-visible { outline: 3px solid rgba(143, 29, 33, .25); border-color: var(--brand); }
.input:disabled { background: #f1eee9; color: var(--muted); }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input.search { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
.chooser { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; cursor: pointer; }
.chooser span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chooser .chev { color: var(--muted); flex: none; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.seg button {
  flex: 1 1 auto; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: #fff; font-weight: 600; cursor: pointer; font-size: 15px;
}
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.paybox .field { margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: #fff; color: var(--ink);
  font-weight: 650; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { background: transparent; color: var(--bad); border-color: #e7b9b4; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.big { min-height: 52px; font-size: 17px; padding: 0 24px; }
.btn.block { width: 100%; }
.btn:disabled, .btn.busy { opacity: .55; cursor: progress; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 40px; height: 40px; border: 0; background: transparent;
  border-radius: 10px; cursor: pointer; font-size: 20px; color: var(--muted);
}
.icon-btn:hover { background: #f0ece6; }
.icon-btn.back { font-size: 30px; color: var(--ink); margin-left: -8px; }
.icon-btn.del { font-size: 16px; }
.linkish { border: 0; background: none; color: var(--brand); text-decoration: underline; cursor: pointer; padding: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin: 6px 0 16px; }
.form-actions.wrap { flex-wrap: wrap; justify-content: flex-start; }
@media (max-width: 640px) { .form-actions:not(.wrap) .btn.big { width: 100%; } }

/* bill lines */
.lines { margin-bottom: 8px; }
.line { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.line:first-child { padding-top: 0; }
.line-item { margin-bottom: 8px; }
.line-item small { display: block; margin-top: 4px; }
.line-nums { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
.mini { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mini > span { font-size: 12px; font-weight: 700; color: var(--muted); }
.mini.amt b { min-height: 46px; display: flex; align-items: center; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.part-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.totals { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.trow { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.trow.big { font-size: 20px; font-weight: 700; }
.trow.big.bad { color: var(--bad); }
.cust-info { margin: -6px 0 10px; }
.cut-sum .trow.big { color: var(--brand); }

.monthbar { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; margin-bottom: 12px; }
.monthbar b { font-size: 17px; }
.monthbar .icon-btn { font-size: 26px; color: var(--ink); }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #eee; }

/* ------------------------------------------------------------------ sheets */
.sheet-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(31, 27, 24, .45);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
.sheet-back.closing { opacity: 0; transition: opacity .15s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--card); border-radius: 18px 18px 0 0; padding-bottom: var(--safe-b); animation: up .18s ease;
}
@media (min-width: 640px) { .sheet-back { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 18px; }
.sheet-head h2 { font-size: 19px; }
.sheet-body { padding: 4px 18px 8px; overflow-y: auto; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 10px 18px 16px; border-top: 1px solid var(--line); }
.sheet-actions .btn { flex: 1; }
@media (min-width: 640px) { .sheet-actions .btn { flex: none; } }
.pick-list { margin-top: 10px; }
.pick-row {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; text-align: left;
  padding: 12px 10px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; min-height: 54px;
}
.pick-row:hover, .pick-row.on { background: var(--brand-soft); }
.pick-main { display: flex; flex-direction: column; min-width: 0; }
.pick-main b { font-weight: 600; }
.pick-main small { color: var(--muted); }
.pick-right { color: var(--muted); font-size: 14px; flex: none; font-variant-numeric: tabular-nums; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }

#toasts { pointer-events: none; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 14px); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 440px); }
.toast { background: #2a2420; color: #fff; padding: 12px 14px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); transition: opacity .4s, transform .4s; }
.toast.ok { background: var(--ok); }
.toast.warn { background: #7a4a00; }
.toast.bad { background: var(--bad); }
.toast.gone { opacity: 0; transform: translateY(8px); }
@media (min-width: 900px) { #toasts { bottom: 24px; } }
#update-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 70; background: var(--ink); color: #fff; padding: 10px 14px; display: flex; gap: 10px; align-items: center; justify-content: center; }

/* ------------------------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px; box-shadow: var(--shadow); }
.login-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 8px; }
.login-logo h1 { font-size: 24px; }
.login-card h2 { font-size: 19px; margin: 12px 0 4px; }
.pin-msg { text-align: center; margin: 14px 0 8px; font-weight: 600; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin-bottom: 18px; min-height: 16px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); }
.pin-dots span.on { background: var(--brand); border-color: var(--brand); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.key { height: 62px; border-radius: 16px; border: 1px solid var(--line); background: #faf8f5; font-size: 24px; font-weight: 600; cursor: pointer; }
.key:active { background: var(--brand-soft); }
.key.ok { background: var(--brand); color: #fff; border-color: var(--brand); font-size: 18px; }
