:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e6e9f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
  background: #eef0f5;
  color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 6px; }

.select, input, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
.select { width: auto; cursor: pointer; }
input:focus, textarea:focus, .select:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }

/* ---------- Login ---------- */
.auth-view {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #e0e7ff, var(--bg));
}
.auth-card {
  background: var(--surface); width: 360px; padding: 34px 30px;
  border-radius: 16px; box-shadow: 0 10px 40px rgba(31,41,55,.12);
  display: flex; flex-direction: column; gap: 7px;
}
.auth-logo {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-size: 28px; font-weight: 700; margin: 0 auto 6px;
}
.auth-card h1 { text-align: center; margin: 0; font-size: 22px; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 14px; }
.auth-card label { font-weight: 600; font-size: 13px; margin-top: 6px; }
.auth-error { color: #b91c1c; font-size: 13px; min-height: 16px; text-align: center; margin: 4px 0 0; }
.auth-toggle { text-align: center; color: var(--muted); margin-top: 10px; font-size: 13px; }
.auth-hint { text-align: center; color: var(--muted); margin: 8px 0 0; font-size: 12px; }
.auth-hint code { background: #eef0f5; padding: 1px 5px; border-radius: 4px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: #111827; color: #cbd5e1; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 8px; position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 17px; color: #fff; display: flex; align-items: center; gap: 8px; padding: 6px 8px 16px; }
.brand-mark { background: var(--primary); color: #fff; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { color: #cbd5e1; padding: 10px 12px; border-radius: 8px; font-weight: 500; }
.nav-item:hover { background: #1f2937; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid #1f2937; }
.user-email { font-size: 12px; color: #94a3b8; word-break: break-all; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 19px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.content { padding: 24px 26px; }

/* ---------- Cards / KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 22px; overflow: hidden;
}
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-body { padding: 6px 0; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 18px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar { height: 8px; border-radius: 4px; background: var(--primary); min-width: 2px; }
.bar-track { flex: 1; background: #eef0f5; border-radius: 4px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tag { background: #eef0f5; color: var(--muted); border-radius: 6px; padding: 2px 8px; font-size: 12px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.column { background: #eef1f7; border-radius: var(--radius); min-width: 250px; width: 250px; display: flex; flex-direction: column; max-height: calc(100vh - 160px); }
.column-head { padding: 12px 14px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; border-top: 3px solid var(--primary); border-radius: var(--radius) var(--radius) 0 0; }
.column-count { background: #fff; border-radius: 999px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.column-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
.column-body.drag-over { background: #e0e7ff; }
.lead-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  cursor: grab; box-shadow: var(--shadow);
}
.lead-card:active { cursor: grabbing; }
.lead-card .name { font-weight: 600; }
.lead-card .meta { color: var(--muted); font-size: 12px; margin-top: 3px; display: flex; flex-direction: column; gap: 2px; }
.lead-card.dragging { opacity: .4; }

/* ---------- Filters bar ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filters input, .filters .select { width: auto; }
.filters input[type=search] { min-width: 220px; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: 16px; width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }
.close-x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; border-left: 2px solid var(--border); }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline .when { color: var(--muted); font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.muted { color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; right: 22px; background: #111827; color: #fff;
  padding: 13px 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 100;
  font-weight: 500; max-width: 360px;
}
.toast.error { background: #b91c1c; }
.toast.ok { background: #15803d; }

@media (max-width: 760px) {
  .sidebar { width: 64px; padding: 16px 8px; }
  .brand span:last-child, .nav-item span, .user-email { display: none; }
  .nav-item { text-align: center; }
}
