:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ee;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --primary: #5b5bd6;
  --primary-soft: #eef0ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --neutral: #9ca3af;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: auto; height: 36px; border-radius: 6px;
  background: #0b1220; padding: 4px 8px;
  display: block; object-fit: contain;
}
.brand-title { font-weight: 600; font-size: 17px; }
.brand-subtitle { font-size: 12px; color: var(--text-muted); }

nav { display: flex; gap: 4px; }
nav button {
  background: transparent; border: none;
  padding: 8px 14px; border-radius: 8px;
  font: inherit; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s;
}
nav button:hover { background: var(--surface-2); color: var(--text); }
nav button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

main { max-width: 1180px; margin: 28px auto; padding: 0 32px; }

.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
  box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  margin-bottom: 20px;
}
.filter-bar label { font-size: 13px; color: var(--text-muted); margin-right: 4px; }
.filter-bar input[type=date] {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font: inherit; color: var(--text); background: var(--surface);
}
.preset {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px; font-size: 12px; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s;
}
.preset:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary); color: white; border: none;
  padding: 8px 16px; border-radius: 8px; font: inherit; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.btn-primary:hover { filter: brightness(1.05); }
.grow { flex: 1; }

.row-delete {
  background: transparent; color: #991b1b; border: 1px solid #fecaca;
  padding: 4px 10px; border-radius: 6px; font: inherit; font-size: 12px;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.row-delete:hover { background: #fee2e2; border-color: #f87171; }
.row-actions { text-align: right; width: 40px; }
.row-trash {
  background: transparent; color: var(--text-muted); border: none;
  padding: 4px 8px; border-radius: 6px; font: inherit; font-size: 16px;
  line-height: 1; cursor: pointer; opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
tbody tr:hover .row-trash, .row-trash:focus { opacity: 1; }
.row-trash:hover { background: #fee2e2; color: #991b1b; }
.sub-actions { margin-top: 10px; text-align: right; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-title { font-weight: 600; }
.panel-meta { font-size: 13px; color: var(--text-muted); display: flex; gap: 0; align-items: baseline; }
.panel-meta > span:first-child { color: var(--text); font-weight: 600; }
.panel-meta-sep { padding: 0 2px; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 20px; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 20px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; text-align: right; font-weight: 500; }
.currency { color: var(--text-muted); font-size: 12px; margin-left: 4px; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.pill.planned { background: #e0e7ff; color: #4338ca; }
.pill.paid { background: #d1fae5; color: #065f46; }
.pill.partially_paid { background: #fef3c7; color: #92400e; }
.pill.failed { background: #fee2e2; color: #991b1b; }
.pill.cancelled { background: #f3f4f6; color: #6b7280; }
.pill.refunded { background: #ede9fe; color: #6d28d9; }

.status-select {
  padding: 3px 8px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase;
  cursor: pointer; appearance: none; -webkit-appearance: none;
}
.status-select.planned { background: #e0e7ff; color: #4338ca; }
.status-select.paid { background: #d1fae5; color: #065f46; }
.status-select.partially_paid { background: #fef3c7; color: #92400e; }
.status-select.failed { background: #fee2e2; color: #991b1b; }
.status-select.cancelled { background: #f3f4f6; color: #6b7280; }
.status-select.refunded { background: #ede9fe; color: #6d28d9; }
.status-select option { text-transform: none; color: var(--text); background: var(--surface); }

.empty { padding: 60px 20px; text-align: center; color: var(--text-muted); }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 6px; font-size: 15px; }

.stat-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.05em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.sub-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
.sub-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.sub-title { font-weight: 600; font-size: 15px; }
.sub-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); }
.sub-amount { font-size: 22px; font-weight: 700; color: var(--text); }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--danger); color: white;
  padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
  opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .app-header { padding: 14px 16px; flex-direction: column; align-items: flex-start; gap: 12px; }
  main { padding: 0 16px; }
  nav { width: 100%; overflow-x: auto; }
}

/* ---- Login overlay ------------------------------------------------------- */

.login-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.6);
  z-index: 1000;
}

.login-card {
  background: var(--card, white);
  border-radius: 12px;
  padding: 28px 32px;
  width: min(420px, 92vw);
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  display: flex; flex-direction: column; gap: 16px;
}

.login-title {
  font-size: 1.2rem; font-weight: 600;
}

.login-error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger, #dc2626);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.85rem; color: var(--muted, #64748b); }
.form-hint  { font-size: 0.75rem; color: var(--muted, #94a3b8); }

.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  font-size: 1rem;
}

.btn-secondary {
  background: transparent;
  color: var(--muted, #64748b);
  border: 1px solid var(--border, #e2e8f0);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  margin-left: 8px;
}
.btn-secondary:hover { background: var(--surface-2, #f1f5f9); }

/* ---- Add expense form --------------------------------------------------- */

.add-expense {
  max-width: 640px;
  margin: 24px auto;
  padding: 24px;
  background: var(--card, white);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  display: flex; flex-direction: column; gap: 16px;
}

.add-expense h2 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 600; }

.add-expense input,
.add-expense select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  font-size: 1rem;
  background: white;
}

.form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}

.form-actions {
  display: flex; justify-content: flex-end; margin-top: 8px;
}

.form-flash {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
}

/* ---- Dictionaries ------------------------------------------------------- */

.dictionaries {
  max-width: 720px;
  margin: 24px auto;
  padding: 24px;
  background: var(--card, white);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  display: flex; flex-direction: column; gap: 24px;
}

.dictionaries h2 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.dict-section h3 { margin: 0 0 10px; font-size: 1rem; font-weight: 600; }

.dict-list {
  margin: 0 0 12px; padding: 0;
  border: 1px solid var(--border, #e2e8f0); border-radius: 8px;
  max-height: 260px; overflow: auto;
}
.dict-list-item {
  padding: 8px 12px; border-bottom: 1px solid var(--border, #f1f5f9);
  font-size: 0.95rem;
}
.dict-list-item:last-child { border-bottom: none; }

.dict-add-row { display: flex; gap: 8px; align-items: center; }
.dict-add-row input,
.dict-add-row select {
  padding: 9px 11px; border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px; font-size: 0.95rem; background: white;
}
.dict-add-row input { flex: 1; }

/* ---- Add: expense/subscription segmented toggle ------------------------- */

.segmented { display: flex; gap: 0; margin-bottom: 8px; }
.seg-button {
  flex: 1; padding: 9px 14px; cursor: pointer;
  border: 1px solid var(--border, #e2e8f0); background: white;
  font-size: 0.95rem; color: var(--muted, #64748b);
}
.seg-button:first-child { border-radius: 6px 0 0 6px; }
.seg-button:last-child  { border-radius: 0 6px 6px 0; border-left: none; }
.seg-button.active {
  background: var(--primary, #6366f1); color: white;
  border-color: var(--primary, #6366f1);
}

/* ---- Members directory additions ------------------------------------- */
.brand-title {
  font-weight: 600;
  font-size: 16px;
  margin-left: 8px;
}

.uuid {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #6b7280;
  word-break: break-all;
}

.detail { max-width: 760px; margin: 24px auto; }
.detail .panel { padding: 28px 32px; }
.detail h2 { margin: 0 0 20px; font-size: 22px; }

.detail-row {
  display: flex;
  gap: 28px;
  align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid #eef0f3;
}
.detail-row:last-child { border-bottom: none; }

.detail-label {
  flex: 0 0 170px;
  color: #6b7280;
  font-size: 13px;
}

.detail-row span:last-child { font-size: 15px; }

.detail .form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.clickable-row { cursor: pointer; }

/* ---- Access: service cards + grant bar ---------------------------------- */
.clickable-card { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.clickable-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(91, 91, 214, 0.12); }

.service-logo-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 64px; margin-bottom: 6px;
}
.service-logo {
  max-height: 56px; max-width: 100%;
  object-fit: contain; display: block;
}

.detail .panel { padding: 0; }
.detail .panel-header { padding: 16px 20px; }
.detail-desc { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }

.grant-bar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 20px;
}
.grant-bar select {
  flex: 1;
  padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 6px; font: inherit; background: white;
}
