:root {
  --accent: #0e7c86;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, white);
  --bg: #f4f5f3;
  --card: #ffffff;
  --ink: #1d2322;
  --muted: #6b7471;
  --line: #e3e6e2;
  --red: #c8372d;
  --amber: #b86e00;
  --green: #1f7a4a;
  --radius: 12px;
  --nav-h: 64px;
  --side-w: 220px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.shell { min-height: 100vh; }
.nav {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: stretch;
}
.nav a, .nav button.navbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; background: none; border: 0; cursor: pointer; position: relative;
}
.nav a.active { color: var(--accent); font-weight: 600; }
.nav svg { width: 22px; height: 22px; }
.nav .plus span.circle {
  width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 40%, transparent);
}
.nav .plus span.circle svg { width: 26px; height: 26px; }
.nav .brand, .nav .side-only { display: none !important; }
[hidden] { display: none !important; }
.badge { position: absolute; top: 6px; left: 55%; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; border-radius: 9px; padding: 1px 5px; min-width: 16px; text-align: center; }
main { padding: 12px 12px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1500px; margin: 0 auto; }

@media (min-width: 900px) {
  .nav {
    top: 0; right: auto; bottom: 0; width: var(--side-w); height: auto; padding: 16px 10px;
    flex-direction: column; justify-content: flex-start; gap: 2px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav .brand { display: block; font-weight: 700; font-size: 17px; padding: 6px 12px 18px; color: var(--ink); }
  .nav .brand small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
  .nav a, .nav button.navbtn { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; border-radius: 9px; font-size: 14px; }
  .nav a:hover { background: var(--bg); }
  .nav a.active { background: var(--accent-soft); }
  .nav .side-only { display: flex !important; }
  .nav .mobile-only { display: none !important; }
  .nav .plus { order: -1; margin-bottom: 10px; }
  .nav .plus span.circle { width: auto; height: auto; border-radius: 9px; padding: 9px 14px; box-shadow: none; gap: 6px; display: flex; font-size: 14px; font-weight: 600; }
  .nav .plus span.circle svg { width: 18px; height: 18px; }
  .nav .plus .lbl { display: none; }
  .nav .plus span.circle::after { content: attr(data-label); }
  .badge { position: static; margin-left: auto; }
  main { margin-left: var(--side-w); padding: 22px 28px 40px; }
}

/* ---------- elements ---------- */
h1 { font-size: 22px; margin: 4px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
h2 .count { color: var(--ink); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #c9cec8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; padding: 6px; cursor: pointer; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; outline: none;
  min-height: 42px; font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 70px; resize: vertical; }
label.f { display: block; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px 2px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel + .panel { margin-top: 12px; }
.panel h3 { margin: 0 0 10px; font-size: 15px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag { font-size: 12px; color: var(--muted); background: var(--bg); padding: 2px 8px; border-radius: 6px; }
.empty { color: var(--muted); padding: 14px 4px; font-size: 14px; }
.seg { display: inline-flex; background: #e9ebe7; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.search { position: relative; flex: 1; min-width: 180px; }
.search input { padding-left: 36px; }
.search svg { position: absolute; left: 11px; top: 12px; width: 18px; height: 18px; color: var(--muted); }

/* ---------- deal cards ---------- */
.cards { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px; position: relative; transition: border-color .15s;
}
.card:hover { border-color: #c3c9c2; }
.card .top { display: flex; align-items: center; gap: 8px; }
.card .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .info { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .next { font-size: 13px; display: flex; gap: 6px; align-items: center; }
.card .next.overdue { color: var(--red); font-weight: 600; }
.card .next.today { color: var(--amber); font-weight: 600; }
.card .last { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .wa-mini { position: absolute; right: 8px; bottom: 8px; width: 30px; height: 30px; border-radius: 50%; background: #25d366; color: #fff; display: grid; place-items: center; }
.card .wa-mini svg { width: 17px; height: 17px; }
.money { font-variant-numeric: tabular-nums; }
.debt { color: var(--red); font-weight: 600; }

/* ---------- board ---------- */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x mandatory; margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
.col { flex: 0 0 82vw; max-width: 300px; scroll-snap-align: start; background: #ebedea; border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 7px; min-height: 120px; }
@media (min-width: 900px) { .board { margin: 0; padding-left: 0; } .col { flex: 0 0 270px; } }
.col.drop { outline: 2px dashed var(--accent); }
.col-head { display: flex; align-items: center; gap: 6px; padding: 4px 4px 2px; font-weight: 600; font-size: 13px; }
.col-head .n { color: var(--muted); font-weight: 500; }
.col-head .sum { margin-left: auto; color: var(--muted); font-weight: 500; font-size: 12px; }
.col .card { box-shadow: 0 1px 1px rgba(0,0,0,.03); }

/* ---------- deal page ---------- */
.deal-head { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 12px; }
.deal-head h1 { margin: 0; }
.deal-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.statusbar { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; }
.statusbar button { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 7px 13px; font-size: 13px; cursor: pointer; white-space: nowrap; color: var(--muted); }
.statusbar button.on { color: #fff; border-color: transparent; font-weight: 600; }
.deal-layout { display: grid; gap: 12px; }
@media (min-width: 1100px) { .deal-layout { grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); align-items: start; } }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.timeline { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.ev { font-size: 14px; border-left: 3px solid var(--line); padding: 2px 0 2px 10px; white-space: pre-wrap; word-break: break-word; }
.ev.note { border-color: var(--accent); }
.ev.bot { border-color: #25d366; }
.ev.status { border-color: #a78bfa; color: var(--muted); }
.ev.system { color: var(--muted); }
.ev .meta { font-size: 11px; color: var(--muted); margin-bottom: 1px; }
.pay-row { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.pay-row:last-child { border-bottom: 0; }
.totals { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.totals div { font-size: 13px; color: var(--muted); }
.totals b { display: block; font-size: 18px; color: var(--ink); }
.savebar { position: sticky; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom)); z-index: 5; display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
@media (min-width: 900px) { .savebar { bottom: 12px; } }
.savebar .btn { box-shadow: 0 6px 18px rgba(0,0,0,.15); }

/* ---------- calendar ---------- */
.cal-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.cal { display: grid; min-width: max-content; position: relative; }
.cal .c { height: 46px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 12px; }
.cal .unit { position: sticky; left: 0; z-index: 3; background: #fff; padding: 0 10px; display: flex; align-items: center; font-weight: 600; font-size: 13px; width: 110px; box-shadow: 1px 0 0 var(--line); }
.cal .dh { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); height: 40px; }
.cal .dh b { color: var(--ink); font-size: 13px; }
.cal .dh.we { background: #fafaf7; }
.cal .dh.today b { color: #fff; background: var(--accent); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
.cal .cell { cursor: pointer; }
.cal .cell:hover { background: var(--accent-soft); }
.cal .cell.we { background: #fafaf7; }
.bar {
  position: absolute; z-index: 2; height: 34px; border-radius: 8px; color: #fff; font-size: 12px; padding: 3px 8px; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; cursor: pointer; line-height: 1.25; box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.bar small { display: block; opacity: .85; font-size: 11px; }
.bar.tent { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.28) 0 6px, transparent 6px 12px); opacity: .85; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

/* ---------- stats ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { white-space: nowrap; font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.hbar { display: grid; grid-template-columns: minmax(110px, 180px) 1fr 70px; gap: 8px; align-items: center; font-size: 13px; padding: 4px 0; }
.hbar .track { background: #eef0ec; border-radius: 6px; height: 12px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 6px; background: var(--accent); }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #fafbf9; }
table.t td.r, table.t th.r { text-align: right; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 26px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 6px; }
.err { color: var(--red); font-size: 14px; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20,25,24,.4); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .overlay { align-items: center; } .modal { border-radius: 16px; padding: 22px; } }
.modal h2 { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 18px; margin: 0 0 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.suggest { border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; overflow: hidden; }
.suggest div { padding: 9px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--line); }
.suggest div:last-child { border-bottom: 0; }
.suggest div:hover { background: var(--accent-soft); }
.hint { font-size: 13px; padding: 8px 10px; border-radius: 8px; margin-top: 6px; }
.hint.ok { background: #e8f5ec; color: var(--green); }
.hint.bad { background: #fdecea; color: var(--red); }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%) translateY(20px); background: #1d2322; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .2s; z-index: 60; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--red); }
.list-link { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; color: var(--ink); font-weight: 500; }
.list-link svg { width: 20px; height: 20px; color: var(--muted); }
