/* ===========================================================================
   Pipeline CRM — design system
   Dark sidebar, light content, colour-coded badges, SaaS feel.
   Hand-written CSS, no frameworks.
   =========================================================================== */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #6366f1;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-soft: #eef2ff;

  --green: #16a34a;   --green-soft: #dcfce7;
  --blue: #2563eb;    --blue-soft: #dbeafe;
  --amber: #d97706;   --amber-soft: #fef3c7;
  --red: #dc2626;     --red-soft: #fee2e2;
  --purple: #7c3aed;  --purple-soft: #ede9fe;
  --slate: #475569;   --slate-soft: #e2e8f0;
  --teal: #0d9488;    --teal-soft: #ccfbf1;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.18);
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: inherit; text-decoration: none; }

/* ---- buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; font-size: 13.5px;
  transition: var(--transition); white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon {
  width: 32px; height: 32px; padding: 0; justify-content: center;
  background: transparent; color: var(--text-muted); border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ===========================================================================
   LOGIN
   =========================================================================== */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 20% -10%, #1e293b 0%, #0f172a 55%, #020617 100%);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border-radius: 16px; padding: 36px 32px; box-shadow: var(--shadow-lg);
  animation: pop var(--transition);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-brand .logo-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; color: #fff; }
.login-brand h1 { font-size: 19px; font-weight: 700; }
.login-card p.sub { color: var(--text-muted); margin-bottom: 24px; font-size: 13.5px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 6px; color: var(--text); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  transition: var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; min-height: 72px; }
.login-card .btn { width: 100%; justify-content: center; }
.login-error { background: var(--red-soft); color: var(--red); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }
.login-divider { text-align: center; color: var(--text-faint); font-size: 12px; margin: 16px 0; position: relative; }
.demo-hint { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--text-muted); }
.demo-hint code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--border); }

/* ===========================================================================
   APP SHELL
   =========================================================================== */
.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; transition: grid-template-columns .22s ease; }
.shell.sidebar-collapsed { grid-template-columns: 0px 1fr; }
.shell.sidebar-collapsed .sidebar { padding: 0; pointer-events: none; }
/* Icon rail: slim CRM nav to icons only (used on the Email screen) */
.shell.nav-rail { grid-template-columns: 64px 1fr; }
.shell.nav-rail .sidebar { padding: 18px 8px; }
.shell.nav-rail .sidebar .brand h1,
.shell.nav-rail .nav a span,
.shell.nav-rail .sidebar .user-chip .meta { display: none; }
.shell.nav-rail .sidebar .brand { justify-content: center; padding: 6px 0 20px; }
.shell.nav-rail .nav a { justify-content: center; padding: 10px 0; }
.shell.nav-rail .sidebar .user-chip { justify-content: center; padding: 10px 0; }

.sidebar {
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
  overflow: hidden; transition: padding .22s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 20px; }
.sidebar .brand .logo-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; color: #fff; }
.sidebar .brand h1 { font-size: 16px; color: #fff; font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: var(--radius-sm); color: var(--sidebar-text); font-weight: 500;
  transition: var(--transition);
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.nav a:hover { background: var(--sidebar-2); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav a.active svg { opacity: 1; }
.sidebar .spacer { flex: 1; }
.sidebar .user-chip {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px;
  border-top: 1px solid var(--sidebar-2); margin-top: 8px;
}
.sidebar .user-chip .avatar { width: 32px; height: 32px; font-size: 12px; }
.sidebar .user-chip .meta { overflow: hidden; }
.sidebar .user-chip .meta .name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user-chip .meta .email { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 20px; font-weight: 700; }
.topbar .sub { color: var(--text-muted); font-size: 13px; margin-top: 1px; }
.topbar .actions { display: flex; gap: 10px; align-items: center; }
.content { padding: 24px 28px 48px; flex: 1; overflow-y: auto; }
.hamburger { display: flex; align-items: center; }

/* ---- cards ------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-title { font-size: 14px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.stat .label { color: var(--text-muted); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stat .label .ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 10px; letter-spacing: -0.5px; }
.stat .value small { font-size: 14px; color: var(--text-muted); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.grid-1 { margin-bottom: 20px; }

/* ---- table ------------------------------------------------------------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 200px; max-width: 360px; position: relative;
}
.search input { width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-faint); }
select.filter { padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow-sm); }
.table-wrap table { min-width: 640px; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-faint); padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--text-muted); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0.4; transition: var(--transition); }
tr:hover .row-actions { opacity: 1; }

.name-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }

/* ---- badges ------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.b-lead, .b-Lead { background: var(--blue-soft); color: var(--blue); }
.b-prospect, .b-Qualified { background: var(--amber-soft); color: var(--amber); }
.b-customer, .b-active { background: var(--green-soft); color: var(--green); }
.b-inactive { background: var(--slate-soft); color: var(--slate); }
.b-Proposal { background: var(--purple-soft); color: var(--purple); }
.b-Negotiation { background: var(--teal-soft); color: var(--teal); }
.b-ClosedWon { background: var(--green-soft); color: var(--green); }
.b-ClosedLost { background: var(--red-soft); color: var(--red); }
.tag { display: inline-flex; padding: 3px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--slate); border: 1px solid var(--border); }

/* ---- activity type pills ---------------------------------------------- */
.act-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.act-call { background: var(--blue-soft); color: var(--blue); }
.act-email { background: var(--purple-soft); color: var(--purple); }
.act-meeting { background: var(--amber-soft); color: var(--amber); }
.act-note { background: var(--slate-soft); color: var(--slate); }
.act-task { background: var(--teal-soft); color: var(--teal); }

/* ===========================================================================
   KANBAN
   =========================================================================== */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(248px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 120px; transition: var(--transition); }
.kcol.drag-over { background: var(--primary-soft); border-color: var(--primary); }
.kcol-head { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); position: sticky; top: 0; }
.kcol-head .ktitle { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kcol-head .kcount { background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.kcol-head .ktotal { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.kcol-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; box-shadow: var(--shadow-sm); cursor: grab; transition: var(--transition);
  border-left: 3px solid var(--stage-color, var(--primary));
}
.kcard:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kcard.dragging { opacity: 0.5; cursor: grabbing; }
.kcard.k-selectable { cursor: pointer; }
.kcard.k-selected { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent); }
.kcard-check { position: absolute; top: 8px; right: 8px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface2); display: grid; place-items: center; font-size: 10px; color: #fff; transition: var(--transition); }
.kcard.k-selected .kcard-check { background: var(--primary); border-color: var(--primary); }
.kcard .ktitle { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.kcard .kval { font-weight: 700; color: var(--green); font-size: 14px; }
.kcard .kmeta { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--text-muted); font-size: 12px; }
.kcard .kmeta .kcontact { display: flex; align-items: center; gap: 6px; overflow: hidden; }
.kcard .mini-avatar { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 9px; font-weight: 700; flex: none; }

/* ===========================================================================
   CHARTS
   =========================================================================== */
.chart { width: 100%; }
.bar-chart .bar { transition: var(--transition); }
.bar-chart .bar:hover { opacity: 0.85; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 12px; color: var(--text-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---- activity feed ----------------------------------------------------- */
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 14px; padding: 14px 4px; border-bottom: 1px solid var(--border); }
.feed-item:last-child { border-bottom: none; }
.feed-item .body { flex: 1; min-width: 0; }
.feed-item .ftop { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.feed-item .fsubject { font-weight: 600; }
.feed-item .fsubject.done { text-decoration: line-through; color: var(--text-faint); }
.feed-item .ftime { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.feed-item .fdesc { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.feed-item .flinks { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.feed-item .flinks .chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; color: var(--text-muted); }
.feed-item .fcheck { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-top: 8px; cursor: pointer; }
.feed-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ===========================================================================
   MODAL / DRAWER
   =========================================================================== */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: flex; justify-content: flex-end; z-index: 100;
  opacity: 0; transition: opacity var(--transition);
}
.overlay.show { opacity: 1; }
.drawer {
  width: 460px; max-width: 100%; background: var(--surface); height: 100%;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
}
.overlay.show .drawer { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.drawer-head h3 { font-size: 17px; font-weight: 700; }
.drawer-body { padding: 22px 24px; }
.drawer-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: var(--surface); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* centered confirm modal */
.overlay.center { justify-content: center; align-items: center; }
.overlay.center .confirm {
  background: var(--surface); border-radius: var(--radius); padding: 24px; width: 380px; max-width: 90%;
  box-shadow: var(--shadow-lg); transform: scale(0.96); transition: transform var(--transition);
}
.overlay.center.show .confirm { transform: scale(1); }
.confirm h3 { font-size: 16px; margin-bottom: 8px; }
.confirm p { color: var(--text-muted); margin-bottom: 20px; }
.confirm .row { display: flex; gap: 10px; justify-content: flex-end; }

/* company detail rows */
.detail-section { margin-top: 22px; }
.detail-section h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); margin-bottom: 10px; }
.mini-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.mini-row:last-child { border-bottom: none; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; }
.kv dt { color: var(--text-muted); font-size: 13px; }
.kv dd { font-weight: 500; }

/* ---- toast ------------------------------------------------------------- */
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); animation: pop var(--transition); }
.toast.err { background: var(--red); }

/* ---- daily briefing card ---------------------------------------------- */
.briefing { display: flex; align-items: center; gap: 16px; background: linear-gradient(120deg, #eef2ff 0%, #faf5ff 100%); border-color: #e0e7ff; }
.briefing .brief-ico { width: 40px; height: 40px; border-radius: 11px; background: var(--primary); color: #fff; display: grid; place-items: center; flex: none; }
.briefing .brief-ico svg { width: 22px; height: 22px; }
.briefing .brief-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--primary); margin-bottom: 3px; }
.briefing .brief-text { font-size: 14.5px; color: var(--text); line-height: 1.5; }

/* ---- business switcher + tags ----------------------------------------- */
.biz-switch { font-weight: 600; }
.list-count { color: var(--text-muted); font-size: 12.5px; margin: -6px 2px 12px; }
.kbiz { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 6px; }
.kbiz span { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ---- type-to-search picker -------------------------------------------- */
.typeahead { position: relative; }
.typeahead .ta-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.typeahead .ta-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ta-menu { display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); z-index: 5; max-height: 240px; overflow-y: auto; }
.ta-menu.open { display: block; }
.ta-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; font-size: 13px; }
.ta-item:hover { background: var(--primary-soft); }
.ta-empty { padding: 10px; color: var(--text-faint); font-size: 13px; }

/* ---- calendar --------------------------------------------------------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dows { margin-bottom: 6px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.cal-cell { min-height: 92px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; background: var(--surface); transition: var(--transition); cursor: pointer; overflow: hidden; }
.cal-cell:hover { border-color: var(--primary); background: var(--surface-2); }
.cal-cell.out { background: transparent; border: none; cursor: default; }
.cal-cell.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal-num { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.cal-cell.today .cal-num { color: var(--primary); }
.cal-chip { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 5px; border: 1px solid; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-more { font-size: 10.5px; color: var(--text-faint); padding-left: 2px; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-faint); }
.empty svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.5; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 40px auto; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ===========================================================================
   RESPONSIVE (down to tablet 768px)
   =========================================================================== */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; width: 244px;
    transform: translateX(-100%); transition: transform var(--transition);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: inline-flex; }
  .scrim { position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 55; }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .form-row { grid-template-columns: 1fr; }
  .drawer { width: 100%; }
}

/* ---- Price List Editor ---- */
.pl-shell { display: flex; height: 100%; gap: 0; overflow: hidden; }
.pl-sidebar { width: 220px; flex-shrink: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; padding: 16px 0; }
.pl-sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 16px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.pl-sidebar-title { font-weight: 600; font-size: 13px; color: var(--text); }
.pl-list { list-style: none; margin: 0; padding: 0 8px; display: flex; flex-direction: column; gap: 2px; }
.pl-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); transition: background .15s; }
.pl-item:hover { background: var(--surface-2); }
.pl-item-edit { opacity: 0; font-size: 13px; }
.pl-item:hover .pl-item-edit { opacity: 1; }
.pl-empty-item { font-size: 13px; color: var(--text-muted); padding: 8px 10px; }
.pl-editor { flex: 1; overflow-y: auto; padding: 24px 28px; }
.pl-empty { color: var(--text-muted); font-size: 14px; margin-top: 48px; text-align: center; }
.pl-form { display: flex; flex-direction: column; gap: 20px; max-width: 760px; }
.pl-form-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.pl-form-header > div:first-child { flex: 1; min-width: 200px; }
.pl-form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pl-id-note { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.pl-section { border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.pl-section legend { font-weight: 600; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); padding: 0 6px; }
.pl-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.pl-label-row { display: flex; align-items: center; justify-content: space-between; }
.pl-label-text { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.pl-input { border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; font-size: 13px; color: var(--text); background: var(--surface); width: 100%; font-family: inherit; resize: vertical; }
.pl-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.pl-pkg { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.pl-pkg-summary { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; user-select: none; background: var(--surface-2); }
.pl-pkg-summary::-webkit-details-marker { display: none; }
.pl-pkg-num { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); flex-shrink: 0; }
.pl-pkg-title-preview { font-size: 13px; font-weight: 500; color: var(--text); flex: 1; }
.pl-pkg-del { margin-left: auto; flex-shrink: 0; }
.pl-pkg-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); }
.pl-price-rows-section { display: flex; flex-direction: column; gap: 6px; }
.pl-price-rows-list { display: flex; flex-direction: column; gap: 4px; }
.pl-price-row { display: flex; gap: 8px; align-items: center; }
.pl-price-row .pl-row-label { flex: 2; }
.pl-price-row .pl-row-val { flex: 1; }
.pl-status { font-size: 13px; min-height: 20px; }
.pl-status.ok { color: #16a34a; }
.pl-status.err { color: #dc2626; }
.pl-danger { color: #dc2626; border-color: #dc2626; }
.pl-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---- Settings shell ---- */
.set-shell { display: flex; height: 100%; gap: 0; overflow: hidden; }
.set-nav { width: 200px; flex-shrink: 0; border-right: 1px solid var(--border); padding: 16px 8px; display: flex; flex-direction: column; gap: 2px; }
.set-nav-item { text-align: left; padding: 9px 12px; border: none; background: transparent; color: var(--text); font-size: 13px; border-radius: 6px; cursor: pointer; font-family: inherit; }
.set-nav-item:hover { background: var(--surface-2); }
.set-nav-item.active { background: var(--surface-2); font-weight: 600; color: var(--primary); }
.set-pane { flex: 1; overflow-y: auto; padding: 20px 24px; }

/* ---- Agreement template editor ---- */
.at-form { display: flex; flex-direction: column; gap: 20px; }
.at-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.at-actions { display: flex; gap: 8px; }
.at-tokens { font-size: 12px; color: var(--text-muted); }
.at-tokens code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }
.at-clause { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.at-clause-bar { display: flex; gap: 8px; align-items: center; }
.at-clause-bar .at-c-heading { flex: 1; }
.at-clause-btns { display: flex; gap: 4px; flex-shrink: 0; }

/* ---- Generic modal shell ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---- Send Agreement modal ---- */
.sa-modal { width: 720px; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; }
.sa-body { overflow-y: auto; }
.sa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sa-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 16px 0 8px; }
.sa-item { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.sa-item .sa-it-desc { flex: 3; }
.sa-item .sa-it-amt { flex: 1; }
.sa-totals { display: flex; gap: 24px; margin-top: 14px; font-size: 14px; }
.sa-foot { display: flex; gap: 8px; justify-content: flex-end; }
