:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1a1d29;
  --muted: #6b7280;
  --border: #e6e8ef;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --shadow: 0 1px 3px rgba(17,24,39,.06), 0 1px 2px rgba(17,24,39,.04);
  --sidebar-top: #0b1020;
  --sidebar-bot: #1a1d3a;
  --sidebar-text: #cbd5e1;
}
[data-theme="dark"] {
  --bg: #0f1117; --surface: #1a1d29; --text: #e6e8ef;
  --muted: #94a3b8; --border: #2a2e3a;
  --shadow: 0 1px 3px rgba(0,0,0,.45), 0 1px 2px rgba(0,0,0,.3);
}
[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] .card, [data-theme="dark"] .kpi, [data-theme="dark"] .auth-card,
[data-theme="dark"] .kanban-col, [data-theme="dark"] .deal-card {
  background: var(--surface) !important; border-color: var(--border) !important;
}
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: #232734 !important; color: var(--text) !important; border-color: var(--border) !important;
}
[data-theme="dark"] .table tbody tr:hover { background: rgba(255,255,255,.03) !important; }
[data-theme="dark"] .kanban-col { background: #232734 !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5; display: flex; min-height: 100vh;
}
a { color: inherit; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 244px;
  background: linear-gradient(180deg, var(--sidebar-top) 0%, var(--sidebar-bot) 100%);
  color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 20px 14px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,.04);
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }
.brand {
  display: flex; align-items: center; gap: 11px; text-decoration: none;
  margin: 0 4px 18px; padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand .logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 17px;
  box-shadow: 0 4px 12px rgba(79,70,229,.4); flex-shrink: 0;
}
.brand-name { color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -.2px; }
.brand-tag { color: #94a3b8; font-size: 9.5px; text-transform: uppercase; letter-spacing: 1.4px; font-weight: 600; }

.user-chip {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  padding: 9px 10px; border-radius: 10px; margin-bottom: 16px;
  background: rgba(255,255,255,.04); transition: background .15s;
}
.user-chip:hover { background: rgba(255,255,255,.08); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.avatar.img { object-fit: cover; }
.user-info { min-width: 0; flex: 1; }
.user-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; }
.user-badge { font-size: 10px; color: #94a3b8; }
.user-badge.admin { color: #a5b4fc; font-weight: 600; }

.sidebar nav { display: flex; flex-direction: column; flex: 1; gap: 2px; }
.nav-section { display: flex; flex-direction: column; gap: 1px; margin-bottom: 12px; }
.nav-label {
  color: #cbd5e1; font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  font-weight: 800; padding: 6px 12px 6px; opacity: .8;
}
.nav-item {
  color: var(--sidebar-text); text-decoration: none; padding: 9px 12px;
  border-radius: 8px; font-size: 13.5px; font-weight: 500;
  display: flex; align-items: center; gap: 11px; transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: rgba(79,70,229,.25); color: #fff; font-weight: 600; }
.nav-ico { width: 18px; height: 18px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 10px;
}
.sidebar-foot { margin-top: 8px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.06); display: flex; flex-direction: column; gap: 2px; }
.sidebar-credit { color: #64748b; font-size: 10.5px; text-align: center; padding: 8px 4px 2px; }

/* ---------- Main ---------- */
.main { flex: 1; padding: 28px 36px; max-width: calc(100% - 244px); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; }
.page-head .muted { margin: 0; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border-radius: 10px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; border: 1px solid var(--border); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border-radius: 10px; padding: 18px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 6px 0 4px; }
.kpi-sub { color: var(--muted); font-size: 12px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.table th { font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.table tbody tr:hover { background: #fafbfd; }
.table .right, th.right { text-align: right; }
.table a { color: var(--primary); text-decoration: none; font-weight: 500; }
.table a:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-ico { font-size: 40px; margin-bottom: 8px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; font-size: 13px; font-weight: 500; text-decoration: none; transition: all .15s; }
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; justify-content: center; }
.icon-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 4px 8px; font-size: 17px; }
.icon-btn:hover { color: var(--danger); }

/* ---------- Segmented control / filters ---------- */
.seg { display: inline-flex; background: #eef0f5; border-radius: 6px; padding: 3px; }
.seg a { padding: 5px 12px; font-size: 13px; text-decoration: none; color: var(--muted); border-radius: 4px; }
.seg a.active { background: #fff; color: var(--text); box-shadow: var(--shadow); font-weight: 500; }
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search input, .filter-bar input, .filter-bar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.search input { width: 260px; }

/* ---------- Pills ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 500; background: #eef0f5; color: var(--muted); text-transform: capitalize; }
.pill-call { background: #dbeafe; color: #1e40af; }
.pill-email { background: #e0e7ff; color: #3730a3; }
.pill-meeting { background: #fef3c7; color: #92400e; }
.pill-task { background: #f3e8ff; color: #6b21a8; }
.pill-note { background: #f1f5f9; color: #475569; }
.stage-lead { background: #f1f5f9; color: #475569; }
.stage-qualified { background: #dbeafe; color: #1e40af; }
.stage-proposal { background: #ede9fe; color: #6d28d9; }
.stage-negotiation { background: #fef3c7; color: #92400e; }
.stage-won { background: #d1fae5; color: #065f46; }
.stage-lost { background: #fee2e2; color: #991b1b; }
.status-draft { background: #f1f5f9; color: #475569; }
.status-sent { background: #dbeafe; color: #1e40af; }
.status-paid { background: #d1fae5; color: #065f46; }
.status-overdue { background: #fee2e2; color: #991b1b; }

/* ---------- Forms ---------- */
form.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .form-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.form input, .form select, .form textarea { padding: 9px 11px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text); font-weight: 400; text-transform: none; letter-spacing: normal; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.check { flex-direction: row !important; align-items: center; gap: 8px; text-transform: none; font-weight: 500; color: var(--text); }
.check input { width: auto; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; width: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); padding: 20px; }
.auth-card { background: #fff; border-radius: 14px; padding: 36px; width: 100%; max-width: 400px; box-shadow: 0 20px 40px rgba(0,0,0,.15); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .logo { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin: 20px 0; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.auth-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.auth-card .center { text-align: center; }
.auth-card a { color: var(--primary); text-decoration: none; font-weight: 500; }

/* ---------- Flash ---------- */
.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 10px; font-size: 13px; border: 1px solid; }
.flash-success { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.flash-error { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(190px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { background: #f1f3f8; border-radius: 8px; padding: 10px; min-height: 320px; display: flex; flex-direction: column; }
.kanban-col-head { padding: 4px 6px 12px; display: flex; justify-content: space-between; align-items: center; }
.kanban-col-title { font-weight: 600; font-size: 13px; }
.kanban-col-sub { font-size: 11px; color: var(--muted); }
.kanban-col-body { flex: 1; display: flex; flex-direction: column; gap: 8px; min-height: 100px; }
.kanban-col-body.drag-over { background: rgba(79,70,229,.08); border-radius: 6px; outline: 2px dashed rgba(79,70,229,.3); }
.deal-card { background: #fff; border-radius: 6px; padding: 10px; box-shadow: var(--shadow); border: 1px solid var(--border); cursor: grab; transition: transform .15s, box-shadow .15s; }
.deal-card:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,.08); }
.deal-card.dragging { opacity: .5; cursor: grabbing; }
.deal-title { font-weight: 600; color: var(--text); text-decoration: none; font-size: 13px; display: block; }
.deal-title:hover { color: var(--primary); }
.deal-amount { font-size: 15px; font-weight: 700; margin: 4px 0; color: var(--success); }
.deal-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }

/* ---------- Stage bars (dashboard/reports) ---------- */
.stage-bars { display: flex; flex-direction: column; gap: 12px; }
.stage-row { display: grid; grid-template-columns: 130px 1fr 110px; gap: 12px; align-items: center; font-size: 13px; }
.stage-row-label { font-weight: 500; }
.stage-row-value { text-align: right; font-weight: 600; }
.stage-bar { height: 8px; background: #eef0f5; border-radius: 4px; overflow: hidden; }
.stage-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }

/* ---------- Detail layout ---------- */
.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.big-avatar { width: 56px; height: 56px; font-size: 20px; border-radius: 14px; }
.head-row { display: flex; align-items: center; gap: 14px; }

.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline li { display: flex; gap: 10px; }
.timeline .dot { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; background: #eef0f5; }
.timeline .ev-body { flex: 1; }
.timeline .ev-time { color: var(--muted); font-size: 11px; }

.note-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.note-meta { color: var(--muted); font-size: 11px; margin-bottom: 4px; }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { text-align: center; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; padding: 6px 0; }
.cal-cell { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-height: 92px; padding: 6px; }
.cal-cell.empty { background: transparent; border: none; }
.cal-cell.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.cal-day { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.cal-ev { background: rgba(79,70,229,.12); color: var(--primary); border-radius: 4px; padding: 1px 5px; font-size: 11px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Notifications dropdown ---------- */
.notif-wrap { position: relative; }
.notif-list { display: flex; flex-direction: column; }
.notif-item { display: flex; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.notif-item:hover { background: #fafbfd; }
.notif-item.unread { background: rgba(79,70,229,.05); }
.notif-icon { width: 36px; height: 36px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.notif-title { font-weight: 600; font-size: 13px; }
.notif-time { color: var(--muted); font-size: 11px; }

/* ---------- Mobile ---------- */
.mobile-menu-btn { display: none; position: fixed; top: 12px; left: 12px; z-index: 1000; width: 44px; height: 44px; border-radius: 10px; background: linear-gradient(135deg, #0b1020, #1a1d3a); color: #fff; border: none; cursor: pointer; font-size: 22px; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 998; }
@media (max-width: 768px) {
  html, body { display: block; }
  .mobile-menu-btn { display: flex; }
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; width: 270px; transform: translateX(-100%); transition: transform .25s ease; z-index: 999; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .main { max-width: 100%; padding: 60px 16px 30px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kanban { grid-template-columns: repeat(6, 80vw); }
}
