/* ============================================================
   Фонограма CRM — main.css  (повний редизайн)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --primary:        #5b21b6;
  --primary-light:  #7c3aed;
  --primary-soft:   #ede9fe;
  --primary-dark:   #4c1d95;

  --bg:             #f1f3f9;
  --surface:        #ffffff;
  --surface-2:      #f7f8fc;
  --border:         #e4e7f0;
  --border-light:   #eef0f7;

  --text:           #111827;
  --text-muted:     #6b7280;
  --text-light:     #9ca3af;

  --sidebar-bg:     #0f0d22;
  --sidebar-w:      230px;
  --topbar-h:       60px;

  --radius:         14px;
  --radius-sm:      10px;
  --radius-xs:      7px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:     0 4px 12px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md:  0 12px 32px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.05);

  --t: 0.15s ease;

  --c-danger:  #dc2626;
  --c-warning: #d97706;
  --c-success: #059669;
  --c-info:    #2563eb;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: rgba(91,33,182,0.15); }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

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

.sidebar-logo {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.logo-text {
  font-size: 0.93rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 11px;
  border-radius: var(--radius-xs);
  color: rgba(255,255,255,0.52);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background var(--t), color var(--t);
  margin-bottom: 2px;
  text-decoration: none;
  white-space: nowrap;
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.65; transition: opacity var(--t); }
.nav-item:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.88); text-decoration: none; }
.nav-item:hover svg { opacity: 1; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.active svg { opacity: 1; }

.nav-divider { height: 1px; background: rgba(255,255,255,0.07); margin: 6px 0; }
.nav-logout:hover { background: rgba(220,38,38,0.18); color: #fca5a5; }

/* ── Main content ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar — FIXED height, never shifts ── */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  max-height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-xs);
  transition: background var(--t);
}
.sidebar-toggle:hover { background: var(--bg); }

.page-title {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

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

.topbar-user {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.79rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* ── Global stats — stable, not sticky ── */
.global-stats-shell {
  padding: 16px 24px 0;
  flex-shrink: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  margin: 0;
  position: static;
  top: auto;
  z-index: auto;
}

.global-stats-header,
.global-stats-kicker,
.global-stats-title { display: none !important; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 0;
  align-items: stretch;
}

.stats-grid-global {}

/* Fixed-height stat cards — never resize between pages */
.stat-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px 11px;
  box-shadow: var(--shadow-sm);
  height: 108px;
  display: flex;
  flex-direction: column;
}

.stat-card::before {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--stat-accent, var(--primary));
}

/* Remove the decorative circle */
.stat-card::after { display: none; }

.stat-card .stat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.stat-chip {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--stat-accent, var(--primary));
  text-transform: uppercase;
  padding: 0;
  background: none;
  border-radius: 0;
}

.stat-icon { display: none; }

.stat-card .stat-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.2;
  min-height: 0;
  margin-bottom: 5px;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.03em;
  flex: 1;
  display: flex;
  align-items: flex-end;
}

.stat-card .stat-sub {
  font-size: 0.66rem;
  color: var(--text-light);
  margin-top: 3px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-card.accent  { --stat-accent: var(--primary); }
.stat-card.danger  { --stat-accent: var(--c-danger); }
.stat-card.warning { --stat-accent: var(--c-warning); }
.stat-card.success { --stat-accent: var(--c-success); }
.stat-card.info    { --stat-accent: var(--c-info); }

.stat-card-link {
  display: flex;
  flex-direction: column;
  color: inherit;
  text-decoration: none;
  transition: box-shadow var(--t), border-color var(--t), transform var(--t);
}
.stat-card-link:hover {
  text-decoration: none;
  box-shadow: var(--shadow);
  border-color: rgba(91,33,182,0.22);
  transform: translateY(-1px);
}

/* ── Content body ── */
.content-body {
  padding: 16px 24px 28px;
  flex: 1;
  min-width: 0;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 52px;
}

.card-title { font-size: 0.89rem; font-weight: 700; letter-spacing: -0.01em; }
.card-body { padding: 18px; }

/* ── Page actions / toolbar ── */
.page-actions,
.list-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  min-height: 40px;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
}

.page-actions-tight { justify-content: flex-start; }
.page-actions:not(.page-actions-tight) { justify-content: space-between; }

/* ── Filters bar ── */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  align-items: flex-end;
}

.filters-bar .form-group { flex: 1 1 160px; min-width: 0; }
.filters-bar .form-group label { font-size: 0.72rem; color: var(--text-muted); }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
.table-wrap table { min-width: 920px; }

table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }

thead th {
  padding: 9px 14px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border-light); transition: background var(--t); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }
tbody td { padding: 9px 14px; vertical-align: middle; color: var(--text); }

.td-muted { color: var(--text-muted); }
.td-mono  { font-family: 'JetBrains Mono', monospace; font-size: 0.81rem; font-variant-numeric: tabular-nums; }
.nowrap   { white-space: nowrap; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  font-size: 0.71rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success   { background: #d1fae5; color: #065f46; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-info      { background: #dbeafe; color: #1e40af; }
.badge-purple    { background: var(--primary-soft); color: var(--primary-dark); }
.badge-cyan      { background: #cffafe; color: #164e63; }
.badge-orange    { background: #ffedd5; color: #9a3412; }
.badge-secondary { background: #f3f4f6; color: #374151; }

/* ── Buttons — consistent 40px / 34px ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--t), box-shadow var(--t), transform var(--t), border-color var(--t), color var(--t);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
  flex-shrink: 0;
}

.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary-dark); box-shadow: 0 1px 3px rgba(91,33,182,0.22); }
.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); text-decoration: none; color: #fff; transform: translateY(-1px); box-shadow: 0 4px 10px rgba(91,33,182,0.28); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--bg); border-color: #c4c9d8; text-decoration: none; transform: translateY(-1px); }

.btn-danger { background: var(--surface); color: var(--c-danger); border-color: #fecaca; }
.btn-danger:hover { background: #fff5f5; border-color: #fca5a5; text-decoration: none; transform: translateY(-1px); }

.btn-success { background: var(--c-success); color: #fff; border-color: var(--c-success); }
.btn-success:hover { background: #047857; text-decoration: none; color: #fff; }

.btn-sm { height: 34px; min-height: 34px; padding: 0 12px; font-size: 0.79rem; border-radius: var(--radius-xs); }
.btn-icon { width: 34px; min-width: 34px; padding: 0; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full-width { grid-column: 1 / -1; }

label { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.required-mark { color: var(--c-danger); margin-left: 2px; }

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="url"],
select,
textarea {
  width: 100%;
  height: 40px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--t), box-shadow var(--t);
  outline: none;
  line-height: 40px;
}

textarea { height: auto; min-height: 100px; resize: vertical; line-height: 1.5; padding: 10px 12px; }

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,33,182,0.1);
}

.form-hint { font-size: 0.73rem; color: var(--text-muted); margin-top: 2px; }

.checkbox-group { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 0.84rem; }
.checkbox-group input[type="checkbox"] { width: auto; height: auto; min-height: auto; cursor: pointer; }

/* ── Section title ── */
.section-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }

.tab-btn {
  padding: 8px 16px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--t), border-color var(--t);
  white-space: nowrap;
  font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }

.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; }

.modal-header { padding: 15px 20px 13px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.modal-title { font-size: 0.93rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); padding: 2px 6px; border-radius: 4px; line-height: 1; }
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 18px 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Alerts ── */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 0.84rem; font-weight: 500; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fca5a5; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ── Summary ── */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.summary-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 14px; }
.summary-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 3px; font-weight: 600; }
.summary-value { font-size: 1.1rem; font-weight: 700; }

/* ── Urgency ── */
.urgency-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c-danger); margin-right: 5px; flex-shrink: 0; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state svg { width: 44px; height: 44px; opacity: 0.22; margin-bottom: 10px; }
.empty-state p { font-size: 0.86rem; }

/* ── Actions col ── */
.actions-col { display: flex; gap: 5px; align-items: center; white-space: nowrap; }

/* ── Row highlights ── */
.row-overdue td:first-child { border-left: 3px solid var(--c-danger); }
.row-today   td:first-child { border-left: 3px solid var(--c-warning); }

/* ── Finance totals ── */
.finance-totals {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 18px;
}

.finance-total-item { flex: 1; padding: 14px 18px; border-right: 1px solid var(--border); }
.finance-total-item:last-child { border-right: none; }
.finance-total-item .label { font-size: 0.69rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600; margin-bottom: 3px; }
.finance-total-item .value { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
.finance-total-item.green .value { color: var(--c-success); }
.finance-total-item.red   .value { color: var(--c-danger); }
.finance-total-item.blue  .value { color: var(--c-info); }

/* ── Client totals ── */
.client-totals { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.client-total-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 16px; min-width: 140px; }
.client-total-item .label { font-size: 0.69rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.client-total-item .value { font-size: 1.05rem; font-weight: 700; margin-top: 2px; }

/* ── Settings ── */
.settings-section { margin-bottom: 28px; }
.settings-list { list-style: none; }
.settings-list li { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border-light); font-size: 0.86rem; gap: 10px; min-height: 44px; }
.settings-list li:last-child { border-bottom: none; }

/* ── History ── */
.history-list { list-style: none; }
.history-item { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-light); font-size: 0.82rem; }
.history-item:last-child { border-bottom: none; }
.history-date { color: var(--text-muted); white-space: nowrap; font-size: 0.76rem; min-width: 118px; }
.history-desc { color: var(--text); }

/* ── Login ── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--sidebar-bg) 0%, #2d1f6e 100%); }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px 32px; width: 100%; max-width: 380px; box-shadow: var(--shadow-md); }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo-text { font-size: 1.1rem; font-weight: 800; color: var(--primary); }
.login-box h2 { font-size: 0.96rem; font-weight: 600; margin-bottom: 20px; text-align: center; color: var(--text); }

/* ── Misc ── */
.inline-create-panel { margin-top: 16px; padding-top: 4px; border-top: 1px solid var(--border); }
.link-icon { display: inline-flex; align-items: center; color: var(--primary); font-size: 0.81rem; gap: 4px; }
.link-icon:hover { text-decoration: underline; }

input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0.45; cursor: pointer; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 199; }

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

/* ── Responsive: 900px ── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: flex; }

  .global-stats-shell { padding: 12px 16px 0; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat-card { height: 100px; }

  .content-body { padding: 14px 16px 24px; }
  .form-grid { grid-template-columns: 1fr; }
  .finance-totals { flex-wrap: wrap; }
  .finance-total-item { flex: 1 1 45%; border-bottom: 1px solid var(--border); }
}

/* ── Responsive: 560px ── */
@media (max-width: 560px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { height: auto; min-height: 92px; }
  .stat-card .stat-value { font-size: 1.45rem; }
  .topbar { padding: 0 14px; }
  table { font-size: 0.79rem; }
  tbody td, thead th { padding: 8px 10px; }
  .login-box { padding: 26px 20px; }
  .page-actions .btn, .page-actions-tight .btn { width: 100%; }
}

@media (max-width: 480px) {
  .filters-bar .form-group { flex: 1 1 130px; }
}
