:root {
  --navy: #1f2a6b; --purple: #7f499c; --peach: #fae3d9; --olive: #a8a035;
  --bg: #f4f5fa; --card: #fff; --ink: #1d2033; --muted: #6b7087; --line: #e1e3ee;
  --ok: #1f9d55; --bad: #d93025;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
a { color: var(--purple); }

.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--line); height: 54px;
}
.brand { height: 30px; width: auto; }
.tag { font-weight: 700; color: var(--purple); background: #f1e9f6; border-radius: 999px; padding: 2px 10px; font-size: 13px; }
#logout { margin-left: auto; }

.tabs { position: sticky; top: 54px; z-index: 19; display: flex; gap: 6px; padding: 8px 12px; background: var(--bg); max-width: 784px; margin: 0 auto; }
.tabs button { flex: 1; border: 0; background: #e6e8f2; color: var(--navy); font-weight: 700; padding: 10px 6px; border-radius: 10px; font-size: 15px; }
.tabs button.on { background: var(--navy); color: #fff; }

main { max-width: 784px; margin: 0 auto; padding: 0 12px 16px; }
.card {
  background: var(--card); border-radius: 14px; padding: 14px; margin: 10px 0; border: 1px solid #eceef6;
  box-shadow: 0 1px 2px rgba(20, 24, 60, .05), 0 4px 14px rgba(20, 24, 60, .05);
}
.headline { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
h2 { margin: 6px 0; font-size: 20px; color: var(--navy); }
h3 { margin: 0 0 10px; font-size: 15.5px; color: var(--purple); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
p.small { margin: -4px 0 10px; }

label { display: block; font-size: 13px; font-weight: 600; color: #40445c; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; font: inherit; font-size: 16px; color: var(--ink);
  background: #fbfbfe; border: 1px solid #d6d9e6; border-radius: 10px; padding: 11px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 46px; line-height: 1.35; }
input:focus, select:focus, textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(127, 73, 156, .16); background: #fff; }
input.need { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(217, 48, 37, .15); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 340px) { .grid { grid-template-columns: 1fr; } }
.mail input { background: #f6f1fa; border-color: #d9c6e6; }
.note { display: block; margin-top: 5px; color: #9a5b00; font-weight: 600; }

button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.primary {
  background: linear-gradient(135deg, var(--purple), var(--navy)); color: #fff; border: 0; border-radius: 12px;
  padding: 12px 16px; font-weight: 700; font-size: 16px;
}
.ghost { background: #fff; color: var(--navy); border: 1px solid #cfd3e4; border-radius: 12px; padding: 11px 14px; font-weight: 600; font-size: 15px; }
.ghost.small, .primary.small { padding: 7px 11px; font-size: 13.5px; border-radius: 9px; }
.danger { color: var(--bad); border-color: #f0c4c0; }
.wide { width: 100%; }
.top-gap { margin-top: 12px; }
button:disabled { opacity: .55; }
.btnlink { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.link { font-weight: 600; font-size: 11.5px; margin-left: 4px; border-radius: 6px; padding: 1px 6px; }
.link.auto { color: var(--ok); background: #e7f6ed; }
.link.manual { color: var(--purple); background: #f1e9f6; cursor: pointer; }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 8px; justify-content: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .97);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(20, 24, 60, .06);
}
.bar .ghost { flex: 0 0 auto; }
.bar .primary { flex: 1; max-width: 420px; }

details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h3 { margin: 0; }
details.fold > summary h3::before { content: "\25B8  "; color: var(--muted); }
details.fold[open] > summary h3::before { content: "\25BE  "; }
details.fold[open] > summary { margin-bottom: 8px; }
details.sub { margin: 12px 0 4px; }
details.sub > summary { cursor: pointer; color: var(--purple); font-weight: 600; font-size: 13.5px; margin-bottom: 10px; }

.sec { margin: 10px 0 14px; }
.sec-h { background: var(--olive); color: #fff; font-weight: 700; font-size: 12.5px; letter-spacing: .3px; padding: 7px 10px; border-radius: 9px 9px 0 0; }
.sec.tax .sec-h, .sec.acct .sec-h { background: var(--purple); }
.lines { border: 1px solid #e4e5d3; border-top: 0; border-radius: 0 0 9px 9px; padding: 6px 8px 8px; background: #fcfcf3; }
.sec.tax .lines, .sec.acct .lines { background: #fbf8fd; border-color: #eadff1; }
.line { display: flex; gap: 6px; margin: 6px 0; }
.line .ln { flex: 1; margin: 0; min-width: 0; }
.line .la { width: 96px; flex: 0 0 96px; margin: 0; text-align: right; }
.line .x { flex: 0 0 42px; border: 0; background: #fbe9e8; color: var(--bad); border-radius: 10px; font-weight: 700; }
.sec .add { margin-top: 6px; }
.rates { width: 100%; border-collapse: collapse; }
.rates th { font-size: 12px; color: var(--muted); text-align: right; padding: 4px; font-weight: 600; }
.rates td { padding: 3px 4px; font-size: 13.5px; font-weight: 600; }
.rates input { margin: 0; text-align: right; }
.acct .lines.grid { padding-top: 10px; }
.sumline { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; background: var(--peach); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 4px 0 14px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stat { background: #fff; border-radius: 12px; padding: 10px 6px; border: 1px solid #eceef6; text-align: center; }
.stat b { display: block; font-size: 19px; color: var(--navy); }
.stat span { font-size: 12px; color: var(--muted); }
.search { margin: 6px 0 4px; }
.item {
  display: block; width: 100%; text-align: left; background: #fff; border: 1px solid #eceef6; border-radius: 12px;
  padding: 12px; margin: 8px 0; box-shadow: 0 1px 2px rgba(20, 24, 60, .05); color: var(--ink);
}
.item .r1 { display: flex; justify-content: space-between; font-weight: 700; color: var(--navy); }
.item .r2 { color: #40445c; margin: 2px 0 7px; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 2px 9px; margin: 0 6px 2px 0; background: #eef0f5; color: #555b75; }
.pill.paid { background: #e3f5ea; color: var(--ok); }
.pill.unpaid { background: #fdecec; color: var(--bad); }
.pill.sent { background: #e9ecfb; color: var(--navy); }
.pill.cancel { background: #eee; color: #666; text-decoration: line-through; }

.okbox { background: #e6f6ec; border: 1px solid #bfe6cc; color: #14532d; border-radius: 12px; padding: 12px; margin: 8px 0; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.row { display: flex; gap: 8px; margin-top: 12px; align-items: stretch; }
.row input { margin: 0; flex: 1; min-width: 0; }
.row button { flex: 0 0 auto; }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 18, 40, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  position: relative; background: #fff; width: 100%; max-width: 784px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.close { position: absolute; right: 10px; top: 10px; border: 0; background: #f0f1f7; border-radius: 50%; width: 36px; height: 36px; font-size: 16px; color: #333; }
.sheet h3 { padding-right: 40px; }
.preview img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.auth { max-width: 420px; margin: 28px auto; padding: 0 14px; }
.auth label { margin: 12px 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 60;
  background: #1d2033; color: #fff; padding: 10px 14px; border-radius: 10px; max-width: 92vw; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2); text-align: center;
}
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
