/* SkyRaptor CRM — Next.js-inspired workspace UI */
:root {
  --sr-blue: #6a82fb;
  --sr-purple: #6b3fa0;
  --sr-gradient: linear-gradient(135deg, #6a82fb 0%, #6b3fa0 100%);
  --sr-soft: #eef2ff;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e8ecf4;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-w: 260px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(106, 130, 251, 0.06);
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body.crm-body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--sr-purple); text-decoration: none; }
a:hover { color: var(--sr-blue); }

.crm-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.crm-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
}
.crm-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}
.crm-brand-mark {
  display: flex; align-items: center; gap: 12px;
}
.crm-brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--sr-gradient); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 0.95rem;
  box-shadow: 0 6px 16px rgba(106, 130, 251, 0.35);
}
.crm-brand h1 { font-size: 1rem; font-weight: 700; letter-spacing: -0.02em; }
.crm-brand p { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.crm-nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.crm-nav-label {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: #94a3b8; padding: 8px 10px 6px;
}
.crm-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: #475569; font-size: 0.9rem; font-weight: 500;
  margin-bottom: 2px; transition: 0.15s;
}
.crm-nav a i { width: 18px; text-align: center; opacity: 0.85; }
.crm-nav a:hover { background: #f8fafc; color: var(--sr-purple); }
.crm-nav a.active {
  background: var(--sr-soft); color: var(--sr-purple); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--sr-purple);
}

.crm-sidebar-foot {
  padding: 14px 16px 18px; border-top: 1px solid var(--border);
}
.crm-help-card {
  background: linear-gradient(180deg, #f8fafc, #fff);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; font-size: 0.78rem; color: var(--muted); margin-bottom: 12px;
}
.crm-user-chip {
  display: flex; align-items: center; gap: 10px;
}
.crm-avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--sr-gradient); color: #fff;
  display: grid; place-items: center; font-size: 0.75rem; font-weight: 700;
}
.crm-user-chip strong { display: block; font-size: 0.82rem; }
.crm-user-chip span { font-size: 0.7rem; color: var(--muted); }

/* Main */
.crm-main {
  margin-left: var(--sidebar-w);
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.crm-topbar {
  height: 64px; background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 30;
}
.crm-topbar-left { color: var(--muted); font-size: 0.9rem; }
.crm-topbar-right { display: flex; align-items: center; gap: 14px; }
.crm-bell {
  position: relative; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff;
  display: grid; place-items: center; color: #64748b; cursor: pointer;
}
.crm-bell .badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; border-radius: 999px;
  background: #ef4444; color: #fff; font-size: 0.65rem; font-weight: 700;
  display: grid; place-items: center; padding: 0 4px;
}
.crm-btn-ghost {
  border: 1px solid var(--border); background: #fff; color: #475569;
  border-radius: 10px; padding: 8px 12px; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.crm-btn-ghost:hover { border-color: #c4b5fd; color: var(--sr-purple); }

.crm-content { padding: 28px; max-width: 1280px; width: 100%; margin: 0 auto; }

.crm-page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.crm-page-head .eyebrow {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 4px;
}
.crm-page-head h2 {
  font-size: clamp(1.4rem, 2vw, 1.75rem); font-weight: 750;
  letter-spacing: -0.03em;
}
.crm-page-head p { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }

.crm-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 11px; padding: 11px 18px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: 0.15s;
}
.crm-btn-primary {
  background: var(--sr-gradient); color: #fff;
  box-shadow: 0 6px 18px rgba(106, 130, 251, 0.35);
}
.crm-btn-primary:hover { transform: translateY(-1px); color: #fff; }
.crm-btn-secondary {
  background: #fff; color: #334155; border: 1px solid var(--border);
}
.crm-btn-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* KPI cards */
.crm-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.crm-kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 16px; box-shadow: var(--shadow);
}
.crm-kpi .label { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.crm-kpi .value {
  font-size: 1.85rem; font-weight: 750; letter-spacing: -0.03em;
  margin: 6px 0 4px; color: var(--text);
}
.crm-kpi .hint { font-size: 0.78rem; color: #94a3b8; }

.crm-grid-2 {
  display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px;
}
.crm-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.crm-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.crm-card-head h3 { font-size: 0.98rem; font-weight: 700; }
.crm-card-head .sub { font-size: 0.78rem; color: var(--muted); font-weight: 400; }

/* Attention list */
.crm-attn-item {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; background: #fff;
}
.crm-attn-item.urgent { border-color: #fde68a; background: #fffbeb; }
.crm-attn-item .meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.crm-attn-item strong { display: block; font-size: 0.9rem; margin-bottom: 6px; }
.crm-attn-item .row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

/* Badges */
.crm-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
}
.crm-badge-urgent { background: #fef2f2; color: #b91c1c; }
.crm-badge-high { background: #fff7ed; color: #c2410c; }
.crm-badge-normal { background: var(--sr-soft); color: var(--sr-purple); }
.crm-badge-low { background: #f1f5f9; color: #64748b; }
.crm-badge-ok { background: #ecfdf5; color: #047857; }
.crm-badge-warn { background: #fffbeb; color: #b45309; }
.crm-badge-info { background: #eff6ff; color: #1d4ed8; }
.crm-badge-muted { background: #f8fafc; color: #64748b; border: 1px solid var(--border); }

/* Tables */
.crm-table-wrap { overflow-x: auto; }
.crm-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.crm-table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fafbfc;
}
.crm-table td {
  padding: 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle;
}
.crm-table tr:hover td { background: #fafbff; }

/* Forms */
.crm-form label {
  display: block; font-size: 0.82rem; font-weight: 600; color: #334155; margin: 0 0 6px;
}
.crm-form .field { margin-bottom: 14px; }
.crm-form input, .crm-form select, .crm-form textarea {
  width: 100%; padding: 11px 12px; border: 1px solid #dbe2ea; border-radius: 10px;
  font-size: 0.92rem; background: #fff; color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.crm-form input:focus, .crm-form select:focus, .crm-form textarea:focus {
  outline: none; border-color: var(--sr-blue);
  box-shadow: 0 0 0 3px rgba(106, 130, 251, 0.18);
}
.crm-form textarea { min-height: 100px; resize: vertical; }
.crm-form .hint { font-size: 0.76rem; color: var(--muted); margin-top: 5px; }
.crm-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.crm-alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 0.9rem;
}
.crm-alert.ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.crm-alert.err { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.crm-alert.info { background: var(--sr-soft); border: 1px solid #c7d2fe; color: #3730a3; }

.crm-stat-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.crm-stat-pill {
  flex: 1; min-width: 110px; background: #f8fafc; border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; text-align: center;
}
.crm-stat-pill .n { font-size: 1.35rem; font-weight: 750; }
.crm-stat-pill .l { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.crm-timeline { list-style: none; }
.crm-timeline li {
  position: relative; padding: 0 0 16px 18px;
  border-left: 2px solid #e2e8f0; margin-left: 8px;
}
.crm-timeline li::before {
  content: ''; position: absolute; left: -5px; top: 4px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--sr-blue);
}
.crm-timeline .when { font-size: 0.72rem; color: var(--muted); }
.crm-timeline .what { font-size: 0.88rem; margin-top: 2px; }

/* Auth */
.crm-auth-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(106,130,251,0.25), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(107,63,160,0.2), transparent 55%),
    var(--bg);
  padding: 24px;
}
.crm-auth-card {
  width: 100%; max-width: 420px; background: #fff;
  border: 1px solid var(--border); border-radius: 18px;
  padding: 32px 28px; box-shadow: var(--shadow);
}
.crm-auth-card .logo-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 22px;
}
.crm-auth-card h2 { font-size: 1.35rem; letter-spacing: -0.02em; margin-bottom: 4px; }
.crm-auth-card .sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 22px; }

.crm-empty {
  text-align: center; padding: 36px 16px; color: var(--muted);
}
.crm-empty i { font-size: 1.8rem; color: #c4b5fd; margin-bottom: 8px; display: block; }

/* TAT clock */
.crm-clock {
  margin: 0 0 18px; padding: 18px 20px; border-radius: 16px;
  border: 1px solid var(--border); background: #fff; box-shadow: var(--shadow);
}
.crm-clock.running { border-color: #c7d2fe; background: linear-gradient(135deg, #eef2ff, #fff); }
.crm-clock.paused { border-color: #fde68a; background: #fffbeb; }
.crm-clock.overdue { border-color: #fecaca; background: #fef2f2; }
.crm-clock-label { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.crm-clock-time { font-size: 2.2rem; font-weight: 800; letter-spacing: 0.04em; margin: 4px 0; font-variant-numeric: tabular-nums; color: var(--sr-purple); }
.crm-clock.overdue .crm-clock-time { color: #b91c1c; }
.crm-clock.paused .crm-clock-time { color: #b45309; font-size: 1.6rem; }
.crm-clock-meta { font-size: 0.82rem; color: var(--muted); }

.crm-locked-tat {
  background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 12px; padding: 12px 14px;
}
.crm-locked-tat .label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; }
.crm-locked-tat strong { font-size: 1.25rem; color: var(--sr-purple); }
.crm-locked-tat .hint { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

.crm-attach-list { list-style: none; }
.crm-attach-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.crm-attach-list li:last-child { border-bottom: 0; }
.crm-attach-list .meta { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.crm-kpi-early .value { color: #047857; }
.crm-kpi-pct { font-size: 0.55em; font-weight: 700; color: #059669; vertical-align: middle; }

/* Call stats + line rows */
.crm-call-stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px;
}
.crm-call-stat {
  background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow);
}
.crm-call-stat .label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.crm-call-stat .value { font-size: 1.45rem; font-weight: 750; margin-top: 4px; }
.crm-call-stat .pct { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.crm-call-stat .bar { height: 6px; background: #e2e8f0; border-radius: 99px; margin-top: 10px; overflow: hidden; }
.crm-call-stat .bar span { display: block; height: 100%; border-radius: 99px; background: var(--sr-purple); }
.crm-call-stat.ok .bar span { background: #10b981; }
.crm-call-stat.ok .value { color: #047857; }
.crm-call-stat.warn .bar span { background: #f59e0b; }
.crm-call-stat.warn .value { color: #b45309; }

.crm-lead-row {
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; background: #fff;
}
.crm-lead-row.focus { border-color: #c7d2fe; box-shadow: 0 0 0 3px rgba(106,130,251,0.12); }
.crm-lead-row.done { opacity: 0.85; background: #f8fafc; }
.crm-lead-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 10px; flex-wrap: wrap; }
.crm-lead-head .num { display: inline-block; font-size: 0.7rem; font-weight: 700; color: var(--sr-purple); background: #eef2ff; padding: 2px 8px; border-radius: 6px; margin-bottom: 8px; }
.crm-lead-fields { display: grid; gap: 4px; }
.crm-lead-fields .k {
  display: inline-block; min-width: 118px; font-size: 0.72rem; font-weight: 650;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em;
}
.crm-lead-fields .phone { font-weight: 700; color: #312e81; letter-spacing: 0.02em; }
.crm-mobile-block {
  display: grid;
  gap: 8px;
  margin: 2px 0 4px;
}
.crm-mobile-block .k { margin-bottom: 0; }
.crm-mobile-value { line-height: 1.2; }
.crm-connect {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.crm-connect-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-decoration: none !important;
  border: 1px solid transparent;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.crm-connect-btn i { font-size: 0.92rem; line-height: 1; }
.crm-connect-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.1);
}
.crm-connect-call {
  color: #1e40af !important;
  background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
  border-color: #93c5fd;
}
.crm-connect-wa {
  color: #166534 !important;
  background: linear-gradient(180deg, #f0fdf4 0%, #dcfce7 100%);
  border-color: #86efac;
}
.crm-connect-sms {
  color: #9a3412 !important;
  background: linear-gradient(180deg, #fff7ed 0%, #ffedd5 100%);
  border-color: #fdba74;
}
@media (max-width: 520px) {
  .crm-connect-btn span { display: none; }
  .crm-connect-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: 10px;
  }
}
.crm-lead-fields em { font-style: normal; color: #3730a3; font-weight: 600; }
.crm-lead-fields .muted { color: var(--muted); }
.crm-lead-head .city { margin-left: 8px; font-size: 0.78rem; color: var(--muted); }
.crm-lead-instructions { margin-bottom: 10px; }
.crm-lead-form { margin-bottom: 10px; }
.crm-lead-import-note {
  font-size: 0.82rem; color: #3730a3; background: #eef2ff; border-radius: 8px;
  padding: 8px 10px; margin-bottom: 10px;
}
.crm-lead-thread {
  border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 4px;
}

.crm-filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; align-items: end;
}
.crm-filters .field { margin: 0; }
.crm-filters .field label {
  display: block; font-size: 0.72rem; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 5px;
}
.crm-filters .field input, .crm-filters .field select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; background: #fff; font: inherit;
}
.crm-filters-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-bottom: 2px; }

@media (max-width: 1100px) {
  .crm-call-stats { grid-template-columns: repeat(2, 1fr); }
}

.crm-mobile-toggle {
  display: none; border: 1px solid var(--border); background: #fff;
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
}

@media (max-width: 1100px) {
  .crm-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .crm-grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .crm-sidebar { transform: translateX(-105%); transition: 0.25s; }
  .crm-sidebar.open { transform: translateX(0); }
  .crm-main { margin-left: 0; }
  .crm-mobile-toggle { display: grid; place-items: center; }
  .crm-content { padding: 18px 14px 40px; }
  .crm-form-row { grid-template-columns: 1fr; }
  .crm-topbar { padding: 0 14px; }
}
