:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #6b7a90;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --income: #15803d;
  --expense: #b91c1c;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(26, 35, 50, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "PT Sans", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top left, #d8f3ef 0%, transparent 45%),
    radial-gradient(ellipse at bottom right, #e8eef7 0%, transparent 40%),
    var(--bg);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; color: var(--accent); }

.nav-links {
  display: flex;
  gap: 0.75rem;
  flex: 1;
  flex-wrap: wrap;
}
.nav-links a {
  color: var(--muted);
  font-weight: 500;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

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

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
}
.flash-success { border-color: #86efac; background: #f0fdf4; }
.flash-danger { border-color: #fca5a5; background: #fef2f2; }
.flash-warning { border-color: #fde68a; background: #fffbeb; }
.flash-info { border-color: #93c5fd; background: #eff6ff; }

.page-title {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}
.page-sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stats-secondary {
  grid-template-columns: repeat(4, 1fr);
  margin-top: -0.5rem;
}
.stats-now {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.stats-now .badge { font-size: 0.78rem; }
.dash-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.dash-tabs a {
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
}
.dash-tabs a.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
@media (max-width: 900px) {
  .stats-secondary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .stats { grid-template-columns: 1fr; }
  .stats-secondary { grid-template-columns: 1fr; }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
a.stat-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
a.stat-link:hover {
  border-color: var(--accent);
}
a.stat-link.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.stat-warn { color: var(--expense); }
.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}
.stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.stat-value-sm { font-size: 1.2rem; }
.stat-meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}
.stat-value.income { color: var(--income); }
.stat-value.expense { color: var(--expense); }

.chart-panel h2 { margin-bottom: 0.85rem; }
.chart-wrap {
  position: relative;
  height: 240px;
}
.chart-wrap-lg { height: 280px; }
.chart-wrap-donut { height: 260px; }
@media (max-width: 700px) {
  .chart-wrap, .chart-wrap-lg, .chart-wrap-donut { height: 220px; }
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
}
.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.toolbar-title {
  align-items: flex-end;
  margin-bottom: 1.25rem;
}
.month-picker {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 200px;
}
.month-picker label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.month-picker .form-control {
  min-width: 220px;
}


.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: none;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; color: #fff; }
.btn-secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover { color: var(--ink); background: #f8fafc; }
.btn-danger { background: var(--expense); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
table.data th,
table.data td {
  text-align: left;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.amount-income { color: var(--income); font-weight: 600; }
.amount-expense { color: var(--expense); font-weight: 600; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 0.85rem;
}
.dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  display: inline-block;
}

.auth-wrap {
  max-width: 420px;
  margin: 2rem auto;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}
.auth-card h1 {
  margin: 0 0 1.25rem;
  font-size: 1.35rem;
}

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.form-control {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.form-control:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.form-control.is-invalid { border-color: #f87171; }
.invalid-feedback {
  color: #b91c1c;
  font-size: 0.85rem;
  margin-top: 0.3rem;
}
.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.actions-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.muted { color: var(--muted); }
.empty {
  color: var(--muted);
  padding: 1rem 0;
  text-align: center;
}

.cat-bar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; }
.cat-row-link {
  text-decoration: none;
  color: inherit;
  padding: 0.45rem 0.5rem;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.cat-row-link:hover {
  background: #f8fafc;
  border-color: var(--border);
  text-decoration: none;
  color: inherit;
}
.cat-row-link.is-active {
  background: var(--accent-soft);
  border-color: #99f6e4;
}
a.badge.cat-link {
  text-decoration: none;
  color: inherit;
}
a.badge.cat-link:hover {
  outline: 2px solid var(--accent-soft);
}

tr.row-link {
  cursor: pointer;
}
tr.row-link:hover {
  background: #f8fafc;
}
.plan-strip {
  margin-bottom: 1.25rem;
}

.status-pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-pending { background: #eef2ff; color: #4338ca; }
.status-due { background: #fff7ed; color: #c2410c; }
.status-ok { background: #ecfdf5; color: #047857; }
.status-skip { background: #f1f5f9; color: #64748b; }

.template-toggle { display: inline-flex; margin: 0; }
.template-check {
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--accent);
  font-weight: 700;
}
.template-check.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.sms-item {
  border-top: 1px solid var(--border);
  padding: 0.85rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.sms-item:first-of-type { border-top: 0; padding-top: 0; }
.sms-body { font-size: 0.92rem; }
.sms-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
}
.sms-history-body { font-size: 0.85rem; max-width: 520px; }
.pair-code { font-size: 1.3rem; letter-spacing: 0.08em; }
.nav-badge {
  display: inline-block;
  min-width: 1.2rem;
  padding: 0 0.35rem;
  margin-left: 0.25rem;
  border-radius: 999px;
  background: #f97316;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2rem;
  text-align: center;
}

.security-report {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  overflow: auto;
  max-height: 70vh;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.due-card {
  border: 1px solid #fed7aa;
  background: linear-gradient(180deg, #fffbeb 0%, #fff 100%);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.due-card h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }
.due-item {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-top: 1px solid #fde68a;
}
.due-item:first-of-type { border-top: none; }

.cat-track {
  grid-column: 1 / -1;
  height: 8px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}
.cat-fill { height: 100%; border-radius: 999px; }

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.color-native {
  width: 3rem;
  height: 2.6rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.color-native::-webkit-color-swatch-wrapper { padding: 3px; }
.color-native::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}
.color-hex {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  letter-spacing: 0.02em;
}
.color-palette {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 0.4rem;
  margin-top: 0.75rem;
}
@media (max-width: 480px) {
  .color-palette { grid-template-columns: repeat(5, 1fr); }
}
.color-chip {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.color-chip:hover { transform: scale(1.06); }
.color-chip.is-selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent);
}
.color-hint {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
}
