:root {
  --bg: #f3f1ec;
  --bg-2: #e8e4db;
  --card: #fffdf9;
  --ink: #122033;
  --muted: #6b7789;
  --line: #e4dfd4;
  --navy: #0f2744;
  --navy-2: #17375f;
  --teal: #0e7c66;
  --teal-dark: #0a5f4e;
  --gold: #c4a35a;
  --ok: #0e7c66;
  --danger: #c2413b;
  --shadow: 0 10px 30px rgba(18, 32, 51, 0.08);
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Assistant, "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(1200px 400px at 100% -10%, #dce8e4 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
.top {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  color: #fff;
  padding: 12px 16px 0;
  box-shadow: 0 8px 24px rgba(15, 39, 68, 0.25);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--gold); color: var(--navy);
  font-weight: 800; font-size: 16px;
}
.brand-mark.lg { width: 48px; height: 48px; font-size: 22px; margin: 0 auto 10px; }
.top h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.top-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.top-user { display: flex; align-items: center; gap: 8px; font-size: 13px; opacity: .92; }
.btn.light { color: #fff; border-color: rgba(255,255,255,.4); }
.btn.light:hover { background: rgba(255,255,255,.1); }
body.mode-shift .month-only { display: none; }
.mode-pick { display: flex; gap: 10px; flex-wrap: wrap; }
.mode-opt {
  display: flex; align-items: center; gap: 8px; color: var(--ink);
  background: #f6f3ec; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
}
.mode-opt input { width: auto; margin: 0; }

.login-screen {
  position: fixed; inset: 0; z-index: 80;
  background: linear-gradient(180deg, #0f2744 0%, #1b3d66 48%, #f3f1ec 48%);
  display: grid; place-items: center; padding: 20px;
}
.login-screen[hidden] { display: none; }
.login-card {
  width: min(420px, 100%); background: var(--card);
  border: 1px solid var(--line); border-radius: 24px;
  padding: 28px 24px; text-align: center; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 6px; font-size: 26px; }
.login-card label, .login-card input { text-align: right; }
.login-card .btn { width: 100%; margin-top: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn[disabled] { opacity: 0.85; cursor: wait; }
.btn-spin {
  display: none; width: 18px; height: 18px; flex: none;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.btn.loading .btn-spin { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 2px; }
.tab {
  flex: 1; border: 0; background: transparent; color: rgba(255,255,255,.62);
  padding: 11px 0 12px; font-size: 15px; cursor: pointer;
  border-bottom: 3px solid transparent; font-family: inherit; font-weight: 700;
}
.tab.active { color: #fff; border-bottom-color: var(--gold); }

main { max-width: 760px; margin: 0 auto; padding: 16px 14px 40px; }
.panel { display: none; }
.panel.active { display: block; }

.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.hero-month { margin-bottom: 10px; }
.hero-total {
  width: 100%; border: 0; background: linear-gradient(135deg, #12324f, #0e7c66);
  color: #fff; border-radius: 18px; padding: 16px 18px; text-align: right;
  cursor: pointer; font-family: inherit;
}
.hero-total .lbl { color: rgba(255,255,255,.75); font-size: 13px; display: block; }
.hero-total .big { color: #fff; font-size: 36px; display: block; margin: 2px 0; }
.hero-hint { color: rgba(255,255,255,.7); font-size: 12px; }
.stats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px; margin-top: 12px;
}
.count {
  background: #f6f3ec; border-radius: 14px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.count span { color: var(--muted); font-size: 12px; }
.count b { font-size: 18px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  box-shadow: 0 4px 16px rgba(18, 32, 51, 0.04);
}
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2.gap { margin-top: 10px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }

label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px;
  padding: 11px 12px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14,124,102,.28); border-color: var(--teal); }
.edit-banner {
  margin-top: 12px; padding: 10px 12px; border-radius: 12px;
  background: #eef6f3; color: var(--teal); display: flex; gap: 10px;
  align-items: center; justify-content: space-between; flex-wrap: wrap; font-weight: 700;
}

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px;
  margin-bottom: 8px; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: #fff;
  color: var(--ink); border-radius: 999px; padding: 8px 12px;
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.add-row {
  display: grid; grid-template-columns: 1.1fr 1fr auto; gap: 8px; align-items: end;
}
@media (max-width: 560px) { .add-row { grid-template-columns: 1fr 1fr; } .add-row .btn { grid-column: 1 / -1; } }

.import-card summary {
  cursor: pointer; font-weight: 800; font-size: 16px; list-style: none;
}
.import-card summary::-webkit-details-marker { display: none; }
.import-card[open] summary { margin-bottom: 10px; }

.btn {
  border: 0; background: var(--teal); color: #fff; font-size: 16px; font-family: inherit;
  padding: 11px 18px; border-radius: 12px; cursor: pointer; font-weight: 800;
}
.btn:hover { background: var(--teal-dark); }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f6f3ec; }
.btn.danger { color: var(--danger); border-color: #f0c9c6; }
.btn.danger:hover { background: #fdf2f1; }
.btn.small { padding: 7px 12px; font-size: 14px; }

.dash-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.dash-row .idx { min-width: 54px; color: var(--muted); font-size: 14px; }
.dash-row input { margin: 0; }
.dash-row .tag { min-width: 70px; text-align: left; font-weight: 700; color: var(--ok); font-size: 14px; }
.dash-row .tag.none { color: var(--muted); font-weight: 400; }
.x {
  border: 0; background: #f3eee6; color: var(--muted); width: 36px; height: 36px;
  border-radius: 10px; font-size: 18px; cursor: pointer;
}
.x:hover { background: #fde8e6; color: var(--danger); }

.item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item .name { flex: 1; }
.item .amt { color: var(--ok); font-size: 13px; font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-size: 20px; cursor: pointer; color: var(--teal);
}
.stepper input { width: 54px; margin: 0; text-align: center; padding: 8px 4px; }

.spacer { height: 90px; }
.resultbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: rgba(255,253,249,.94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(18, 32, 51, 0.08);
  padding: 10px 16px; display: none; align-items: center; justify-content: flex-end; gap: 8px;
}
body.calc-active .resultbar { display: flex; }
.lbl { color: var(--muted); font-size: 13px; }
.big { font-size: 28px; font-weight: 800; color: var(--navy); line-height: 1.1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 70px; z-index: 40;
  max-height: 70vh; overflow: auto; background: var(--card);
  border-radius: 22px 22px 0 0; border: 1px solid var(--line);
  box-shadow: 0 -8px 30px rgba(18, 32, 51, 0.18);
  padding: 16px; max-width: 760px; margin: 0 auto;
}
.sheet[hidden] { display: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.expl-group { margin-top: 10px; font-weight: 800; color: var(--teal); font-size: 14px; }
.expl-line { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.expl-line .t { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; }
.expl-line .d { color: var(--muted); font-size: 13px; }
.expl-line .a { white-space: nowrap; }
.expl-total { display: flex; justify-content: space-between; font-size: 18px; font-weight: 800; margin-top: 12px; }
.empty { color: var(--muted); text-align: center; padding: 22px 0; }

.history-top { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .history-top { grid-template-columns: 1fr; } }
.monthsum { display: flex; flex-direction: column; justify-content: center; }
.hist {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
}
.hist-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 14px; cursor: pointer;
}
.hist-head .date { font-weight: 800; }
.hist-head .sub { color: var(--muted); font-size: 13px; }
.hist-head .tot { font-size: 20px; font-weight: 800; color: var(--teal); }
.hist-body { padding: 0 14px 12px; display: none; }
.hist.open .hist-body { display: block; }
.hist-actions { margin-top: 10px; text-align: left; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.monthsum .btn { margin-top: 8px; width: fit-content; }

.tier-row, .item-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; flex-wrap: wrap; }
.tier-row label { flex: 1; min-width: 110px; }
.item-row label.grow { flex: 3; min-width: 180px; }
.item-row label.mid { flex: 1; min-width: 100px; }
.item-row label.sm { flex: 1; min-width: 80px; }
.item-row { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.rules-actions { display: flex; gap: 10px; margin: 6px 0; flex-wrap: wrap; }

textarea {
  min-height: 140px; margin: 8px 0; resize: vertical; line-height: 1.4;
}
#parseChat { margin-top: 4px; }
.mini-items { margin-top: 10px; }
.mini-items .item input { width: 80px; margin: 0; }
#unmappedList { margin: 0; padding-right: 18px; color: var(--muted); }
.note-field { display: block; margin: 4px 0 12px; }

.user-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.user-row:last-child { border-bottom: 0; }
.user-row b { font-size: 17px; }
.user-row span { color: var(--muted); font-size: 13px; }

.tour {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(15, 39, 68, 0.55);
  display: grid; place-items: center; padding: 20px;
}
.tour[hidden] { display: none; }
.tour-card {
  width: min(420px, 100%); background: var(--card);
  border-radius: 22px; padding: 22px; box-shadow: var(--shadow);
}
.tour-step { color: var(--gold); font-weight: 800; font-size: 13px; margin-bottom: 6px; }
.tour-card h2 { margin: 0 0 8px; font-size: 22px; }
.tour-card p { margin: 0 0 14px; color: var(--muted); }
.tour-actions { display: flex; justify-content: space-between; gap: 8px; }
.tour-actions .btn { min-width: 110px; }

.toast {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 100;
  box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); }
.toast[hidden] { display: none; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
