/* ============================================================
   Tekmetric CRM — Shared Design System
   Brand: #F0572A (orange), #5D5D5D (gray), #2B2B2B (ink)
   Clean SaaS aesthetic (HubSpot/Salesforce-like)
   ============================================================ */

:root {
  /* Brand */
  --tek-orange: #F0572A;
  --tek-orange-600: #d9461c;
  --tek-orange-50: #fef1ec;
  --tek-orange-100: #fde0d5;
  --tek-gray: #5D5D5D;
  --tek-ink: #2B2B2B;

  /* Neutrals */
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e6e9ed;
  --border-strong: #d4d9df;
  --text: #1f2733;
  --text-muted: #6b7480;
  --text-faint: #9aa3ae;

  /* Status */
  --green: #16a34a; --green-bg: #e8f6ed;
  --blue: #2563eb;  --blue-bg: #e8effd;
  --amber: #d97706; --amber-bg: #fdf2e3;
  --red: #dc2626;   --red-bg: #fdeaea;
  --purple:#7c3aed; --purple-bg:#f0eafe;
  --teal: #0d9488;  --teal-bg: #e6f5f3;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow: 0 1px 3px rgba(16,24,40,.10), 0 1px 2px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 25px rgba(16,24,40,.12);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--tek-orange); text-decoration: none; }
h1,h2,h3,h4 { color: var(--tek-ink); margin: 0; font-weight: 700; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: #1c2230; color: #c7ccd6;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar__brand {
  padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar__brand svg, .sidebar__brand img { height: 26px; width: auto; }
.sidebar__section { padding: 14px 12px 4px; font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; color: #6b7385; font-weight: 600; }
.nav { list-style: none; margin: 0; padding: 4px 8px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: 8px; color: #c7ccd6; font-weight: 500; font-size: 13.5px;
  margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--tek-orange); color: #fff; }
.nav a .ico { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.nav a .badge-count { margin-left: auto; background: rgba(255,255,255,.16);
  color: #fff; border-radius: 20px; font-size: 11px; padding: 1px 8px; }
.nav a.active .badge-count { background: rgba(255,255,255,.25); }
.sidebar__user {
  margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}

/* ---------- Main ---------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar .spacer { flex: 1; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; width: 320px; max-width: 36vw;
}
.search input { border: 0; background: transparent; outline: none; width: 100%; font-size: 13.5px; color: var(--text); }
.content { padding: 24px; flex: 1; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head .spacer { flex: 1; }
.page-title { font-size: 22px; }
.page-sub { color: var(--text-muted); margin-top: 4px; font-size: 13.5px; }
.breadcrumb { color: var(--text-faint); font-size: 12.5px; margin-bottom: 6px; }
.breadcrumb a { color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; transition: .12s; white-space: nowrap;
}
.btn:hover { background: #f7f8fa; }
.btn--primary { background: var(--tek-orange); border-color: var(--tek-orange); color: #fff; }
.btn--primary:hover { background: var(--tek-orange-600); border-color: var(--tek-orange-600); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--bg); }
.btn--sm { padding: 6px 10px; font-size: 12.5px; }
.btn--icon { padding: 8px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card__head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.card__head h3 { font-size: 15px; }
.card__head .spacer { flex: 1; }
.card__body { padding: 18px; }
.card__foot { padding: 12px 18px; border-top: 1px solid var(--border); }

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

/* ---------- KPI tiles ---------- */
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm); }
.kpi__label { color: var(--text-muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi__value { font-size: 28px; font-weight: 800; color: var(--tek-ink); margin: 8px 0 4px; }
.kpi__delta { font-size: 12.5px; font-weight: 600; display: inline-flex; gap: 4px; align-items: center; }
.kpi__delta.up { color: var(--green); } .kpi__delta.down { color: var(--red); }
.kpi__spark { margin-top: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tek { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tek thead th {
  text-align: left; padding: 11px 14px; color: var(--text-muted); font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border); background: #fafbfc; white-space: nowrap;
}
table.tek tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tek tbody tr:hover { background: #fafbfc; }
table.tek tbody tr:last-child td { border-bottom: 0; }
.t-strong { font-weight: 600; color: var(--tek-ink); }
.t-muted { color: var(--text-muted); }
.checkbox { width: 16px; height: 16px; accent-color: var(--tek-orange); }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; }
.badge--green{background:var(--green-bg);color:var(--green);}
.badge--blue{background:var(--blue-bg);color:var(--blue);}
.badge--amber{background:var(--amber-bg);color:var(--amber);}
.badge--red{background:var(--red-bg);color:var(--red);}
.badge--purple{background:var(--purple-bg);color:var(--purple);}
.badge--teal{background:var(--teal-bg);color:var(--teal);}
.badge--gray{background:#eef0f3;color:var(--text-muted);}
.dot{width:8px;height:8px;border-radius:50%;display:inline-block;}

/* ---------- Avatars ---------- */
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--tek-orange-100);
  color: var(--tek-orange-600); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex: 0 0 auto; }
.avatar--sm { width: 26px; height: 26px; font-size: 11px; }
.avatar--lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.b{background:var(--blue-bg);color:var(--blue);} .avatar.g{background:var(--green-bg);color:var(--green);}
.avatar.p{background:var(--purple-bg);color:var(--purple);} .avatar.t{background:var(--teal-bg);color:var(--teal);}

/* ---------- Cell helpers ---------- */
.cell-lead { display: flex; align-items: center; gap: 10px; }
.cell-lead .meta { line-height: 1.3; }
.cell-lead .meta small { color: var(--text-muted); font-size: 12px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.kanban__col { flex: 0 0 270px; background: #eef1f4; border-radius: var(--radius); padding: 10px; }
.kanban__col h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 10px; }
.kanban__col h4 .count { margin-left: auto; background: #fff; border-radius: 20px; padding: 0 8px; font-size: 11px; }
.kanban__card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  margin-bottom: 9px; box-shadow: var(--shadow-sm); cursor: grab; }
.kanban__card:hover { box-shadow: var(--shadow); }
.kanban__card .title { font-weight: 600; color: var(--tek-ink); margin-bottom: 4px; }
.kanban__card .sub { color: var(--text-muted); font-size: 12.5px; }
.kanban__card .row { display: flex; align-items: center; gap: 6px; margin-top: 10px; }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 9px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline__item { position: relative; padding-bottom: 18px; }
.timeline__item::before { content: ''; position: absolute; left: -21px; top: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; border: 3px solid var(--tek-orange); }
.timeline__item.call::before{border-color:var(--green);}
.timeline__item.email::before{border-color:var(--blue);}
.timeline__item.note::before{border-color:var(--amber);}
.timeline__meta { font-size: 12px; color: var(--text-faint); }
.timeline__title { font-weight: 600; color: var(--tek-ink); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input, .select, textarea.input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px; padding: 9px 12px;
  font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff; outline: none;
}
.input:focus, .select:focus, textarea.input:focus { border-color: var(--tek-orange); box-shadow: 0 0 0 3px var(--tek-orange-50); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a { padding: 10px 14px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--tek-orange); border-bottom-color: var(--tek-orange); }

/* ---------- Progress / funnel ---------- */
.progress { height: 8px; background: var(--border); border-radius: 20px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--tek-orange); border-radius: 20px; }

.funnel-row { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.funnel-bar { height: 38px; border-radius: 8px; background: var(--tek-orange); color: #fff;
  display: flex; align-items: center; padding: 0 14px; font-weight: 700; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong);
  background: #fff; border-radius: 20px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.chip:hover { border-color: var(--tek-orange); color: var(--tek-orange); }
.chip--active { background: var(--tek-orange-50); border-color: var(--tek-orange); color: var(--tek-orange-600); }

/* ---------- Utilities ---------- */
.flex{display:flex;} .items-center{align-items:center;} .gap-8{gap:8px;} .gap-12{gap:12px;} .gap-16{gap:16px;}
.spacer{flex:1;} .mt-8{margin-top:8px;} .mt-16{margin-top:16px;} .mt-24{margin-top:24px;} .mb-0{margin-bottom:0;}
.text-muted{color:var(--text-muted);} .text-faint{color:var(--text-faint);} .small{font-size:12.5px;}
.right{margin-left:auto;} .nowrap{white-space:nowrap;} .strong{font-weight:700;color:var(--tek-ink);}
.divider{height:1px;background:var(--border);margin:16px 0;}
.scroll-x{overflow-x:auto;}

/* ---------- Bars for mini charts ---------- */
.barchart { display: flex; align-items: flex-end; gap: 8px; height: 140px; }
.barchart .bar { flex: 1; background: var(--tek-orange-100); border-radius: 6px 6px 0 0; position: relative; }
.barchart .bar > i { position: absolute; bottom: 0; left: 0; right: 0; background: var(--tek-orange); border-radius: 6px 6px 0 0; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Auth / live data notice ---------- */
.auth-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--tek-orange);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  padding: 12px 14px;
}
.auth-notice form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}
.auth-notice .input {
  width: 210px;
  padding: 7px 10px;
}
.auth-notice__title {
  font-weight: 700;
  color: var(--tek-ink);
}

/* ---------- PA lead visualization ---------- */
.lead-filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}
.lead-filter-grid .field {
  margin-bottom: 0;
}
.lead-filter-grid .field span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.lead-breakdown-grid {
  align-items: stretch;
}
.metric-bar {
  margin-bottom: 14px;
}
.metric-bar:last-child {
  margin-bottom: 0;
}
.metric-bar__label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 5px;
  font-size: 12.5px;
}
.metric-bar__label span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--tek-ink);
  font-weight: 700;
}
.metric-bar__label strong {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
}
.metric-bar__track {
  height: 9px;
  overflow: hidden;
  background: #eef1f4;
  border-radius: 999px;
}
.metric-bar__track span {
  display: block;
  height: 100%;
  min-width: 3px;
  background: var(--tek-orange);
  border-radius: 999px;
}
.metric-bar__track .metric-bar__fill--blue {
  background: var(--blue);
}
.metric-bar__track .metric-bar__fill--green {
  background: var(--green);
}
.metric-bar__sub {
  color: var(--text-faint);
  font-size: 11.5px;
  margin-top: 4px;
}
.lead-viz-table .cell-lead {
  min-width: 260px;
}
.lead-viz-table .meta small {
  display: block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.signal-stack {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  min-width: 160px;
}
.loading-state,
.empty-note {
  color: var(--text-muted);
  padding: 18px;
  text-align: center;
}
@media (max-width: 860px) {
  .auth-notice { align-items: flex-start; flex-direction: column; }
  .auth-notice form { margin-left: 0; width: 100%; }
  .auth-notice .input { width: 100%; }
  .lead-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app {
    display: block;
  }
  .sidebar {
    width: 100%;
    height: auto;
    min-height: 0;
    position: sticky;
    top: 0;
    z-index: 40;
  }
  .sidebar__brand {
    padding: 12px 14px;
  }
  .sidebar__brand svg,
  .sidebar__brand img {
    height: 24px;
  }
  .sidebar__section,
  .sidebar__user {
    display: none;
  }
  .sidebar .nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 10px;
    scrollbar-width: none;
  }
  .sidebar .nav::-webkit-scrollbar {
    display: none;
  }
  .sidebar .nav:nth-of-type(n+3) {
    display: none;
  }
  .nav a {
    margin-bottom: 0;
    padding: 8px 10px;
    white-space: nowrap;
  }
  .nav a .ico {
    width: 17px;
    height: 17px;
  }
  .main {
    min-width: 0;
  }
  .topbar {
    position: static;
    height: auto;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }
  .topbar .spacer {
    display: none;
  }
  .topbar h1 {
    flex: 1 1 auto;
  }
  .topbar .btn {
    padding: 8px 10px;
  }
  .search {
    order: 3;
    width: 100%;
    max-width: none;
  }
  .content {
    padding: 16px;
  }
  .page-head {
    flex-wrap: wrap;
    gap: 10px;
  }
  .page-head .spacer {
    display: none;
  }
  .page-title {
    font-size: 21px;
  }
  .content > .grid[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  .auth-notice form {
    align-items: stretch;
    flex-direction: column;
  }
  .auth-notice .btn {
    justify-content: center;
  }
  .lead-filter-grid {
    grid-template-columns: 1fr;
  }
  .lead-viz-table .cell-lead {
    min-width: 220px;
  }
  .lead-viz-table .meta small {
    max-width: 240px;
  }
}
