:root {
  --bg: #0f1117;
  --surface: #171a23;
  --border: #262b38;
  --text: #e6e8ef;
  --muted: #8b8fa3;
  --accent: #6c63ff;
  --danger: #ff6b6b;
  --success: #4caf7d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 18px;
}

.logout-form { margin: 0; }

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.logout-btn:hover { color: var(--text); border-color: var(--accent); }

/* Login page */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-title { margin: 0 0 4px; font-size: 22px; }
.login-subtitle { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.login-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.login-form button {
  margin-top: 6px;
  background: var(--accent);
  border: none;
  color: white;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.muted { color: var(--muted); }

/* Funnel */
.funnel {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.funnel-step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 120px;
  flex: 1;
}

.funnel-num { font-size: 24px; font-weight: 700; }
.funnel-label { font-size: 13px; color: var(--muted); }
.funnel-pct { font-size: 12px; color: var(--accent); }

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
}

.filters input, .filters select, .filters button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

.date-label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }

.filters button {
  background: var(--accent);
  border: none;
  cursor: pointer;
  color: white;
  font-weight: 600;
}

.export-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  margin-left: auto;
}

/* Table */
.leads-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.leads-table th, .leads-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
}

.leads-table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }

.leads-table a { color: var(--text); text-decoration: none; }
.leads-table a:hover { color: var(--accent); }

.leads-table tr.unread { background: rgba(108, 99, 255, 0.08); }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--border);
}

.badge-won { background: rgba(76, 175, 125, 0.2); color: var(--success); }
.badge-lost { background: rgba(255, 107, 107, 0.2); color: var(--danger); }
.badge-in_progress { background: rgba(108, 99, 255, 0.2); color: var(--accent); }

.pagination {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.pagination a { color: var(--accent); text-decoration: none; }

/* Detail page */
.back-link {
  color: var(--muted);
  text-decoration: none;
  display: inline-block;
  margin-bottom: 16px;
}

.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.lead-card h1 { margin: 0 0 12px; font-size: 22px; }

.lead-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0 0 16px;
}

.lead-meta dt { color: var(--muted); font-size: 13px; }
.lead-meta dd { margin: 0; }
.lead-meta a { color: var(--accent); }

.status-form select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

.panel-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.panel-block h2 { margin: 0 0 12px; font-size: 16px; }

.panel-block textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

.panel-block button {
  margin-top: 8px;
  background: var(--accent);
  border: none;
  color: white;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
}

.timeline, .notes { list-style: none; padding: 0; margin: 0; }

.timeline li, .notes li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.timeline li:last-child, .notes li:last-child { border-bottom: none; }

.timeline-time, .note-time { color: var(--muted); font-size: 12px; margin-right: 10px; }
.timeline-data { color: var(--accent); margin-left: 8px; }

.notes p { margin: 4px 0 0; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

.flash-ok { background: rgba(76, 175, 125, 0.15); color: var(--success); }
.flash-error { background: rgba(255, 107, 107, 0.15); color: var(--danger); }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --border: #e2e4ec;
    --text: #1a1c25;
    --muted: #6b6f80;
  }
}
