:root {
  --bg: #0f1729;
  --bg-2: #131c33;
  --surface: #1a2440;
  --surface-2: #223056;
  --border: #2a3760;
  --text: #e8ecf5;
  --text-dim: #9aa6c2;
  --primary: #e63946;
  --primary-2: #ff4d5e;
  --accent: #ffb703;
  --success: #2ec27e;
  --danger: #ff5c5c;
  --info: #4cc9f0;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(230,57,70,.18), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(76,201,240,.15), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 980px; margin: 0 auto; padding: 0 16px; }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(10px);
  background: rgba(15,23,41,.75);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .3px; }
.brand .subtitle { margin: 0; color: var(--text-dim); font-size: 12px; }
.logo { font-size: 28px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.currency-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 999px;
  font-size: 13px; color: var(--text-dim);
}

/* Tabs */
.tabs {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 12px 16px; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: .15s ease;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(230,57,70,.35);
}

/* Panels */
.tab-panel { display: none; padding: 8px 0 60px; }
.tab-panel.active { display: block; }

/* Warn banner */
.warn-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: linear-gradient(135deg, rgba(255,183,3,.18), rgba(255,183,3,.06));
  border: 1px solid rgba(255,183,3,.45);
  color: var(--accent);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 8px 0 16px;
  cursor: pointer;
  font-size: 14px;
  transition: .15s;
}
.warn-banner:hover { transform: translateY(-1px); border-color: var(--accent); }
.warn-banner .warn-action { font-size: 12px; opacity: .8; white-space: nowrap; }
.card.has-warn { border-color: rgba(255,183,3,.5); }
.card.has-warn .stat-value { color: var(--accent); }

.section-header { margin: 22px 0 12px; }
.section-header h2 { margin: 0 0 4px; font-size: 16px; }
.section-header.row { display: flex; justify-content: space-between; align-items: center; }
.hint { color: var(--text-dim); font-size: 12px; margin: 0; }
.hint-inline { color: var(--text-dim); font-size: 12px; font-weight: 400; }

/* Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 8px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 6px; }

@media (max-width: 720px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 18px; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px rgba(230,57,70,.35);
}
.btn-ghost { background: transparent; }
.btn-danger {
  background: rgba(255,92,92,.12);
  color: var(--danger);
  border-color: rgba(255,92,92,.35);
}
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Inputs */
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary-2); }
textarea { resize: vertical; }

.filters { display: flex; gap: 8px; margin: 8px 0 14px; align-items: center; flex-wrap: wrap; }
.filters input[type="text"] { flex: 2; min-width: 200px; }
.filters select { flex: 1; max-width: 220px; min-width: 160px; }
.filter-check {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.filter-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.filter-check:has(input:checked) { color: var(--accent); border-color: rgba(255,183,3,.5); }
@media (max-width: 600px) {
  .filters select, .filters input[type="text"] { max-width: 100%; flex: 1 1 100%; }
}

/* Balances */
.balances-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 10px; }
.balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.balance-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  color: #fff;
}
.balance-amount { font-weight: 700; font-size: 16px; }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.zero { color: var(--text-dim); }

/* Expenses */
.expenses-list { display: flex; flex-direction: column; gap: 10px; }
.expense-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: .15s;
  position: relative;
}
.expense-item:hover { border-color: var(--primary-2); transform: translateY(-1px); }
.expense-item.is-open {
  border-color: rgba(255,183,3,.55);
  background: linear-gradient(180deg, rgba(255,183,3,.06), var(--surface) 70%);
}
.expense-item.is-open::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent);
  border-radius: var(--radius) 0 0 var(--radius);
}
.expense-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.expense-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.expense-title { font-weight: 600; margin: 0; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-open {
  background: rgba(255,183,3,.12);
  color: var(--accent);
  border-color: rgba(255,183,3,.4);
}
.badge-ok {
  background: rgba(46,194,126,.12);
  color: var(--success);
  border-color: rgba(46,194,126,.35);
}
.split-pill.muted { opacity: .65; font-style: italic; }
.expense-meta { color: var(--text-dim); font-size: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.expense-amount { font-size: 18px; font-weight: 700; white-space: nowrap; }
.expense-payer-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 999px; font-size: 11px;
}
.expense-splits { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.split-pill {
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--text-dim);
}
.expense-notes { margin-top: 8px; color: var(--text-dim); font-size: 13px; font-style: italic; }

/* Debts */
.debts-list { display: flex; flex-direction: column; gap: 8px; }
.debt-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.debt-flow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.arrow { color: var(--text-dim); }
.debt-amount { font-weight: 700; color: var(--accent); }

.payments-list { display: flex; flex-direction: column; gap: 8px; }
.payment-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.payment-meta { color: var(--text-dim); font-size: 12px; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }

/* History — audit timeline */
.history-list { display: flex; flex-direction: column; gap: 20px; }
.history-date-group {}
.history-date-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.history-date-label span { white-space: nowrap; }
.history-date-label::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.history-entries {
  display: flex; flex-direction: column; gap: 5px;
  border-left: 2px solid var(--border);
  margin-left: 10px;
  padding-left: 18px;
}
.audit-item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  transition: background .15s;
}
.audit-item:hover { background: var(--surface-2); }
.audit-item::before {
  content: '';
  position: absolute;
  left: -25px; top: 50%; transform: translateY(-50%);
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--event-color, var(--text-dim));
  box-shadow: 0 0 0 3px rgba(255,255,255,.04);
}
.audit-item.ev-expense  { --event-color: var(--primary); border-left: 2px solid rgba(230,57,70,.5); }
.audit-item.ev-edit     { --event-color: var(--accent);  border-left: 2px solid rgba(255,183,3,.5); }
.audit-item.ev-delete   { --event-color: var(--danger);  border-left: 2px solid rgba(255,92,92,.4); }
.audit-item.ev-payment  { --event-color: var(--success); border-left: 2px solid rgba(46,194,126,.5); }
.audit-item.ev-person   { --event-color: var(--info);    border-left: 2px solid rgba(76,201,240,.5); }

.audit-main { display: flex; align-items: flex-start; gap: 10px; }
.audit-icon { font-size: 17px; flex-shrink: 0; line-height: 1.5; }
.audit-body { flex: 1; min-width: 0; }
.audit-title { font-size: 14px; line-height: 1.45; }
.audit-title b { color: var(--text); }
.audit-title em { font-style: normal; color: var(--text); opacity: .9; }
.audit-detail { font-size: 12px; color: var(--text-dim); margin-top: 4px; line-height: 1.5; }
.audit-detail b { color: var(--text); font-weight: 600; }
.audit-right {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  flex-shrink: 0; min-width: 60px;
}
.audit-amount { font-weight: 700; font-size: 14px; white-space: nowrap; color: var(--text); }
.audit-amount.payment { color: var(--success); }
.audit-amount.edit { color: var(--accent); }
.audit-time { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.audit-pill {
  display: inline-block;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-dim);
  margin: 1px 2px 1px 0;
  white-space: nowrap;
}
.audit-pill.new { border-color: rgba(46,194,126,.4); color: var(--success); }

/* Actor selector in header */
.actor-container {
  display: flex; align-items: center; gap: 0;
}
.actor-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  width: auto;
  max-width: 130px;
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}
.actor-select:focus { border-color: var(--primary-2); }
@media (max-width: 480px) { .actor-select { max-width: 100px; font-size: 11px; } }

/* People */
.add-person-row { display: flex; gap: 8px; margin-bottom: 14px; }
.add-person-row input { flex: 1; }
.people-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 10px; }
.person-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.person-info { display: flex; align-items: center; gap: 10px; }

/* Modal */
.modal { position: fixed; inset: 0; display: none; z-index: 100; }
.modal.open { display: block; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.modal-content {
  position: relative;
  max-width: 560px; width: calc(100% - 24px);
  margin: 5vh auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header, .modal-footer {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-footer { border-bottom: none; border-top: 1px solid var(--border); gap: 8px; justify-content: flex-end; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer;
}
.modal-body { padding: 16px 18px; overflow-y: auto; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.form-row.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) {
  .form-row.two-col { grid-template-columns: 1fr; }
}

/* Split modes chips */
.split-modes { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.chip.active {
  background: var(--primary);
  color: white;
  border-color: transparent;
}

/* Participants list in modal */
.participants-list {
  display: flex; flex-direction: column;
  gap: 6px;
  max-height: 260px; overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--bg);
}
.participant-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 4px;
}
.participant-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
.participant-row .pname { display: flex; align-items: center; gap: 8px; }
.participant-row input[type="number"] {
  width: 110px; text-align: right;
  padding: 7px 9px;
}
.participant-row.disabled { opacity: .45; }

.split-summary {
  margin-top: 8px;
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-dim);
}
.split-summary strong { color: var(--text); }
.split-summary.warn strong { color: var(--danger); }
.split-summary.open strong { color: var(--accent); }
.split-summary.ok strong { color: var(--success); }
.calc-amount { color: var(--text-dim); font-size: 13px; min-width: 80px; text-align: right; }

/* Empty state */
.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty .big { font-size: 36px; margin-bottom: 8px; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: .25s ease;
  z-index: 200;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* Login screen */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 300;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(230,57,70,.25), transparent 60%),
    radial-gradient(700px 400px at -10% 110%, rgba(76,201,240,.18), transparent 60%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  max-width: 380px; width: 100%;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop .25s ease;
}
.login-logo { font-size: 56px; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-subtitle { margin: 0 0 22px; color: var(--text-dim); font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input[type="password"] { font-size: 16px; padding: 14px; text-align: center; letter-spacing: 2px; }
.login-btn { padding: 13px; font-size: 15px; }
.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}

/* Sync indicator */
.sync-indicator {
  display: inline-block;
  font-size: 10px;
  color: var(--success);
  transition: color .3s, transform .3s;
  user-select: none;
}
.sync-indicator.syncing { color: var(--info); animation: spin 1s linear infinite; }
.sync-indicator.error { color: var(--danger); }
.sync-indicator.offline { color: var(--text-dim); }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
