:root {
  --ink: #14241d;          /* deep ledger green-black */
  --ink-2: #1d332a;
  --paper: #f4f5f0;        /* counter-book paper */
  --card: #ffffff;
  --line: #dfe3da;
  --accent: #0e7a4b;       /* stamp green */
  --accent-soft: #e2f2e9;
  --money: #9a6b1f;        /* brass */
  --danger: #b3372c;
  --muted: #6b746c;
  --radius: 10px;
  --mono: "SF Mono", "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--paper); color: var(--ink); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--ink); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: #fafbf7; }
.num { font-family: var(--mono); text-align: right; white-space: nowrap; }

/* ---------- layout ---------- */
#app { display: none; height: 100vh; }
#app.on { display: grid; grid-template-columns: 216px 1fr; }
aside { background: var(--ink); color: #e8ede8; display: flex; flex-direction: column; padding: 18px 0; }
.logo { padding: 0 20px 16px; font-weight: 800; font-size: 17px; letter-spacing: .02em; }
.logo small { display: block; font-weight: 400; color: #9fb3a6; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
nav { flex: 1; overflow-y: auto; }
nav button { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: none; border: 0; color: #cfd9d0; padding: 10px 20px; border-left: 3px solid transparent; }
nav button:hover { background: var(--ink-2); color: #fff; }
nav button.active { background: var(--ink-2); color: #fff; border-left-color: var(--accent); }
nav .sep { margin: 10px 20px 4px; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: #7d8f83; }
.whoami { padding: 12px 20px 0; border-top: 1px solid var(--ink-2); font-size: 12px; color: #9fb3a6; }
.whoami b { color: #fff; display: block; }
.whoami button { margin-top: 8px; width: 100%; background: none; border: 1px solid #3b4f44; color: #cfd9d0; border-radius: 8px; padding: 6px; }

main { overflow-y: auto; padding: 24px 28px 60px; }
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.pagehead h2 { margin: 0; font-size: 21px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1000px) { .grid.c4, .grid.c3 { grid-template-columns: repeat(2, 1fr); } #app.on { grid-template-columns: 64px 1fr; } .logo, nav button span, .whoami, nav .sep { display: none; } }

/* ---------- widgets ---------- */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat.money .v { color: var(--accent); }
.stat.warn .v { color: var(--danger); }

.btn { background: var(--accent); border: 0; color: #fff; padding: 9px 16px; border-radius: 8px; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge.paid { background: var(--accent-soft); color: var(--accent); }
.badge.partial { background: #fdf1dc; color: var(--money); }
.badge.unpaid { background: #fbe4e1; color: var(--danger); }
.badge.quote { background: #e8eaf6; color: #3949ab; }
.badge.returned, .badge.converted { background: #eee; color: #666; }
.badge.open { background: #e0f2fe; color: #0369a1; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }

/* login */
#login { height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ink); }
#login .card { width: 340px; padding: 28px; }
#login h1 { margin: 0 0 2px; font-size: 22px; }
#login p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

/* modal */
#modal-back { position: fixed; inset: 0; background: rgba(10,20,15,.55); display: none; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; }
#modal-back.on { display: flex; }
#modal { background: #fff; border-radius: 12px; width: 620px; max-width: 100%; max-height: 86vh; overflow-y: auto; padding: 22px; }
#modal h3 { margin: 0 0 14px; }

/* POS */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.pos-items td { padding: 6px 8px; }
.pos-total { font-family: var(--mono); }
.pos-total .grand { font-size: 26px; font-weight: 800; color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); }

/* bar chart */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; position: relative; }
.bars .bar i { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-style: normal; font-size: 10.5px; color: var(--muted); }
.bars .bar b { position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: 10px; font-family: var(--mono); }

#toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; display: none; z-index: 99; max-width: 380px; }
#toast.err { background: var(--danger); }
.mt { margin-top: 12px; }

/* ================= mobile (≤768px): bottom navigation ================= */
#bottomnav, #more-back { display: none; }

@media (max-width: 768px) {
  #app.on { display: block; height: auto; min-height: 100vh; }
  aside { display: none; }

  main { padding: 14px 12px calc(76px + env(safe-area-inset-bottom)); }
  .pagehead h2 { font-size: 18px; }
  .grid.c4, .grid.c3, .grid.c2 { grid-template-columns: repeat(2, 1fr); }
  .stat .v { font-size: 19px; }

  /* wide tables scroll inside their card instead of breaking layout */
  .card { overflow-x: auto; }
  th, td { padding: 8px 8px; font-size: 13px; }

  /* billing screen stacks; totals stay visible */
  .pos { grid-template-columns: 1fr; }
  .pos > .card:last-child { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 5; box-shadow: 0 -4px 18px rgba(10,20,15,.12); }

  /* touch targets */
  .btn { padding: 11px 16px; }
  input, select, textarea { padding: 11px 12px; font-size: 16px; } /* 16px stops iOS zoom */
  #modal { width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0; }
  #modal-back { padding: 8vh 0 0; align-items: flex-end; }
  #toast { left: 12px; right: 12px; bottom: calc(74px + env(safe-area-inset-bottom)); max-width: none; }

  /* --- bottom nav bar --- */
  #bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--ink); padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 12px rgba(10,20,15,.25);
  }
  #bottomnav button {
    flex: 1; background: none; border: 0; color: #9fb3a6;
    padding: 8px 2px 9px; font-size: 10.5px; font-weight: 600;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
  }
  #bottomnav button i { font-style: normal; font-size: 19px; line-height: 1; }
  #bottomnav button.active { color: #fff; }
  #bottomnav button.active i { color: var(--accent-soft); }

  /* --- "More" slide-up sheet --- */
  #more-back.on { display: flex; position: fixed; inset: 0; z-index: 45;
    background: rgba(10,20,15,.55); align-items: flex-end; }
  #more-sheet { background: #fff; width: 100%; border-radius: 16px 16px 0 0;
    padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); }
  #more-sheet .mo-user { padding: 10px 6px 12px; border-bottom: 1px solid var(--line);
    margin-bottom: 6px; }
  #more-sheet .mo-user b { display: block; }
  #more-sheet .mo-user span { font-size: 12px; color: var(--muted); }
  #more-sheet button { display: block; width: 100%; text-align: left; background: none;
    border: 0; padding: 13px 6px; font-size: 15px; border-bottom: 1px solid var(--line); }
  #more-sheet button:last-child { border-bottom: 0; }
  #more-sheet .mo-out { color: var(--danger); font-weight: 600; }
}
