:root,
:root[data-theme="dark"] {
  --bg: #0f1117;
  --panel: #161923;
  --panel-2: #1c202c;
  --border: #262b3a;
  --text: #e9eaf0;
  --text-dim: #9096a8;
  --accent: #7c5cfc;
  --accent-2: #9d7bff;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --radius: 12px;
}

:root[data-theme="light"] {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f1f2f8;
  --border: #e3e5ee;
  --text: #1a1d29;
  --text-dim: #656b7d;
  --accent: #7c5cfc;
  --accent-2: #6a45f5;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #d97706;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color .15s ease, color .15s ease;
}

a { color: inherit; text-decoration: none; }

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 20px; padding: 0 6px; }
.brand span { flex: 1; }
.brand-badge { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }

.theme-toggle {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1; padding: 0;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-icon-dark, .theme-icon-light { display: none; }
:root[data-theme="dark"] .theme-icon-dark { display: inline; }
:root[data-theme="light"] .theme-icon-light { display: inline; }

.workspace-pill { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: var(--radius); padding: 10px; margin-bottom: 18px; }
.workspace-avatar { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.workspace-name { font-size: 13px; font-weight: 600; }
.workspace-sub { font-size: 11px; color: var(--text-dim); }

.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin: 16px 10px 6px; }
.nav-link { display: block; padding: 9px 12px; border-radius: 9px; font-size: 14px; color: var(--text-dim); margin-bottom: 2px; }
.nav-link:hover { background: var(--panel-2); color: var(--text); }
.nav-link.active { background: rgba(124, 92, 252, .15); color: var(--accent-2); font-weight: 600; }

.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.user-pill { display: flex; align-items: center; gap: 10px; padding: 6px; margin-bottom: 6px; }
.user-avatar { width: 30px; height: 30px; border-radius: 8px; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.user-name { font-size: 13px; font-weight: 600; }
.user-sub { font-size: 11px; color: var(--text-dim); }
.link-btn { background: none; border: none; color: var(--text-dim); font-size: 12px; cursor: pointer; padding: 4px 8px; }
.link-btn:hover { color: var(--red); }

.content { flex: 1; padding: 28px 32px; max-width: 100%; overflow-x: hidden; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.period-tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.period-tabs a { padding: 7px 14px; border-radius: 7px; font-size: 13px; color: var(--text-dim); }
.period-tabs a.active { background: var(--accent); color: #fff; }

h1 { font-size: 24px; margin: 0 0 4px; }
.subtitle { color: var(--text-dim); font-size: 14px; margin: 0 0 20px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin-bottom: 10px; }
.kpi-value { font-size: 30px; font-weight: 700; margin-bottom: 6px; }
.kpi-change { font-size: 12px; color: var(--text-dim); }
.kpi-change.up { color: var(--green); }
.kpi-change.down { color: var(--red); }

.section-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.section-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }

.funnel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.funnel-bar-wrap { flex: 1; background: var(--panel-2); border-radius: 8px; height: 40px; display: flex; align-items: center; padding: 0 14px; font-weight: 600; font-size: 14px; overflow: hidden; }
.funnel-pct { width: 50px; text-align: right; color: var(--text-dim); font-size: 13px; }

.btn { background: var(--accent); color: #fff; border: none; padding: 10px 16px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent-2); }
.btn.secondary { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 12px; }

input, select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-size: 14px; font-family: inherit;
}
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field { margin-bottom: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 100px; font-size: 11px; font-weight: 600; }
.badge.green { background: rgba(34,197,94,.15); color: var(--green); }
.badge.red { background: rgba(239,68,68,.15); color: var(--red); }
.badge.gray { background: var(--panel-2); color: var(--text-dim); }
.badge.purple { background: rgba(124,92,252,.15); color: var(--accent-2); }

.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { min-width: 260px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.kanban-col-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; font-size: 14px; }
.kanban-count { background: var(--panel-2); border-radius: 100px; padding: 2px 9px; font-size: 12px; }
.lead-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 10px; margin-bottom: 8px; cursor: grab; }
.lead-card:hover { border-color: var(--accent); }
.lead-name { font-weight: 600; font-size: 13px; }
.lead-phone { font-size: 12px; color: var(--text-dim); }

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.auth-card { width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.auth-card h1 { font-size: 20px; }
.error-msg { background: rgba(239,68,68,.12); color: #fca5a5; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

.list-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }

.stage-row { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.keyword-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border-radius: 100px; padding: 4px 10px 4px 12px; font-size: 12px; margin: 3px 4px 0 0; }
.keyword-chip button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 13px; }

.tag-code { display: block; background: #0a0c12; border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: monospace; font-size: 12px; overflow-x: auto; white-space: pre; margin: 10px 0; }
