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

:root {
  --navy: #173A53;
  --steel: #1F5A7A;
  --ink: #0F1A24;
  --aluminum: #E9EEF5;
  --accent: #7EC3FF;
  --white: #ffffff;
  --muted: #6b7b8c;
  --border: #e7edf3;
  --bg: #f5f7fa;
  --red: #d94f4f;
  --green: #2e7d52;
  --amber: #b45309;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(23,58,83,.08);
  --sidebar-w: 220px;
  --sidebar-collapsed-w: 56px;
  font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

html { overflow-x: hidden; }
body { background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; overflow-x: hidden; }
a { color: var(--steel); text-decoration: none; }
button { cursor: pointer; font: inherit; }

/* ── Layout ── */
.app-layout { display: flex; min-height: 100vh; overflow-x: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #c8dae8;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width .22s ease, transform .25s ease;
  overflow: hidden;
}

/* ── Collapsed sidebar ── */
.sidebar.collapsed { width: var(--sidebar-collapsed-w); }
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-user,
.sidebar.collapsed .sidebar-footer .btn { display: none; }
.sidebar.collapsed .sidebar-logo { padding: 18px 0; justify-content: center; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .nav-item svg { width: 18px; height: 18px; }
.sidebar.collapsed .sidebar-nav { padding: 10px 6px; }
.sidebar.collapsed .sidebar-footer { padding: 10px 6px; }

.sidebar-collapse-wrap {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.collapse-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px; border-radius: 6px;
  background: transparent; border: none; color: #9ab4c8;
  font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.collapse-btn:hover { background: rgba(255,255,255,.07); color: var(--white); }
.collapse-btn svg { flex-shrink: 0; transition: transform .22s ease; }
.sidebar.collapsed .collapse-btn { justify-content: center; padding: 8px 0; }
.sidebar.collapsed .collapse-btn svg { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-collapse-wrap { padding: 8px 0 10px; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo .mark {
  width: 32px; height: 32px;
  background: var(--white);
  color: var(--navy);
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  flex-shrink: 0;
}
.sidebar-logo span { font-weight: 700; font-size: 15px; color: var(--white); }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  color: #9ab4c8;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: var(--white); }
.nav-item.active { background: rgba(255,255,255,.12); color: var(--white); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user { font-size: 12px; color: #7a99b0; margin-bottom: 8px; padding: 0 4px; }
.sidebar-user strong { display: block; color: #c8dae8; font-size: 13px; }

/* Sign-out button — light styling for the navy sidebar */
.sidebar-footer .btn-ghost {
  color: #dbe7f0;
  background: rgba(255,255,255,.05);
  border-color: rgba(255,255,255,.16);
}
.sidebar-footer .btn-ghost:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.28);
  color: var(--white);
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
  transition: margin-left .22s ease;
}
.main-content.collapsed { margin-left: var(--sidebar-collapsed-w); }

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  min-width: 0;
}
.topbar-title { font-size: 15px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.search-wrap { flex: 1; }
.search-wrap { position: relative; max-width: 340px; min-width: 0; }
.search-wrap input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px 7px 32px;
  font: inherit;
  font-size: 13px;
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}
.search-wrap input:focus { border-color: var(--steel); background: var(--white); }
.search-icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.1);
  display: none; z-index: 200; overflow: hidden;
}
.search-results.open { display: block; }
.search-section-label { padding: 8px 12px 4px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.search-result-item {
  padding: 8px 12px; cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.search-result-item:hover { background: var(--bg); }
.search-result-item .name { font-weight: 500; font-size: 13px; }
.search-result-item .meta { font-size: 12px; color: var(--muted); }

.page-content { padding: 24px; flex: 1; min-width: 0; overflow-x: auto; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent; transition: all .15s;
}
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--steel); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); border-color: #cdd6e0; }
.btn-danger { background: transparent; color: var(--red); border-color: #f5c6c6; }
.btn-danger:hover { background: #fdf2f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 6px; background: transparent; border: 1px solid transparent; color: var(--muted); }
.btn-icon:hover { background: var(--bg); color: var(--ink); }
.btn svg { width: 14px; height: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ── Pills / Badges ── */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.pill-residential { background: #dbeafe; color: #1e40af; }
.pill-commercial { background: #ede9fe; color: #5b21b6; }
.pill-glass { background: #d1fae5; color: #065f46; }
.pill-referral { background: #fef3c7; color: #92400e; }
.pill-bni { background: #dbeafe; color: #1e40af; }
.pill-website { background: #d1fae5; color: #065f46; }
.pill-walkin { background: #e0f2fe; color: #075985; }
.pill-architect { background: #ede9fe; color: #5b21b6; }
.pill-social { background: #fce7f3; color: #9d174d; }
.pill-other { background: var(--aluminum); color: var(--muted); }

/* ── Status/Stage colors ── */
.status-new { color: var(--muted); }
.status-contacted { color: var(--steel); }
.status-qualified { color: #0369a1; }
.status-negotiating { color: var(--amber); }
.status-won { color: var(--green); font-weight: 600; }
.status-lost { color: var(--red); }

/* ── Cards ── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body { padding: 16px; }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 13px; font-weight: 600; color: var(--ink); }

/* ── KPI Cards ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.kpi-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--ink); line-height: 1.1; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ── Kanban ── */
.kanban-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-select {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font: inherit; font-size: 12.5px;
  background: var(--white); color: var(--ink); outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--steel); }

.kanban-board {
  display: flex; gap: 12px; overflow-x: auto;
  padding-bottom: 16px; align-items: flex-start;
}
.kanban-board::-webkit-scrollbar { height: 6px; }
.kanban-board::-webkit-scrollbar-track { background: transparent; }
.kanban-board::-webkit-scrollbar-thumb { background: #cdd6e0; border-radius: 3px; }

.kanban-col {
  flex: 0 0 260px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}
.kanban-col.drag-over { border-color: var(--steel); background: #eef5fa; }

.col-header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.col-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.col-count {
  background: var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}

.col-cards {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 80px;
}
.col-cards::-webkit-scrollbar { width: 4px; }
.col-cards::-webkit-scrollbar-thumb { background: #cdd6e0; border-radius: 2px; }

/* ── Kanban Cards ── */
.k-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 11px 12px;
  cursor: pointer;
  user-select: none;
  transition: box-shadow .15s, transform .1s;
  position: relative;
}
.k-card:hover { box-shadow: 0 4px 12px rgba(23,58,83,.1); }
.k-card.dragging { opacity: .5; transform: scale(.97); box-shadow: 0 8px 24px rgba(23,58,83,.15); }
.k-card-name { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.k-card-meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: 6px; }
.k-card-row { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.k-card-value { font-size: 12px; font-weight: 600; color: var(--green); }
.k-card-date { font-size: 11px; color: var(--muted); }
.k-card-date.overdue { color: var(--red); font-weight: 600; }
.k-card-phone { font-size: 11.5px; color: var(--muted); }

/* ── Drawer ── */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 400;
  display: none;
  opacity: 0;
  transition: opacity .2s;
}
.drawer-overlay.open { display: block; opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 480px; max-width: 100vw;
  background: var(--white);
  border-left: 1px solid var(--border);
  z-index: 500;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,.08);
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.drawer-title { font-size: 15px; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
  flex-shrink: 0;
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
.form-label .required { color: var(--red); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 11px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--white);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--steel); box-shadow: 0 0 0 3px rgba(31,90,122,.08); }
.form-input::placeholder, .form-textarea::placeholder { color: #aab7c4; }
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.form-error { font-size: 11.5px; color: var(--red); margin-top: 4px; }
.checkbox-row { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.checkbox-item {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; color: var(--ink); cursor: pointer;
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 6px;
  transition: border-color .15s, background .15s;
}
.checkbox-item:hover { border-color: #cdd6e0; background: var(--bg); }
.checkbox-item input { width: 15px; height: 15px; accent-color: var(--navy); cursor: pointer; }

/* ── Activity Log ── */
.activity-list { display: flex; flex-direction: column; gap: 0; }
.activity-item {
  display: flex; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); flex-shrink: 0; margin-top: 5px;
}
.activity-dot.status { background: var(--steel); }
.activity-dot.created { background: var(--green); }
.activity-dot.deleted { background: var(--red); }
.activity-text { font-size: 13px; color: var(--ink); flex: 1; }
.activity-text .user { font-weight: 600; }
.activity-time { font-size: 11px; color: var(--muted); white-space: nowrap; text-align: right; }
.activity-rel { font-weight: 500; }
.activity-stamp { font-size: 10px; color: var(--muted); opacity: .75; margin-top: 1px; }
.activity-toggle {
  background: none; border: none; color: var(--steel);
  font-size: 12px; font-weight: 500; padding: 8px 0 2px;
  cursor: pointer;
}
.activity-toggle:hover { text-decoration: underline; }

/* ── Detail View ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-field { }
.detail-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }
.detail-value { font-size: 14px; color: var(--ink); }
.detail-value.empty { color: var(--muted); font-style: italic; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  z-index: 600; display: none; place-items: center;
}
.modal-overlay.open { display: grid; }
.modal {
  background: var(--white); border-radius: 10px;
  width: 480px; max-width: calc(100vw - 32px);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  overflow: hidden;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: var(--white);
  padding: 10px 16px; border-radius: 7px;
  font-size: 13px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  transform: translateY(8px); opacity: 0;
  transition: all .2s;
  max-width: 300px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ── Skeleton ── */
.skeleton { background: linear-gradient(90deg, #e7edf3 25%, #f0f4f8 50%, #e7edf3 75%); background-size: 200%; animation: shimmer 1.2s infinite; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-kpi { height: 72px; border-radius: 8px; }
.skeleton-card { height: 90px; border-radius: 6px; }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.empty-state-sub { font-size: 13px; color: var(--muted); margin-bottom: 20px; }

/* ── Dashboard ── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px; }
.overdue-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.overdue-item:last-child { border-bottom: none; }
.overdue-name { font-weight: 500; }
.overdue-date { font-size: 11.5px; color: var(--red); font-weight: 600; }

/* ── Login Page ── */
.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
.login-card { width: 380px; max-width: calc(100vw - 32px); }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-logo .mark { width: 40px; height: 40px; background: var(--navy); color: var(--white); border-radius: 9px; display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.login-logo-text { font-size: 18px; font-weight: 700; color: var(--navy); }
.login-logo-sub { font-size: 12px; color: var(--muted); }
.login-title { font-size: 20px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--muted); margin-bottom: 24px; }
.login-error { background: #fdf2f2; border: 1px solid #f5c6c6; color: var(--red); border-radius: 6px; padding: 10px 12px; font-size: 13px; margin-bottom: 16px; display: none; }
.login-error.show { display: block; }

/* ── Responsive ── */
.hamburger { display: none; }

@media (max-width: 768px) {
  /* On mobile: sidebar slides in/out, ignore collapsed-width logic */
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .sidebar.collapsed.open { transform: translateX(0); }
  /* Show all text labels on mobile regardless of collapsed state */
  .sidebar.collapsed .sidebar-logo-text,
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .sidebar-user,
  .sidebar.collapsed .sidebar-footer .btn { display: revert; }
  .sidebar.collapsed .collapse-btn .nav-label { display: revert; }
  .sidebar.collapsed .sidebar-logo { padding: 20px 18px; justify-content: flex-start; }
  .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 9px 10px; }
  .sidebar.collapsed .nav-item svg { width: 16px; height: 16px; }
  .sidebar.collapsed .sidebar-footer { padding: 12px 10px; }
  .sidebar.collapsed .sidebar-collapse-wrap { padding: 8px 10px 10px; }
  .sidebar.collapsed .collapse-btn { justify-content: flex-start; padding: 8px 10px; }
  .sidebar.collapsed .collapse-btn svg { transform: none; }
  /* On mobile, collapse button closes the sidebar overlay */
  .collapse-btn { display: flex; }
  .main-content { margin-left: 0 !important; }
  .hamburger { display: flex; }
  .kanban-col { flex: 0 0 220px; }
  .form-row { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .drawer { width: 100vw; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .page-content { padding: 12px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kanban-col { flex: 0 0 200px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .search-wrap { display: none; }
  .topbar-title { font-size: 14px; }
}

/* ── Misc ── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mt-8 { margin-top: 8px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 12px; }
