*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --border: #242424;
  --border-light: #2e2e2e;
  --text: #ececec;
  --text-2: #8a8a8a;
  --text-3: #5a5a5a;
  --accent: #22c55e;
  --accent-dim: rgba(34, 197, 94, 0.14);
  --blue: #3b82f6;
  --owe: #f97316;
  --owe-dim: rgba(249, 115, 22, 0.14);
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

html, body { background: var(--bg); color: var(--text); overscroll-behavior-y: none; }
body {
  font-family: var(--font);
  font-size: 16px;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }

.logo { font-weight: 700; font-size: 22px; letter-spacing: -0.04em; }
.logo-dot { color: var(--accent); }
.logo-big { font-size: 44px; }

/* ── Lock ── */
.lock-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg); z-index: 100;
}
.lock-content { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.lock-sub { color: var(--text-2); margin-bottom: 24px; }
.lock-input-wrap { display: flex; width: 100%; gap: 8px; }
.lock-input-wrap input {
  flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; outline: none; font-size: 16px;
}
.lock-input-wrap input:focus { border-color: var(--accent); }
.lock-btn {
  width: 52px; border-radius: var(--radius-sm); background: var(--accent); color: #04120a;
  display: flex; align-items: center; justify-content: center;
}
.lock-error { color: var(--danger); font-size: 14px; margin-top: 8px; text-align: center; }

/* ── App shell ── */
.app { max-width: 520px; margin: 0 auto; min-height: 100dvh; }
.header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.icon-btn:active { background: var(--surface-2); }
.main { padding: 16px 16px calc(var(--safe-bottom) + 120px); }

/* ── Balance ── */
.balance-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.balance-label { color: var(--text-2); font-size: 14px; }
.balance-amount { font-size: 36px; font-weight: 700; letter-spacing: -0.03em; }
.balance-amount.pos { color: var(--accent); }
.balance-amount.neg { color: var(--owe); }
.balance-sub { color: var(--text-2); font-size: 13px; min-height: 1em; margin-bottom: 8px; }

.month-stats { display: flex; gap: 8px; overflow-x: auto; margin: 12px -16px 0; padding: 0 16px; scrollbar-width: none; }
.month-stats::-webkit-scrollbar { display: none; }
.stat {
  flex: 0 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font-size: 13px; color: var(--text-2);
}
.stat b { display: block; color: var(--text); font-size: 15px; font-weight: 600; }

/* ── List ── */
.list { margin-top: 16px; }
.month-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: var(--text-2); padding: 16px 4px 8px; text-transform: uppercase; letter-spacing: 0.04em;
}
.entry {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px; border-radius: 12px;
}
.entry:active { background: var(--surface); }
.entry-icon {
  width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; position: relative;
}
.entry-icon .clip { position: absolute; right: -3px; bottom: -3px; font-size: 11px; background: var(--bg); border-radius: 50%; padding: 1px; }
.entry-main { flex: 1; min-width: 0; }
.entry-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-right { text-align: right; flex-shrink: 0; }
.entry-amount { font-weight: 600; }
.entry-effect { font-size: 12px; margin-top: 2px; }
.entry-effect.pos { color: var(--accent); }
.entry-effect.neg { color: var(--owe); }
.entry-effect.none { color: var(--text-3); }
.empty { text-align: center; padding: 48px 16px; }
.empty p + p { margin-top: 6px; font-size: 14px; }

/* ── FAB ── */
.fab-group {
  position: fixed; right: max(16px, calc(50% - 260px + 16px)); bottom: calc(var(--safe-bottom) + 20px);
  display: flex; gap: 12px; align-items: center; z-index: 20;
}
.fab {
  height: 56px; padding: 0 22px; border-radius: 28px; background: var(--accent); color: #04120a;
  display: flex; align-items: center; gap: 8px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.fab-secondary { width: 56px; padding: 0; justify-content: center; background: var(--surface-2); color: var(--text); border: 1px solid var(--border-light); }
.fab:active { transform: scale(0.96); }

/* ── Buttons ── */
.btn { width: 100%; padding: 14px; border-radius: var(--radius-sm); font-weight: 600; }
.btn-ghost { background: var(--surface-2); border: 1px solid var(--border-light); }
.btn-small { width: auto; padding: 8px 16px; font-size: 14px; }
.btn-danger { background: rgba(239, 68, 68, 0.12); color: var(--danger); margin-top: 8px; }
.link-btn { color: var(--text-2); padding: 8px 4px; }
.link-btn.strong { color: var(--accent); font-weight: 600; }
.link-btn.small { font-size: 13px; padding: 4px 0; }
.link-btn.danger { color: var(--danger); }
.link-btn:disabled { opacity: 0.4; }

/* ── Sheets ── */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s ease-out;
}
.sheet {
  width: 100%; max-width: 520px; max-height: calc(100dvh - var(--safe-top) - 24px);
  background: var(--surface); border-radius: 20px 20px 0 0; border: 1px solid var(--border);
  display: flex; flex-direction: column; animation: slide 0.2s ease-out;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.sheet-head h2 { font-size: 16px; font-weight: 600; }
.sheet-body {
  overflow-y: auto; padding: 16px 16px calc(var(--safe-bottom) + 24px);
  display: flex; flex-direction: column; gap: 16px; -webkit-overflow-scrolling: touch;
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(40px); opacity: 0.5; } }

/* ── Form ── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; color: var(--text-2); }
.field input, .field textarea {
  background: var(--surface-2); border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 12px 14px; outline: none; font-size: 16px; width: 100%; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.row { display: flex; gap: 12px; }
.grow { flex: 1; }
.amount-input { position: relative; }
.amount-input input { padding-right: 34px; font-size: 20px; font-weight: 600; }
.amount-input .unit { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-2); }
input[type="date"] { min-height: 50px; }

.segmented { display: flex; background: var(--surface-2); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 3px; }
.segmented button { flex: 1; padding: 9px 8px; border-radius: 8px; color: var(--text-2); font-weight: 500; font-size: 14px; }
.segmented button.active { background: var(--border-light); color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border-light);
  font-size: 14px; color: var(--text-2);
}
.chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }

.split-extra:empty { display: none; }
.split-extra { display: flex; gap: 12px; }
.split-extra label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
.split-extra input {
  background: var(--surface-2); border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 10px 12px; outline: none; font-size: 16px; width: 100%;
}
.split-summary { font-size: 14px; color: var(--text-2); background: var(--bg); border-radius: var(--radius-sm); padding: 10px 12px; line-height: 1.5; }
.split-summary b { color: var(--text); font-weight: 600; }
.split-summary.error { color: var(--danger); }

.items { display: flex; flex-direction: column; border: 1px solid var(--border-light); border-radius: var(--radius-sm); overflow: hidden; }
.items-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; font-size: 12px; color: var(--text-2); background: var(--bg); gap: 8px; }
.items-head .quick { display: flex; gap: 10px; }
.items-head .quick button { color: var(--text-2); font-size: 12px; text-decoration: underline; }
.item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 14px; }
.item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-price { flex-shrink: 0; color: var(--text-2); }
.item-assign {
  flex-shrink: 0; min-width: 72px; padding: 5px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--border-light); color: var(--text);
}
.item-assign.a { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.item-assign.b { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }

.receipt-add {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; border: 1.5px dashed var(--border-light); border-radius: var(--radius-sm); color: var(--text-2);
}
.receipt-add:active { background: var(--surface-2); }
.receipt-preview { display: flex; gap: 12px; align-items: center; }
.receipt-preview img { width: 64px; height: 84px; object-fit: cover; border-radius: 8px; background: var(--surface-2); cursor: zoom-in; flex-shrink: 0; }
.receipt-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.receipt-status { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.receipt-status.error { color: var(--danger); }
.receipt-status.ok { color: var(--accent); }
.receipt-actions { display: flex; gap: 16px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-light); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.form-error { color: var(--danger); font-size: 14px; }
.settings-info { font-size: 13px; color: var(--text-2); line-height: 1.6; background: var(--bg); padding: 10px 12px; border-radius: var(--radius-sm); }

/* ── Viewer & toast ── */
.viewer { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, 0.95); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 96px); z-index: 90;
  background: var(--surface-2); border: 1px solid var(--border-light); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.toast.error { border-color: var(--danger); color: #fca5a5; }

@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}
