@import url("tokens.c1308b4b34ac.css");

/* ────────── Reset / base ────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { color: var(--c-primary-hover); }
button { font-family: inherit; cursor: pointer; }

/* ────────── App shell ────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

/* Hamburger toggle: a real <button>, hidden on desktop, shown once JS has
   marked the page as drawer-capable (see the `html.js` rules below). Kept
   inert (display:none) without JS so it never appears as a dead control. */
.menu-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  background: var(--c-surface); color: var(--c-text);
  font-size: var(--fs-lg); line-height: 1;
  flex-shrink: 0;
}
.menu-toggle:hover { background: var(--c-surface-2); }

/* Scrim behind the open drawer. Only ever shown at mobile widths via the
   .is-open class the drawer script toggles; harmless in the DOM otherwise. */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--c-overlay);
  z-index: 40;
}
.sidebar__brand {
  padding: var(--s-6) var(--s-5);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; gap: var(--s-3);
}
.sidebar__logo {
  width: 32px; height: 32px; border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--c-primary), var(--c-future));
  color: var(--c-on-primary); display: grid; place-items: center;
  font-weight: var(--fw-bold); font-size: 14px;
}
.sidebar__title { font-weight: var(--fw-semi); font-size: var(--fs-lg); }

.sidebar__nav { flex: 1; padding: var(--s-3); overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  color: var(--c-text-muted);
  font-size: var(--fs-md); font-weight: var(--fw-med);
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--c-surface-2); color: var(--c-text); }
.nav-item.is-active {
  background: var(--c-primary-soft); color: var(--c-primary);
  font-weight: var(--fw-semi);
}
.nav-item__icon { width: 16px; height: 16px; opacity: 0.8; }

.sidebar__footer {
  border-top: 1px solid var(--c-border);
  padding: var(--s-4);
  display: flex; align-items: center; gap: var(--s-3);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--c-primary-soft); color: var(--c-primary);
  display: grid; place-items: center; font-weight: var(--fw-semi);
}
.user-meta { font-size: var(--fs-sm); line-height: 1.3; }
.user-meta .name { font-weight: var(--fw-semi); }
.user-meta .role { color: var(--c-text-muted); font-size: var(--fs-xs); }

/* ────────── Main area ────────── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  min-height: var(--topbar-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center;
  padding: var(--s-2) var(--s-8);
  gap: var(--s-4);
  position: sticky; top: 0; z-index: 10;
}
@media (max-width: 900px) {
  .topbar { padding: var(--s-2) var(--s-4); }
}
.topbar__title { font-size: var(--fs-xl); font-weight: var(--fw-semi); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__actions { margin-left: auto; display: flex; gap: var(--s-3); flex-wrap: wrap; justify-content: flex-end; }
.content { padding: var(--s-6) var(--s-8); flex: 1; min-width: 0; }

/* ────────── Notification chips ────────── */
.topbar__alerts { display: flex; gap: var(--s-2); margin-left: var(--s-6); flex-wrap: wrap; }
.alert-chip {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 3px var(--s-3); border-radius: 999px;
  font-size: var(--fs-xs); font-weight: var(--fw-med);
  border: 1px solid transparent;
}
.alert-chip strong { font-weight: var(--fw-bold); }
.alert-chip--danger  { background: var(--c-danger-soft);  color: var(--c-danger); }
.alert-chip--warning { background: var(--c-warning-soft); color: var(--c-warning); }
.alert-chip--info    { background: var(--c-info-soft);    color: var(--c-info); }
.alert-chip:hover { border-color: currentColor; }

/* ────────── Buttons ────────── */
.btn {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: var(--fw-semi);
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface); color: var(--c-text);
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:hover { background: var(--c-surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--c-primary); color: var(--c-on-primary); border-color: var(--c-primary);
}
.btn--primary:hover { background: var(--c-primary-hover); color: var(--c-on-primary); }
.btn--ghost { border-color: transparent; background: transparent; }

/* ────────── Cards / KPI ────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card__body { padding: var(--s-5); }
.card__header {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: var(--fw-semi);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-6);
}
.kpi {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--sh-1);
}
.kpi__label { color: var(--c-text-muted); font-size: var(--fs-sm); font-weight: var(--fw-med); }
.kpi__value { font-size: var(--fs-3xl); font-weight: var(--fw-bold); margin-top: var(--s-2); }
.kpi__delta { font-size: var(--fs-xs); color: var(--c-text-muted); margin-top: var(--s-2); }

/* ────────── Dashboard layout ────────── */
.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--s-5); align-items: start; }
.kpi--danger  { border-color: var(--c-danger); }
.kpi--danger .kpi__value  { color: var(--c-danger); }
.kpi--warning { border-color: var(--c-warning); }
.kpi--warning .kpi__value { color: var(--c-warning); }

/* ────────── Funnel ────────── */
.funnel { display: flex; flex-direction: column; gap: var(--s-2); }
.funnel__row {
  display: grid; grid-template-columns: minmax(90px, 200px) 1fr 40px;
  align-items: center; gap: var(--s-3);
  font-size: var(--fs-sm);
}
.funnel__bar {
  height: 24px; border-radius: var(--r-sm);
  background: var(--c-primary-soft); position: relative;
}
.funnel__fill {
  height: 100%; border-radius: var(--r-sm);
  background: var(--c-primary); min-width: 4px;
}
.funnel__count { text-align: right; font-weight: var(--fw-semi); }
.funnel__row--compact { grid-template-columns: 150px 1fr 36px; font-size: var(--fs-xs); }

/* ────────── Report tabs ────────── */
.report-tabs {
  display: flex; gap: var(--s-2); flex-wrap: wrap;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: var(--s-5);
}
.report-tab {
  padding: var(--s-3) var(--s-4);
  color: var(--c-text-muted);
  font-size: var(--fs-sm); font-weight: var(--fw-semi);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.report-tab:hover { color: var(--c-text); }
.report-tab.is-active { color: var(--c-primary); border-bottom-color: var(--c-primary); }

/* ────────── Tables ──────────
   Wide tables scroll horizontally inside their own container instead of
   squeezing columns unreadably. The layered background is the classic
   scroll-shadow trick: two opaque fades that sit "under" the scrolling
   content (background-attachment: local) mask the table edges, and two
   thin shadows that stay fixed to the viewport (background-attachment:
   scroll) only show while there is more to scroll to on that side — that
   is the "visible affordance" a plain overflow:auto lacks. */
.table-wrap {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  background-image:
    linear-gradient(to right, var(--c-surface) 30%, transparent),
    linear-gradient(to left, var(--c-surface) 30%, transparent),
    linear-gradient(to right, var(--c-scroll-shadow), transparent),
    linear-gradient(to left, var(--c-scroll-shadow), transparent);
  background-position: left, right, left, right;
  background-repeat: no-repeat;
  background-size: 24px 100%, 24px 100%, 8px 100%, 8px 100%;
  background-attachment: local, local, scroll, scroll;
}
/* Same scroll treatment for a bare table that isn't already inside a
   .table-wrap card (e.g. a table nested in another card's body). */
.table-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background-image:
    linear-gradient(to right, var(--c-surface) 30%, transparent),
    linear-gradient(to left, var(--c-surface) 30%, transparent),
    linear-gradient(to right, var(--c-scroll-shadow), transparent),
    linear-gradient(to left, var(--c-scroll-shadow), transparent);
  background-position: left, right, left, right;
  background-repeat: no-repeat;
  background-size: 24px 100%, 24px 100%, 8px 100%, 8px 100%;
  background-attachment: local, local, scroll, scroll;
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td {
  padding: var(--s-3) var(--s-4);
  text-align: left; border-bottom: 1px solid var(--c-border);
}
.table th {
  background: var(--c-surface-2); color: var(--c-text-muted);
  font-weight: var(--fw-semi); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.table tbody tr:hover { background: var(--c-surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

/* ────────── Stage badges ────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px var(--s-2); border-radius: 999px;
  font-size: var(--fs-xs); font-weight: var(--fw-semi);
  background: var(--c-surface-2); color: var(--c-text-muted);
  border: 1px solid var(--c-border);
}
.badge--stage { color: var(--c-on-primary); border: none; }
.badge--stage[data-stage="new"] { background: var(--stage-new); }
.badge--stage[data-stage="contacted"] { background: var(--stage-contacted); }
.badge--stage[data-stage="demo_scheduled"] { background: var(--stage-demo_scheduled); }
.badge--stage[data-stage="demo_done"] { background: var(--stage-demo_done); }
.badge--stage[data-stage="requirement"] { background: var(--stage-requirement); }
.badge--stage[data-stage="proposal"] { background: var(--stage-proposal); }
.badge--stage[data-stage="negotiation"] { background: var(--stage-negotiation); }
.badge--stage[data-stage="commercial_confirmed"] { background: var(--stage-commercial_confirmed); }
.badge--stage[data-stage="payment"] { background: var(--stage-payment); }
.badge--stage[data-stage="onboarding"] { background: var(--stage-onboarding); }
.badge--stage[data-stage="closed_live"] { background: var(--stage-closed_live); }
.badge--stage[data-stage="lost"] { background: var(--stage-lost); }
.badge--stage[data-stage="on_hold"] { background: var(--stage-on_hold); }

.badge--priority[data-p="hot"]  { background: var(--c-danger-soft); color: var(--c-danger); border-color: transparent; }
.badge--priority[data-p="warm"] { background: var(--c-warning-soft); color: var(--c-warning); border-color: transparent; }
.badge--priority[data-p="cold"] { background: var(--c-info-soft); color: var(--c-info); border-color: transparent; }

/* ────────── Forms ────────── */
.form-row { margin-bottom: var(--s-4); }
.form-row label {
  display: block; font-size: var(--fs-sm); font-weight: var(--fw-semi);
  color: var(--c-text-muted); margin-bottom: var(--s-2);
}
.input, .form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: var(--s-3) var(--s-4);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  background: var(--c-surface);
  color: var(--c-text);
}
.input:focus, .form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}

/* ────────── Empty state ────────── */
.empty { text-align: center; padding: var(--s-10); color: var(--c-text-muted); }
.empty__title { font-size: var(--fs-lg); font-weight: var(--fw-semi); color: var(--c-text); }
.empty__hint { font-size: var(--fs-sm); margin-top: var(--s-2); }

/* ────────── Login ────────── */
.login-page {
  min-height: 100vh; display: grid; place-items: center;
  padding: var(--s-4);
  background: linear-gradient(180deg, var(--c-bg) 0%, var(--c-primary-soft) 100%);
}
.login-card {
  width: min(380px, 100%); background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--r-xl);
  padding: var(--s-8); box-shadow: var(--sh-3);
}
.login-card h1 { font-size: var(--fs-2xl); margin: 0 0 var(--s-2); }
.login-card p.sub { color: var(--c-text-muted); font-size: var(--fs-sm); margin: 0 0 var(--s-6); }
.login-card .btn { width: 100%; justify-content: center; padding: var(--s-3); }
.login-hint {
  margin-top: var(--s-5); padding: var(--s-3);
  background: var(--c-surface-2); border-radius: var(--r-md);
  font-size: var(--fs-xs); color: var(--c-text-muted);
}

/* ────────── Utilities ────────── */
.stack > * + * { margin-top: var(--s-4); }
/* flex-wrap so a row of badges/buttons/timestamps reflows instead of
   overflowing the viewport on a narrow phone — a no-op at any width where
   everything already fits on one line. */
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--c-text-muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* Two-region "detail" layouts (a main column + a narrower side column) used
   across leads, quotations, approvals, onboarding and payments screens.
   Replaces the inline grid-template-columns each of those templates used
   to repeat, so the responsive collapse lives in one place. */
.split { display: grid; grid-template-columns: 2fr 1fr; gap: var(--s-5); }
.split--wide { grid-template-columns: 3fr 1fr; }
.split--even { grid-template-columns: 3fr 2fr; }
.split > * { min-width: 0; }

/* A row of form fields that reflows on its own as space runs out, instead
   of needing a breakpoint per template. minmax() picks the column count. */
.field-grid { display: grid; gap: var(--s-3) var(--s-4); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.field-grid--tight { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

@media (max-width: 1080px) {
  /* Tablet portrait and below: stack the side column under the main one
     rather than squeezing both into an unreadable sliver. */
  .split, .split--wide, .split--even { grid-template-columns: 1fr; }
  /* The dashboard keeps its own proportions (1.6fr 1fr), so it is named
     separately here rather than folded into .split. */
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .content { padding: var(--s-5); }
}

/* ─── Status badges (quotation versions, approvals, commitments) ─── */
.badge--s { border-color: transparent; }
.badge--s-draft, .badge--s-pending, .badge--s-approval_pending { background: var(--c-warning-soft); color: var(--c-warning); }
.badge--s-sent, .badge--s-viewed, .badge--s-negotiation { background: var(--c-info-soft); color: var(--c-info); }
.badge--s-approved, .badge--s-accepted { background: var(--c-success-soft); color: var(--c-success); }
.badge--s-rejected, .badge--s-expired { background: var(--c-danger-soft); color: var(--c-danger); }
.badge--s-superseded, .badge--s-cancelled, .badge--s-not_required { background: var(--c-surface-2); color: var(--c-text-muted); }
/* Onboarding statuses (Phase H) reuse the same soft-badge vocabulary. */
.badge--s-in_progress { background: var(--c-info-soft); color: var(--c-info); }
.badge--s-completed, .badge--s-done { background: var(--c-success-soft); color: var(--c-success); }

.tabs { display: flex; gap: var(--s-2); border-bottom: 1px solid var(--c-border); margin-bottom: var(--s-4); flex-wrap: wrap; }
.tabs a { padding: var(--s-2) var(--s-3); color: var(--c-text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tabs a.is-active { color: var(--c-primary); border-bottom-color: var(--c-primary); font-weight: var(--fw-semi); }

.levels { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; font-size: var(--fs-xs); }
.levels__step { padding: 2px 8px; border-radius: 999px; background: var(--c-surface-2); color: var(--c-text-muted); border: 1px solid var(--c-border); }
.levels__step.is-done { background: var(--c-success-soft); color: var(--c-success); border-color: transparent; }
.levels__step.is-current { background: var(--c-warning-soft); color: var(--c-warning); border-color: transparent; font-weight: var(--fw-semi); }
.levels__step.is-rejected { background: var(--c-danger-soft); color: var(--c-danger); border-color: transparent; }

.notice { padding: var(--s-3) var(--s-4); border-radius: var(--r-md, 8px); font-size: var(--fs-sm); margin-bottom: var(--s-3); }
.notice--warning { background: var(--c-warning-soft); color: var(--c-warning); }
.notice--info { background: var(--c-info-soft); color: var(--c-info); }
.notice--danger { background: var(--c-danger-soft); color: var(--c-danger); }

.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
@media (max-width: 760px) { .split-2 { grid-template-columns: 1fr; } }

/* ─── Kanban pipeline board ─── */
.kanban-board {
  display: flex; gap: var(--s-3); overflow-x: auto; padding-bottom: var(--s-4);
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.kanban-col-card { min-width: 280px; max-width: 280px; flex-shrink: 0; scroll-snap-align: start; }
.kanban-card {
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  border-radius: var(--r-md); padding: var(--s-3); margin-bottom: var(--s-2);
  cursor: grab;
}
@media (max-width: 640px) {
  /* One card-width per snap on a phone so the board reads as "swipe
     between columns" instead of a sliver of two half-visible columns. */
  .kanban-col-card { min-width: 82vw; max-width: 82vw; }
}

/* ─── Mobile navigation drawer ───
   Base state (no JS, or JS disabled): the sidebar simply stacks above the
   content, exactly like it always has — nothing to toggle, so the toggle
   button stays hidden. The drawer script (base.html) adds `js` to <html>
   as soon as it runs, which is what unlocks the off-canvas behaviour below;
   the page is fully navigable either way. */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
}

@media (max-width: 900px) {
  html.js .menu-toggle { display: inline-flex; }
  html.js .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50;
    width: var(--sidebar-w-drawer); height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--sh-3);
  }
  html.js .sidebar.is-open { transform: translateX(0); }
  html.js .sidebar-overlay.is-open { display: block; }
}

/* ─── Mobile forms & tap targets ───
   iOS Safari zooms the page on focus if an input's font-size is under
   16px, and a 44x44 hit area is the baseline for anything tappable — both
   only matter below tablet width, so desktop density is untouched. */
@media (max-width: 640px) {
  .input, .form-row input, .form-row select, .form-row textarea {
    font-size: 16px;
    min-height: 44px;
  }
  .btn { min-height: 44px; }
  .menu-toggle { min-height: 44px; min-width: 44px; }
}
