:root {
  --primary:      #1a56db;
  --primary-dark: #1e429f;
  --accent:       #3f83f8;
  --sidebar-bg:   #111827;
  --sidebar-w:    240px;
  --bg:           #f3f4f6;
  --income:       #057a55;
  --income-bg:    #def7ec;
  --expense:      #c81e1e;
  --expense-bg:   #fde8e8;
  --profit:       #1e40af;
  --profit-bg:    #ebf5ff;
}

*, *::before, *::after { box-sizing: border-box; }
body { background: var(--bg); font-family: 'Segoe UI', system-ui, sans-serif; margin: 0; }

/* ── OVERLAYS ─────────────────────────────────── */
.full-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
#loadingOverlay { background: var(--sidebar-bg); }
.login-overlay  { background: linear-gradient(135deg, #111827 0%, #1e3a5f 100%); }

.login-card {
  background: #fff; border-radius: 16px;
  padding: 36px 32px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  animation: slideUp .3s ease;
}
@keyframes slideUp {
  from { opacity:0; transform:translateY(20px); }
  to   { opacity:1; transform:translateY(0); }
}
.login-logo     { font-size: 52px; text-align: center; }
.login-title    { font-size: 22px; font-weight: 700; text-align: center; color: var(--sidebar-bg); margin: 8px 0 2px; }
.login-subtitle { font-size: 13px; text-align: center; color: #6b7280; margin-bottom: 24px; }

/* ── SIDEBAR ─────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; z-index: 200;
  width: var(--sidebar-w); height: 100vh;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}
.brand-icon { font-size: 22px; }
.brand-text { font-size: 14px; font-weight: 700; color: #fff; line-height: 1.2; }

.sidebar-nav { list-style: none; padding: 8px 0; margin: 0; flex: 1; overflow-y: auto; }
.sidebar-nav li { margin: 1px 6px; }
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; color: #9ca3af; text-decoration: none; border-radius: 8px;
  font-size: 13.5px; border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-nav .nav-link:hover  { background: rgba(255,255,255,.07); color: #e5e7eb; }
.sidebar-nav .nav-link.active { background: rgba(59,130,246,.2); color: #fff; border-left-color: var(--accent); }

/* Группы в сайдбаре */
.nav-group-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  padding: 10px 15px 3px;
  margin-top: 4px;
  cursor: default;
  user-select: none;
}
.nav-group-item .nav-link { padding-left: 20px !important; }

.sidebar-footer {
  padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.08);
}
.user-info {
  display: flex; align-items: center; gap: 8px;
  color: #9ca3af; font-size: 11px; margin-bottom: 8px;
}
#userEmailDisplay { color: #e5e7eb; font-weight: 600; font-size: 12px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── TOPBAR ──────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: var(--sidebar-w); right: 0; z-index: 100;
  height: 56px; background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.topbar-menu-btn {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: #6b7280; padding: 4px; display: none;
}
.page-title { font-size: 17px; font-weight: 700; color: #111827; margin: 0; }

/* ── MAIN CONTENT ────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 72px 20px 24px;
  min-height: 100vh;
}

/* ── SECTIONS ────────────────────────────────── */
.content-section { display: none; }
.content-section.active { display: block; }

/* ── TOOLBAR ─────────────────────────────────── */
.section-toolbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 10px; margin-bottom: 16px;
}

/* ── TABLE WRAP ──────────────────────────────── */
.table-wrap {
  background: #fff; border-radius: 10px;
  border: 1px solid #e5e7eb;
  overflow-x: auto;
}
.table-wrap .table { margin: 0; font-size: 13px; }
.table-wrap .table thead th {
  background: #f9fafb; font-weight: 600; font-size: 12px;
  color: #6b7280; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 2px solid #e5e7eb; padding: 8px 10px; white-space: nowrap;
}
.table-wrap .table tbody td { padding: 7px 10px; vertical-align: middle; }
.table-wrap .table tbody tr:hover { background: #f8fafc; }

/* ── TOTALS BAR ──────────────────────────────── */
.totals-bar {
  background: #fff; border: 1px solid #e5e7eb; border-top: none;
  border-radius: 0 0 10px 10px; padding: 8px 14px;
  font-size: 13px; color: #374151;
}

/* ── STAT CARDS ──────────────────────────────── */
.stat-card {
  background: #fff; border-radius: 10px; padding: 16px 20px;
  border: 1px solid #e5e7eb;
}
.stat-label { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-card-income  { border-left: 4px solid var(--income);  }
.stat-card-income  .stat-value { color: var(--income); }
.stat-card-expense { border-left: 4px solid var(--expense); }
.stat-card-expense .stat-value { color: var(--expense); }
.stat-card-profit  { border-left: 4px solid var(--profit);  }
.stat-card-profit  .stat-value { color: var(--profit); }

/* ── АКТ НА СПИСАНИЕ — яркая кнопка ─────────── */
.writeoff-btn {
  font-size: 14px; font-weight: 700; letter-spacing: .03em;
  padding: 8px 18px; border-radius: 8px;
  box-shadow: 0 4px 14px rgba(220,38,38,.35);
  animation: pulse-red 2s infinite;
}
@keyframes pulse-red {
  0%,100% { box-shadow: 0 4px 14px rgba(220,38,38,.35); }
  50%      { box-shadow: 0 4px 20px rgba(220,38,38,.6); }
}

/* ── TEMPLATES GRID ──────────────────────────── */
.templates-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px; padding-top: 4px;
}
.template-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 20px 16px; text-align: center;
  transition: box-shadow .15s, transform .15s;
}
.template-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); transform: translateY(-2px); }
.template-icon { font-size: 40px; margin-bottom: 8px; }
.template-name { font-weight: 600; font-size: 14px; color: #111827; margin-bottom: 4px; }
.template-type { font-size: 11px; color: #6b7280; margin-bottom: 4px; }

/* ── MODALS ──────────────────────────────────── */
.modal-header { border-bottom: 1px solid #e5e7eb; }
.modal-footer { border-top: 1px solid #e5e7eb; }
.form-label.small { font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 3px; }

/* ── BADGES ──────────────────────────────────── */
.badge { font-size: 10.5px; font-weight: 600; }

/* ── RESPONSIVE: MOBILE ──────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { left: 0; }
  .topbar-menu-btn { display: block; }
  .main-content { margin-left: 0; padding: 68px 12px 20px; }
  .section-toolbar { flex-direction: column; }
  .writeoff-btn { font-size: 12px; padding: 6px 12px; }
}

/* ── SCROLLBAR ────────────────────────────────── */
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }
