/* ─── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Sora', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1e293b;
  background: #f1f5f9;
}

/* ─── Shell & state views ────────────────────────────────────────────────── */
.private-shell {
  min-height: 100vh;
}

.private-state {
  display: none;
}

.private-state.is-visible {
  display: block;
}

.private-shell[data-view="loading"],
.private-shell[data-view="signedout"],
.private-shell[data-view="denied"] {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.private-shell[data-view="loading"] .private-state,
.private-shell[data-view="signedout"] .private-state,
.private-shell[data-view="denied"] .private-state {
  display: none;
}

.private-shell[data-view="loading"] #stateLoading { display: block; }
.private-shell[data-view="signedout"] #stateSignedOut { display: block; }
.private-shell[data-view="denied"] #stateDenied { display: block; }

.private-loading,
.private-signedout,
.private-error {
  width: min(420px, calc(100vw - 32px));
  padding: 32px;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.10);
  text-align: center;
}

.private-loading p {
  margin: 0;
  color: #64748b;
  font-size: 0.9rem;
}

.private-error h2 {
  margin: 0 0 10px;
  font-size: 1.15rem;
  color: #0f172a;
}

.private-error p {
  margin: 0;
  color: #64748b;
  font-size: 0.875rem;
  line-height: 1.5;
}

.private-google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #1e293b;
  font: 600 0.875rem 'Sora', system-ui, sans-serif;
  cursor: pointer;
  transition: background 150ms, box-shadow 150ms;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.private-google-btn:hover {
  background: #f8fafc;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.private-google-btn[data-busy="true"] {
  opacity: 0.7;
  cursor: wait;
}

.private-google-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ─── App layout ─────────────────────────────────────────────────────────── */
.private-app.is-visible {
  display: block;
}

.priv-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.priv-sidebar {
  background: #0f172a;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.priv-sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.priv-brand-kicker {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #94a3b8;
}

.priv-brand-name {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.01em;
}

.priv-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 0;
}

.priv-nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.priv-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font: 500 0.875rem 'Sora', system-ui, sans-serif;
  cursor: pointer;
  text-align: left;
  transition: background 140ms, color 140ms;
}

.priv-nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
}

.priv-nav-item.is-active {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  font-weight: 600;
}

.priv-nav-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.priv-nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.priv-sidebar-foot {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.priv-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* ─── Main area ──────────────────────────────────────────────────────────── */
.priv-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.priv-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.priv-topbar-left {
  min-width: 0;
}

.priv-topbar-left h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
}

.priv-topbar-sub {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: #64748b;
}

.priv-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.priv-user-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #334155;
  font-size: 0.8rem;
  font-weight: 600;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.priv-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: 600 0.875rem 'Sora', system-ui, sans-serif;
  cursor: pointer;
  transition: background 140ms, opacity 140ms, box-shadow 140ms;
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: #3b82f6;
  color: #ffffff;
  border-color: #3b82f6;
}

.btn-primary:hover:not(:disabled) {
  background: #2563eb;
  border-color: #2563eb;
}

.btn-danger {
  background: #ef4444;
  color: #ffffff;
  border-color: #ef4444;
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
}

.btn-secondary {
  background: #ffffff;
  color: #374151;
  border-color: #d1d5db;
}

.btn-secondary:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #9ca3af;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

/* ─── Stat grid ──────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-card__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.1;
}

.stat-card--danger .stat-card__value { color: #ef4444; }
.stat-card--success .stat-card__value { color: #22c55e; }
.stat-card--warning .stat-card__value { color: #f59e0b; }
.stat-card--info .stat-card__value { color: #3b82f6; }

.stat-card__sub {
  font-size: 0.75rem;
  color: #94a3b8;
}

/* ─── Section card ───────────────────────────────────────────────────────── */
.section-card {
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.section-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #f1f5f9;
}

.section-card__title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
}

.section-card__sub {
  font-size: 0.78rem;
  color: #64748b;
  margin: 2px 0 0;
}

.section-card__body {
  padding: 0;
}

.section-card__body--padded {
  padding: 16px 20px;
}

/* ─── Data table ─────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

.data-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background 120ms;
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.data-table td {
  padding: 12px 16px;
  color: #334155;
  vertical-align: middle;
}

.data-table td.td-actions {
  text-align: right;
  white-space: nowrap;
}

.data-table td.td-actions .btn + .btn {
  margin-left: 6px;
}

.data-table td.td-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge--privat    { background: #dbeafe; color: #1d4ed8; }
.badge--inkasso   { background: #ffedd5; color: #c2410c; }
.badge--gericht   { background: #fee2e2; color: #b91c1c; }
.badge--einnahme  { background: #dcfce7; color: #15803d; }
.badge--ausgabe   { background: #fee2e2; color: #b91c1c; }
.badge--laufend   { background: #fef9c3; color: #a16207; }
.badge--monatlich { background: #e0f2fe; color: #0369a1; }
.badge--quartalsweise { background: #f0fdf4; color: #166534; }
.badge--jaehrlich { background: #faf5ff; color: #7e22ce; }

/* ─── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms;
}

.modal-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.20);
  transform: translateY(12px) scale(0.98);
  transition: transform 180ms;
  overflow: hidden;
}

.modal-overlay.is-open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
}

.modal-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 140ms, color 140ms;
  flex-shrink: 0;
}

.modal-close-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-row label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #374151;
}

.form-row input,
.form-row select,
.form-row textarea {
  padding: 8px 11px;
  border-radius: 7px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  font: 0.875rem 'Sora', system-ui, sans-serif;
  color: #1e293b;
  transition: border-color 140ms, box-shadow 140ms;
  width: 100%;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-row textarea {
  resize: vertical;
  min-height: 72px;
}

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

/* ─── Tab bar ────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #f1f5f9;
  border-radius: 10px;
  width: fit-content;
}

.tab-btn {
  padding: 7px 18px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: #64748b;
  font: 600 0.83rem 'Sora', system-ui, sans-serif;
  cursor: pointer;
  transition: background 140ms, color 140ms, box-shadow 140ms;
}

.tab-btn:hover:not(.is-active) {
  background: rgba(255, 255, 255, 0.7);
  color: #334155;
}

.tab-btn.is-active {
  background: #ffffff;
  color: #1e293b;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.10);
}

/* ─── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.875rem;
}

/* ─── Dashboard layout ───────────────────────────────────────────────────── */
.dashboard-tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ─── Finanzen tabs content ──────────────────────────────────────────────── */
.finanzen-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ─── Assistant module ───────────────────────────────────────────────────── */
.assistant-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.assistant-form label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #374151;
}

.assistant-form textarea {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  font: 0.875rem 'Sora', system-ui, sans-serif;
  color: #1e293b;
  min-height: 96px;
  resize: vertical;
  transition: border-color 140ms, box-shadow 140ms;
  width: 100%;
}

.assistant-form textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.assistant-reply {
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  white-space: pre-wrap;
  font-size: 0.875rem;
  line-height: 1.6;
}

.assistant-reply.is-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-tables {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .priv-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
  }

  .priv-sidebar {
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0;
  }

  .priv-sidebar-brand {
    padding: 12px 16px;
    border-bottom: none;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .priv-brand-kicker {
    display: none;
  }

  .priv-brand-name {
    font-size: 0.95rem;
  }

  .priv-nav {
    flex: 1;
    padding: 6px 8px;
    overflow: visible;
  }

  .priv-nav ul {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .priv-nav-item {
    padding: 8px 10px;
    white-space: nowrap;
    font-size: 0.8rem;
  }

  .priv-sidebar-foot {
    display: none;
  }

  .priv-main {
    overflow: visible;
  }

  .priv-topbar {
    padding: 12px 16px;
    position: static;
  }

  .priv-content {
    padding: 16px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .stat-card__value {
    font-size: 1.2rem;
  }

  .form-group {
    grid-template-columns: 1fr;
  }

  .finanzen-controls {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .priv-topbar-right {
    gap: 6px;
  }

  .priv-user-chip {
    max-width: 100px;
  }
}
