/* ===== FinanceTracker — CSS ===== */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --success-bg: #f0fdf4;
  --warning-bg: #fef3c7;
  --info-bg: #eff6ff;
  --error-bg: #fef2f2;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #3b82f6;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ===== Утилиты ===== */
.hidden { display: none !important; }
.right { text-align: right; }
.muted { color: var(--muted); font-size: 0.875rem; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.end { justify-content: flex-end; }
.inline-search {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.875rem; width: 240px;
}

/* ===== Alert ===== */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 0.875rem; margin-top: 8px; }
.alert.error { background: var(--error-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert.success { background: var(--success-bg); color: #15803d; border: 1px solid #bbf7d0; }
.alert.info { background: var(--info-bg); color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ===== Auth ===== */
.auth-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.auth-card {
  background: var(--surface); border-radius: 12px; padding: 32px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow);
}
.brand {
  font-size: 1.5rem; font-weight: 700; margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
.brand-mark { font-size: 1.75rem; }
.brand.small { font-size: 1.1rem; }

/* Tabs */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab {
  flex: 1; padding: 10px; background: none; border: none; border-bottom: 2px solid transparent;
  margin-bottom: -2px; cursor: pointer; font-size: 0.95rem; color: var(--muted); transition: all .2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab:hover:not(.active) { color: var(--text); }

/* ===== Buttons ===== */
.btn {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font-size: 0.875rem; font-family: inherit;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-hover); }
.btn.ghost { background: transparent; border: none; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 4px 10px; font-size: 0.8rem; }
.btn.block { display: block; width: 100%; text-align: center; }

/* ===== App Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 16px 0; flex-shrink: 0;
}
.sidebar .brand { padding: 0 16px 16px; border-bottom: 1px solid #334155; margin-bottom: 8px; }
.nav { flex: 1; display: flex; flex-direction: column; padding-top: 8px; }
.nav-item {
  padding: 10px 16px; background: none; border: none; color: var(--sidebar-text);
  text-align: left; cursor: pointer; font-size: 0.9rem; font-family: inherit;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active { color: var(--sidebar-active); font-weight: 600; background: rgba(59,130,246,0.1); }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid #334155; }
.who { font-size: 0.85rem; margin-bottom: 6px; }
.content { flex: 1; padding: 24px; overflow-y: auto; }

/* ===== Pages ===== */
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.page-head h1 { font-size: 1.4rem; font-weight: 700; }

/* ===== Filters ===== */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input, .filters select {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.85rem; font-family: inherit;
}

/* ===== Segmented Control ===== */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  padding: 5px 12px; background: var(--surface); border: none; border-right: 1px solid var(--border);
  cursor: pointer; font-size: 0.8rem; font-family: inherit; color: var(--muted); transition: all .15s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active { background: var(--primary); color: #fff; }
.seg-btn:hover:not(.active) { background: #f1f5f9; }
.custom-range { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.custom-range.hidden { display: none; }

/* ===== KPIs ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.kpi-card.danger { border-left-color: var(--danger); }
.kpi-card.success { border-left-color: var(--success); }
.kpi-card h3 { font-size: 0.8rem; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.kpi-card .val { font-size: 1.5rem; font-weight: 700; }
.kpi-card .val.income { color: #15803d; }
.kpi-card .val.expense { color: var(--danger); }

/* ===== Cards ===== */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.card h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ===== Charts ===== */
.chart-box { position: relative; width: 100%; max-height: 320px; }
.chart-box canvas { width: 100% !important; height: 100% !important; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.legend-item { display: flex; align-items: center; gap: 4px; font-size: 0.8rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; cursor: pointer; user-select: none; }
.table th:hover { color: var(--text); }
.table tbody tr:hover { background: #f8fafc; }
.table .actions { display: flex; gap: 4px; }
.table .actions button { padding: 2px 6px; font-size: 0.75rem; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ===== Pager ===== */
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center;
  justify-content: center; background: rgba(0,0,0,0.4);
}
.modal-card {
  background: var(--surface); border-radius: 12px; padding: 24px;
  width: 90%; max-width: 440px; box-shadow: 0 4px 24px rgba(0,0,0,0.15);
}
.modal-card h2 { margin-bottom: 16px; }
.modal-card input, .modal-card select, .modal-card textarea {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.9rem; font-family: inherit; width: 100%;
}
.modal-card input[type="color"] { height: 40px; padding: 4px; cursor: pointer; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  background: var(--text); color: #fff; padding: 12px 20px;
  border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  font-size: 0.9rem; transition: opacity .3s;
}

/* ===== File Input ===== */
.file-label { display: inline-block; }
.file-label input[type="file"] { display: none; }

/* ===== Radio ===== */
.radio { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-size: 0.85rem; }

/* ===== Danger text ===== */
.danger-text { color: var(--danger); }

/* ===== Admin ===== */
.admin-body { background: #0f172a; color: #e2e8f0; }

/* ===== Form fields ===== */
label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.8rem; color: var(--muted); font-weight: 500;
}
label input, label select, label textarea {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.9rem; font-family: inherit; color: var(--text); background: var(--surface);
  width: 100%;
}
label input:focus, label select:focus, label textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
label input[type="color"] { padding: 3px; height: 40px; cursor: pointer; }
label.radio { flex-direction: row; align-items: center; font-size: 0.875rem; color: var(--text); }
label.radio input { width: auto; }
textarea { resize: vertical; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  background: var(--text); color: #fff; padding: 12px 20px;
  border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  font-size: 0.9rem; max-width: 420px;
}
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: #15803d; }

/* ===== Misc ===== */
.kpi-extra { font-size: 0.8rem; color: var(--muted); margin-top: 4px; line-height: 1.6; }
.err-list { margin: 6px 0 0 18px; font-size: 0.82rem; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 0.9rem; }
.dl dt { color: var(--muted); }
.dl dd { font-weight: 500; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
code {
  background: #f1f5f9; padding: 2px 6px; border-radius: 4px;
  font-size: 0.82em; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
}
.table.sortable th[data-sort]::after { content: ' ↕'; color: var(--border); }
.table.sortable th.sorted[data-dir="1"]::after { content: ' ↑'; color: var(--primary); }
.table.sortable th.sorted[data-dir="-1"]::after { content: ' ↓'; color: var(--primary); }
.chart-fallback {
  padding: 24px; text-align: center; border: 1px dashed var(--border);
  border-radius: var(--radius); font-size: 0.85rem;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Admin (тёмная тема) ===== */
.admin-body { background: #0f172a; color: #e2e8f0; }
.admin-body .card, .admin-body .auth-card, .admin-body .modal-card { background: #1e293b; color: #e2e8f0; }
.admin-body .table th { color: #94a3b8; border-bottom-color: #334155; }
.admin-body .table td { border-bottom-color: #334155; }
.admin-body .table tbody tr:hover { background: rgba(255,255,255,0.04); }
.admin-body .sidebar { background: #111827; }
.admin-body label { color: #94a3b8; }
.admin-body label input, .admin-body label select, .admin-body label textarea {
  background: #0f172a; border-color: #334155; color: #e2e8f0;
}
.admin-body .btn { background: #334155; border-color: #475569; color: #e2e8f0; }
.admin-body .btn:hover { background: #475569; }
.admin-body .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.admin-body .btn.ghost { background: transparent; border-color: transparent; }
.admin-body .seg { border-color: #475569; }
.admin-body .seg-btn { background: #0f172a; border-right-color: #475569; color: #94a3b8; }
.admin-body .seg-btn.active { background: var(--primary); color: #fff; }
.admin-body .filters input, .admin-body .filters select {
  background: #0f172a; border-color: #334155; color: #e2e8f0;
}
.admin-body .kpi-card h3 { color: #94a3b8; }
.admin-body .pager { border-top-color: #334155; }
.admin-body .muted { color: #94a3b8; }
.admin-body .inline-search { background: #0f172a; border-color: #334155; color: #e2e8f0; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; padding: 8px; flex-wrap: wrap; }
  .sidebar .brand { padding: 0 8px 0 0; border: none; margin: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; padding: 4px 0 0; }
  .nav-item { padding: 6px 10px; font-size: 0.8rem; }
  .sidebar-foot { padding: 4px 8px; border: none; }
  .content { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .inline-search { width: 100%; }
}
