:root {
  --bg: #f4f5f8; --card: #fff; --text: #171a21; --muted: #6b7280; --line: #e6e8ee;
  --accent: #1f5eff; --accent-soft: #e8efff; --ok: #12805c; --ok-soft: #e3f5ee;
  --warn: #b45309; --warn-soft: #fdf1e1; --bad: #c62828; --bad-soft: #fdeaea;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b22; --text: #eceef3; --muted: #9aa1ad; --line: #2a2f3a;
    --accent: #5b8cff; --accent-soft: #1b2540; --ok: #3ccf91; --ok-soft: #13291f;
    --warn: #f0a44b; --warn-soft: #2d2213; --bad: #ff6b6b; --bad-soft: #321819; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 12px 24px;
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); font-size: 17px; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.nav a.on { color: var(--accent); background: var(--accent-soft); }
.tabbar { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 40px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 20px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 13px; }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 6px 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.item:first-child { border-top: 0; padding-top: 2px; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 13px; }
.item .acts { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; padding-left: 40px; }
.item[data-rem] .acts { padding-left: 0; }
.acts input[type=date] { width: 150px; }
.client-row { cursor: pointer; }
.client-row:hover .title { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.btn { border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn.bad { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.check { width: 28px; height: 28px; flex: none; border-radius: 50%; border: 2px solid var(--line); background: transparent; cursor: pointer; color: transparent; font-weight: 700; }
.check:hover { border-color: var(--ok); color: var(--ok); }
.check.done { background: var(--ok); border-color: var(--ok); color: #fff; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.gray { background: var(--bg); color: var(--muted); }

input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.f { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.inline-form { display: grid; grid-template-columns: 2fr 1fr 120px; gap: 8px; align-items: end; }
#addPay.inline-form { grid-template-columns: 1fr 1fr 2fr auto; }
.select-sm { width: auto; padding: 4px 8px; font-size: 13px; border-radius: 8px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-color: var(--accent); }

.fin { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--line); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); margin-bottom: 16px; }
.fin div { background: var(--card); padding: 10px 14px; }
.fin span { display: block; font-size: 12px; color: var(--muted); }
.fin b { font-variant-numeric: tabular-nums; }

.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.doc { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; user-select: none; }
.doc.on { border-color: var(--ok); background: var(--ok-soft); }
.doc input { width: 18px; height: 18px; accent-color: var(--ok); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 500; font-size: 13px; border-top: 0; }
td.r, th.r { text-align: right; }

.login { max-width: 380px; margin: 12vh auto; text-align: center; }
.login .card { padding: 28px; }
.secret { font-family: ui-monospace, Menlo, monospace; }
.empty { color: var(--muted); padding: 8px 0; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #171a21; color: #fff;
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.tpl-body { white-space: pre-wrap; word-break: break-word; background: var(--bg); border-radius: 9px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.memos { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.memo { margin: 0; display: flex; flex-direction: column; }
.memo img { width: 100%; aspect-ratio: 1 / 1.41; object-fit: cover; object-position: top; border-radius: 8px; border: 1px solid var(--line); display: block; background: #fff; }
.memo-pdf { display: flex; flex-direction: column; justify-content: center; align-items: center; aspect-ratio: 1 / 1.41; border-radius: 8px; border: 1px dashed var(--line); font-size: 22px; }
.memo-title { word-break: break-word; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); }

@media (max-width: 760px) {
  .top { padding: 10px 16px; }
  .nav { display: none; }
  main { padding: 14px 16px 90px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { flex: 1; text-align: center; color: var(--muted); font-size: 10px; padding: 7px 0 6px; }
  .tabbar a i { display: block; font-style: normal; font-size: 18px; line-height: 1.2; }
  .tabbar a.on { color: var(--accent); }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .fin { grid-template-columns: 1fr 1fr; }
  .fin div:last-child { grid-column: span 2; }
  .inline-form { grid-template-columns: 1fr 1fr; }
  .inline-form .wide-m { grid-column: 1 / -1; }
  h1 { font-size: 20px; }
}
