/* ============================================================
   CRM  —  Industrial Utilitarian Design System
   Typefaces: Inter (body/UI, readability) + DM Mono (tabular data
   only) + Syne (headings)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=DM+Mono:wght@400;500&family=Syne:wght@600;700;800&display=swap');

:root {
  --bg:         #0e0f11;
  --surface:    #16181c;
  --surface2:   #1e2027;
  --border:     #2a2d36;
  --accent:     #22d3ee;
  --accent2:    #47c8ff;
  --danger:     #ff4757;
  --success:    #2ecc71;
  --warning:    #f39c12;
  --text:       #e8eaf0;
  --muted:      #8b93a7;
  --sans:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:       'DM Mono', monospace;
  --display:    'Syne', sans-serif;
  --radius:     4px;
  --transition: 150ms ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

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

.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo h1 {
  font-family: var(--display);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.sidebar-logo span {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  display: block;
  margin-top: 4px;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section-label {
  padding: 12px 20px 4px;
  font-size: 0.7rem;
  font-family: var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-family: var(--sans);
  font-weight: 500;
  transition: color var(--transition), background var(--transition);
  border-left: 2px solid transparent;
}

.nav-item:hover  { color: var(--text);   background: var(--surface2); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(34,211,238,0.05); }

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

.sidebar-footer a { color: var(--muted); text-decoration: none; }
.sidebar-footer a:hover { color: var(--danger); }

.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
}

.content { padding: 28px; flex: 1; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Card variant that allows horizontal scrolling inside */
.card-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-family: var(--display);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-body { padding: 20px; }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}

.stat-label { font-size: 0.72rem; font-family: var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-family: var(--display); font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1.1; margin: 6px 0 4px; }
.stat-sub   { font-size: 0.72rem; color: var(--muted); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.72rem;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.td-mono { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 2px;
  font-size: 0.72rem;
  font-family: var(--sans);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 600;
}

.badge-new          { background: rgba(71,200,255,0.15); color: var(--accent2); }
.badge-qualified    { background: rgba(34,211,238,0.15);  color: var(--accent); }
.badge-proposal     { background: rgba(243,156,18,0.2);   color: var(--warning); }
.badge-negotiation  { background: rgba(243,156,18,0.3);   color: #f5b942; }
.badge-won          { background: rgba(46,204,113,0.2);   color: var(--success); }
.badge-lost         { background: rgba(255,71,87,0.15);   color: var(--danger); }
.badge-sent         { background: rgba(71,200,255,0.15);  color: var(--accent2); }
.badge-opened       { background: rgba(46,204,113,0.2);   color: var(--success); }
.badge-draft        { background: var(--surface2);         color: var(--muted); }
/* Semantic badges used by statusBadge() */
.badge-info         { background: rgba(71,200,255,0.15);  color: var(--accent2); }
.badge-success      { background: rgba(46,204,113,0.2);   color: var(--success); }
.badge-warning      { background: rgba(243,156,18,0.2);   color: var(--warning); }
.badge-error        { background: rgba(255,71,87,0.15);   color: var(--danger); }
.badge-purple       { background: rgba(155,89,182,0.2);   color: #c39bd3; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary  { background: var(--accent);  color: #0d1724; }
.btn-primary:hover { background: #06b6d4; }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--muted); }

.btn-danger { background: rgba(255,71,87,0.15); color: var(--danger); border: 1px solid rgba(255,71,87,0.3); }
.btn-danger:hover { background: rgba(255,71,87,0.25); }

.btn-sm { padding: 5px 10px; font-size: 0.72rem; }

.btn svg { width: 14px; height: 14px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type=text],input[type=email],input[type=tel],input[type=password],
input[type=number],input[type=date],select,textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition);
}

input:focus,select:focus,textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(34,211,238,0.1);
}

textarea { resize: vertical; min-height: 80px; }
select { appearance: none; cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Search bar ── */
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 14px; height: 14px; pointer-events: none; }
.search-wrap input { padding-left: 32px; }

/* ── Pipeline Board ── */
.pipeline-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(180px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.pipeline-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 400px; }

.pipeline-col-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pipeline-col-title { font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600; }
.pipeline-col-count { font-size: 0.7rem; color: var(--muted); }

.pipeline-cards { padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.lead-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}

.lead-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lead-card-name  { font-size: 0.8rem; font-weight: 500; margin-bottom: 4px; }
.lead-card-company { font-size: 0.72rem; color: var(--muted); }
.lead-card-value { font-family: var(--display); font-size: 0.95rem; font-weight: 700; color: var(--accent); margin-top: 8px; }

/* ── Notes timeline ── */
.timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.timeline-item:last-child { border-bottom: none; }

.timeline-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.timeline-dot svg { width: 13px; height: 13px; }

.timeline-body { flex: 1; }
.timeline-meta { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(12px);
  transition: transform 0.2s;
}

.modal-backdrop.open .modal { transform: translateY(0); }

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-family: var(--display); font-size: 1rem; font-weight: 700; }

.modal-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 4px; line-height: 1; font-size: 1.2rem;
}

.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Flash alerts ── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 0.82rem; margin-bottom: 20px; border-left: 3px solid; }
.alert-success { background: rgba(46,204,113,0.1); border-color: var(--success); color: var(--success); }
.alert-error   { background: rgba(255,71,87,0.1);  border-color: var(--danger);  color: var(--danger); }
.alert-info    { background: rgba(71,200,255,0.1); border-color: var(--accent2); color: var(--accent2); }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 18px;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
  transition: color var(--transition);
}

.tab:hover  { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Utilities ── */
.flex     { display: flex; }
.items-center { align-items: center; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.justify-between { justify-content: space-between; }
.mb-4   { margin-bottom: 16px; }
.mb-6   { margin-bottom: 24px; }
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-sm  { font-size: 0.78rem; }
.text-xs  { font-size: 0.7rem; }
.font-display { font-family: var(--display); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full   { width: 100%; }
.grid-2   { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(34,211,238,0.05) 0%, transparent 70%);
}

.login-box {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
}

.login-logo {
  font-family: var(--display);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.04em;
  margin-bottom: 6px;
}

.login-sub { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 30px; }

/* ── Hamburger button (hidden on desktop) ── */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.menu-toggle svg { width: 18px; height: 18px; }

/* ── Sidebar overlay backdrop (mobile only) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}
.sidebar-backdrop.open { display: block; }

/* ── Responsive ── */
/* ── Mobile lead cards (leads.php) ── */
.lead-list-cards { display: none; }

.lead-list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lead-list-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.lead-list-card-name {
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  font-size: .9rem;
  line-height: 1.3;
}

.lead-list-card-name:hover { text-decoration: underline; }

.lead-list-card-meta {
  font-size: .72rem;
  color: var(--muted);
  font-family: var(--mono);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 2px;
}

.lead-list-card-meta span::before { content: attr(data-label) ': '; opacity: .6; }

@media (max-width: 768px) {
  /* Show hamburger */
  .menu-toggle { display: flex; }

  /* Lead list: hide table, show cards */
  .lead-list-table { display: none; }
  .lead-list-cards { display: flex; flex-direction: column; gap: 8px; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }

  /* Main takes full width */
  .main { margin-left: 0; }

  /* Topbar gets a bit more breathing room */
  .topbar { padding: 0 16px; gap: 12px; }

  /* Content padding reduced */
  .content { padding: 16px; }

  /* Tables scroll horizontally */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Stack form rows */
  .form-row { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* Stats grid: 2 columns on mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .stat-value { font-size: 1.5rem; }

  /* Pipeline scrolls horizontally */
  .pipeline-board { grid-template-columns: repeat(3, minmax(160px, 1fr)); }

  /* Tabs scroll on mobile */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { white-space: nowrap; padding: 10px 14px; }

  /* Login box fits screen */
  .login-box { width: 100%; max-width: 360px; padding: 28px 20px; }

  /* Modals full-width on mobile */
  .modal { max-width: 100%; margin: 0; border-radius: 0; max-height: 100vh; }
  .modal-backdrop { padding: 0; align-items: flex-end; }

  /* Button groups wrap */
  .btn-group { flex-wrap: wrap; }

  /* Card bodies tighter */
  .card-body { padding: 14px; }

  /* Topbar title truncates */
  .topbar-title { font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .content { padding: 12px; }
  .card-header { padding: 12px 14px; }

  /* Hide less important table columns via utility class */
  .hide-mobile { display: none !important; }
}
