:root {
  --teal: #0f766e;
  --teal-d: #0b5d56;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #16a34a;
  --red: #dc2626;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* login */
.login-box {
  max-width: 360px;
  margin: 12vh auto;
  padding: 24px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box h1 { font-size: 20px; margin: 0 0 8px; text-align: center; }
.err { color: var(--red); font-size: 14px; min-height: 18px; }
.msg { color: var(--green); font-size: 14px; min-height: 18px; }

/* topbar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--teal); color: #fff;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 10;
}
.link { background: none; border: none; color: inherit; text-decoration: underline; cursor: pointer; font-size: 14px; }

.tabpane { padding: 16px; max-width: 640px; margin: 0 auto; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* bottom nav */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 8px;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 12px; padding-bottom: calc(8px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}
.navbtn {
  flex: 1; max-width: 200px; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 12px; padding: 6px; border-radius: 12px;
}
.navbtn.active { color: var(--teal); }
.navbtn.active svg { transform: translateY(-1px); }
.navadd {
  color: #fff; background: var(--teal); max-width: 200px;
}
.navadd span { font-weight: 600; }
.navadd:active { background: var(--teal-d); }

/* toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }

/* stats bar */
.stats { display: flex; gap: 8px; margin-bottom: 14px; }
.stat {
  flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05); min-width: 0;
}
.stat-l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.stat-v { font-size: 15px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-v.stat-debt { color: var(--red); }
.stat.stat-narrow { flex: 0 0 auto; }
.fbtn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.fbtn:active { background: #f1f5f9; }
.badge {
  background: var(--teal); color: #fff; border-radius: 999px; font-size: 12px;
  min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 700;
}

/* filters popup */
.backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 30; }
.filters.popup {
  position: fixed; z-index: 31; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 24px)); max-height: 86vh; overflow-y: auto;
}
.filters {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.btn-apply {
  background: var(--teal); color: #fff; border: none; padding: 13px;
  border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 2px;
}
.btn-apply:active { background: var(--teal-d); }
.filters-head { display: flex; justify-content: space-between; align-items: center; }
.filters-title { font-weight: 700; font-size: 15px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #f8fafc; color: var(--muted);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--teal); color: #fff; border-color: var(--teal); font-weight: 600; }
.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 15px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--teal); }

/* form */
form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 12px; }
.row > label { flex: 1; }
input, select {
  font-size: 16px; padding: 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--teal); border-color: var(--teal); }

button[type=submit] {
  background: var(--teal); color: #fff; border: none; padding: 16px;
  border-radius: 12px; font-size: 17px; font-weight: 600; cursor: pointer;
}
button[type=submit]:active { background: var(--teal-d); }
#login-btn {
  background: var(--teal); color: #fff; border: none; padding: 14px;
  border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer;
}

/* preview */
.preview {
  background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 12px;
  padding: 12px; font-size: 14px; display: none;
}
.preview.show { display: block; }
.preview .pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.preview b { color: var(--teal-d); }
.preview .big { font-size: 18px; }

/* list */
.list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.trip {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
}
.trip:active { background: #f8fafc; border-color: var(--teal); }
.trip .t1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; }
.trip .t1 .tleft { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip .t1 .tdate { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.trip .t2 { color: var(--muted); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip .t3 { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; }
.trip .net { color: var(--green); font-weight: 600; }
.trip .debt { color: var(--red); }
.route { font-weight: 400; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 15px; }

/* form title + delete */
.form-title { font-size: 18px; margin: 0 0 4px; }
.btn-danger {
  background: #fff; color: var(--red); border: 1px solid var(--red);
  padding: 14px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-danger:active { background: #fef2f2; }

/* document actions (б/н) */
.doc-actions { display: flex; gap: 10px; }
.doc-actions.hidden { display: none; }
.btn-doc {
  flex: 1; background: #fff; color: var(--teal-d); border: 1px solid var(--teal);
  padding: 13px; border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-doc:active { background: #ecfdf5; }

/* payment-type icon in card */
.pay { display: inline-flex; align-items: center; flex-shrink: 0; }
.pay svg { display: block; }
.pay-cash { color: #ca8a04; }
.pay-ok { color: var(--green); }
.pay-no { color: var(--red); }
