:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e7ecf3;
  --muted: #8b98a8;
  --accent: #fc3f1d;
  --accent-hover: #ff5533;
  --green: #3dd68c;
  --border: #2d3a4d;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #0f1419 0%, #162032 100%);
  color: var(--text);
  min-height: 100vh;
}

a { color: #6eb6ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: rgba(26, 35, 50, 0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.nav-links {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.nav-links a { color: var(--muted); }
.nav-links a:hover { color: var(--text); }

.inline { display: inline; margin: 0; }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.link-btn:hover { color: var(--text); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

h1 { margin: 0 0 0.5rem; font-size: 1.75rem; }
h2 { margin: 2rem 0 1rem; font-size: 1.25rem; }

.muted { color: var(--muted); }

.card, .auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.auth-card {
  max-width: 420px;
  margin: 4rem auto;
}

.form label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.form input,
.form select,
.form textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font: inherit;
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  color: var(--text) !important;
}

.checkbox input { width: auto; margin: 0; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  border: none;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.alert-error {
  background: rgba(252, 63, 29, 0.15);
  border: 1px solid rgba(252, 63, 29, 0.4);
}

.alert-success {
  background: rgba(61, 214, 140, 0.12);
  border: 1px solid rgba(61, 214, 140, 0.35);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }
.stat-small { font-size: 0.95rem; font-weight: 500; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.table th,
.table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

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

.actions {
  display: flex;
  gap: 0.75rem;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-green { background: rgba(61, 214, 140, 0.15); color: var(--green); }
.badge-gray { background: rgba(139, 152, 168, 0.15); color: var(--muted); }

code {
  background: var(--surface2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.goals-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1rem 0;
}

.goal-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--surface2);
  cursor: pointer;
}

.goal-item input { margin-top: 0.25rem; }
.goal-item strong { display: block; }
.goal-item .muted { font-size: 0.8rem; }

.preview-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  line-height: 1.5;
}

.filters-card {
  margin-bottom: 1.5rem;
}

.filters-form {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.filters-form label {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.filters-form input[type="date"] {
  display: block;
  margin-top: 0.35rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font: inherit;
}

.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.table-wrap {
  overflow-x: auto;
}

.analytics-table th,
.analytics-table td {
  white-space: nowrap;
}

.row-error td {
  background: rgba(252, 63, 29, 0.06);
}

.link-btn-danger {
  color: #ff7a66 !important;
}

.link-btn-danger:hover {
  color: #ff9988 !important;
}

.balance-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.balance-low {
  color: #ff7a66;
  font-weight: 600;
}

.balance-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fc3f1d;
  flex-shrink: 0;
}

.balance-error {
  color: var(--muted);
  font-size: 0.8rem;
}

.budget-weekly {
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.form-hint {
  margin: -0.5rem 0 1rem;
  font-size: 0.85rem;
}

.analytics-table td.cpa-high {
  background: rgba(252, 63, 29, 0.22);
  color: #ffb3a6;
  font-weight: 600;
}

.analytics-table td.cpa-medium {
  background: rgba(255, 193, 7, 0.18);
  color: #ffd966;
  font-weight: 600;
}

.analytics-table td.cpa-low {
  background: rgba(61, 214, 140, 0.15);
  color: #8ef0c0;
  font-weight: 600;
}

.budget-pacing-card {
  margin-bottom: 1.5rem;
}

.budget-pacing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.budget-pacing-header .chart-title {
  margin: 0;
}

.budget-pacing-grid {
  margin-bottom: 0.75rem;
}

.budget-pacing-hint {
  margin: 0;
  font-size: 0.85rem;
}

.pace-badge {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.pace-badge.pace-ok {
  background: rgba(61, 214, 140, 0.18);
  color: #8ef0c0;
}

.pace-badge.pace-over {
  background: rgba(252, 63, 29, 0.18);
  color: #ffb3a6;
}

.pace-badge.pace-under {
  background: rgba(110, 182, 255, 0.18);
  color: #9ecaff;
}

.pace-badge.pace-none {
  background: rgba(139, 152, 168, 0.18);
  color: var(--muted);
}

.pace-deviation.pace-ok {
  color: #8ef0c0;
}

.pace-deviation.pace-over {
  color: #ffb3a6;
}

.pace-deviation.pace-under {
  color: #9ecaff;
}

.client-link {
  color: var(--text);
  text-decoration: none;
}

.client-link:hover {
  color: #6eb6ff;
  text-decoration: underline;
}

.breadcrumb {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.summary-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.summary-value {
  font-size: 1.35rem;
}

.summary-sub {
  font-size: 0.8rem;
}

.chart-card {
  margin-bottom: 1.5rem;
}

.chart-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.chart-wrap {
  position: relative;
}

@media (max-width: 640px) {
  .container { padding: 1rem; }
  .nav { padding: 0.75rem 1rem; flex-direction: column; gap: 0.75rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
