/* Problem Solved Admin — mobile-first UI
   ──────────────────────────────────────── */

/* ── Design tokens (light) ─────────────────────────────────────── */
:root {
  /* Brand — exact, never vary */
  --navy:       #1b2a41;
  --navy-deep:  #11192b;
  --blue:       #08088d;
  --red:        #e31010;
  --accent:     #e31010;   /* alias for --red, used in inline template styles */

  /* Surfaces */
  --bg:         #eef0f5;
  --surface:    #ffffff;
  --surface-2:  #f4f6fb;
  --border:     #dde3ee;
  --border-2:   #c6d0e4;

  /* Text */
  --ink:        #1a1f2e;
  --muted:      #5c6b82;
  --subtle:     #8c9db8;

  /* --line and --paper were used by the pager and calendar but never defined,
     so those rules always fell back to hard-coded light greys — which meant
     white controls in dark mode. Aliasing them to real tokens here makes both
     components follow the theme; the alias resolves per theme automatically,
     because the dark blocks redefine --border and --surface-2 on :root. */
  --line:       var(--border);
  --paper:      var(--surface-2);

  /* Interactive control edges and disabled labels. Separate from --border and
     --subtle because a control has to be identifiable, not merely decorative:
     these are picked to clear 3:1 against --surface in BOTH themes. */
  --control-border:   #7f8ca6;   /* 3.38:1 on white */
  --control-disabled: #78849c;   /* 3.76:1 on white */

  /* Semantic */
  --green:        #15803d;
  --green-bg:     #f0fdf4;
  --green-border: #bbf7d0;
  --amber:        #b45309;
  --amber-bg:     #fffbeb;
  --amber-border: #fde68a;
  --danger:       #dc2626;
  --danger-bg:    #fef2f2;
  --danger-border:#fecaca;

  /* Status tokens */
  --s-new:        #1d4ed8;
  --s-contacted:  #c2410c;
  --s-estimated:  #7c3aed;
  --s-closed:     #15803d;

  /* Type */
  --display: "Oswald", system-ui, sans-serif;
  --body:    "Source Sans 3", system-ui, sans-serif;

  /* Layout */
  --topbar-h:  56px;
  --sidebar-w: 220px;

  /* Shape */
  --r:    6px;
  --r-lg: 10px;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(26,31,46,.06);
  --shadow-sm: 0 1px 3px rgba(26,31,46,.08), 0 1px 2px rgba(26,31,46,.04);
  --shadow-md: 0 4px 16px rgba(26,31,46,.10), 0 2px 4px rgba(26,31,46,.05);
  --shadow-lg: 0 20px 48px rgba(26,31,46,.18);
  --shadow-in: inset 0 1px 2px rgba(26,31,46,.05);
}

/* ── Dark tokens ─────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #0d1520;
    --surface:    #172133;
    --surface-2:  #1c293f;
    --border:     #273a54;
    --border-2:   #324d6a;
    --ink:        #e2edf8;
    --muted:      #93b2cc;
    --subtle:     #6e8fab;
    --control-border:   #55789f;   /* 3.51:1 on --surface */
    --control-disabled: #6e8fab;   /* 4.75:1 on --surface */
    --blue:       #6baae8;
    --green-bg:     #052e16;
    --green-border: #166534;
    --amber-bg:     #1c1205;
    --amber-border: #78350f;
    --danger-bg:    #2b0c0c;
    --danger-border:#7f1d1d;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.25);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.18);
    --shadow-md: 0 4px 16px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.18);
    --shadow-in: inset 0 1px 2px rgba(0,0,0,.2);
  }
}
:root[data-theme="dark"] {
  --bg:         #0d1520;
  --surface:    #172133;
  --surface-2:  #1c293f;
  --border:     #273a54;
  --border-2:   #324d6a;
  --ink:        #e2edf8;
  --muted:      #93b2cc;
  --subtle:     #6e8fab;
  --control-border:   #55789f;   /* 3.51:1 on --surface */
  --control-disabled: #6e8fab;   /* 4.75:1 on --surface */
  --blue:       #6baae8;
  --green-bg:     #052e16;
  --green-border: #166534;
  --amber-bg:     #1c1205;
  --amber-border: #78350f;
  --danger-bg:    #2b0c0c;
  --danger-border:#7f1d1d;
  --shadow-xs: 0 1px 2px rgba(0,0,0,.25);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.18);
  --shadow-md: 0 4px 16px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.18);
  --shadow-in: inset 0 1px 2px rgba(0,0,0,.2);
}

/* ── Base reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 600;
  text-wrap: balance;
  margin: 0 0 .4em;
}

a { color: var(--blue); }
img { max-width: 100%; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ── Admin layout — mobile first ────────────────────────────────── */

/* default (mobile): sidebar off-canvas, content full-width */
.admin-layout { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 60;
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.nav-open .sidebar {
  transform: translateX(0);
  box-shadow: var(--shadow-lg);
}

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11,20,36,.65);
  z-index: 55;
}
body.nav-open .nav-backdrop { display: block; }

.admin-main {
  padding: 1.25rem 1rem 2rem;
}

/* desktop (768px+): grid layout, sidebar locked in */
@media (min-width: 768px) {
  .admin-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "topbar topbar" "sidebar main";
    min-height: 100vh;
  }
  .topbar     { grid-area: topbar; }
  .sidebar    { grid-area: sidebar; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); transform: none !important; box-shadow: none !important; }
  .admin-main { grid-area: main; padding: 1.75rem 2rem 3rem; max-width: 1300px; width: 100%; }
  .menu-toggle  { display: none !important; }
  .nav-backdrop { display: none !important; }
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  background: var(--navy-deep);
  color: #fff;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  gap: .75rem;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex: 1;
  min-width: 0;
}

.topbar__brand {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: .03em;
  white-space: nowrap;
}
.topbar__brand span {
  color: #6e92b8;
  font-weight: 400;
  font-size: .78rem;
  margin-left: .5rem;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

.topbar__site-link {
  color: #6e92b8;
  text-decoration: none;
  font-size: .82rem;
  padding: .25rem .5rem;
  border-radius: var(--r);
  transition: color .1s;
}
.topbar__site-link:hover { color: #fff; }

.topbar__user {
  font-size: .78rem;
  color: #6e92b8;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}
.topbar__user em {
  font-style: normal;
  font-size: .68rem;
  color: #7499b8;
  text-transform: capitalize;
}

@media (max-width: 480px) {
  .topbar__user, .topbar__site-link { display: none; }
}

/* ── Hamburger ───────────────────────────────────────────────────── */
.menu-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 9px;
  background: transparent;
  border: none;
  border-radius: var(--r);
  cursor: pointer;
  flex-shrink: 0;
}
.menu-toggle span {
  display: block;
  height: 2px;
  background: #c0d5ec;
  border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}
body.nav-open .menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.nav-open .menu-toggle span:nth-child(2) { opacity: 0; transform: scaleX(0); }
body.nav-open .menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.menu-toggle:focus-visible { outline: 2px solid rgba(255,255,255,.5); }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  background: var(--navy);
  padding: 1rem 0;
  border-right: 1px solid rgba(255,255,255,.05);
}

.sidebar__nav {
  list-style: none;
  margin: 0;
  padding: 0 .5rem;
}
.sidebar__nav li { margin: 2px 0; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .85rem;
  font-family: var(--display);
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #8aaec8;
  text-decoration: none;
  border-radius: var(--r);
  transition: background .1s, color .1s;
}
.sidebar__link:hover {
  background: rgba(255,255,255,.06);
  color: #cce0f5;
}
.sidebar__link.active {
  background: rgba(227,16,16,.1);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--red);
}
.sidebar__icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: .6;
}
.sidebar__link.active .sidebar__icon,
.sidebar__link:hover  .sidebar__icon { opacity: 1; }

/* Sub-navigation (super admin section) */
.sidebar__sub {
  list-style: none;
  margin: .25rem 0 .5rem 2.4rem;
  padding: 0;
  border-left: 1px solid rgba(255,255,255,.1);
}
.sidebar__sub li { margin: 1px 0; }
.sidebar__sub-link {
  display: block;
  padding: .35rem .75rem;
  font-family: var(--display);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: rgba(255,255,255,.42);
  text-decoration: none;
  border-radius: 0 var(--r) var(--r) 0;
  transition: color .1s, background .1s;
}
.sidebar__sub-link:hover { color: #cce0f5; background: rgba(255,255,255,.05); }
.sidebar__sub-link.active { color: #fff; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font-family: var(--display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: .78rem;
  padding: .5rem 1.05rem;
  min-height: 36px;
  border-radius: var(--r);
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s, box-shadow .12s, opacity .12s;
  line-height: 1;
}

.btn--primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  box-shadow: 0 1px 3px rgba(8,8,141,.25);
}
.btn--primary:hover {
  opacity: .88;
  box-shadow: 0 3px 10px rgba(8,8,141,.3);
}

.btn--ghost {
  background: rgba(255,255,255,.07);
  color: #8ab0ce;
  border-color: rgba(255,255,255,.12);
}
.btn--ghost:hover {
  background: rgba(255,255,255,.13);
  color: #fff;
}

/* Ghost on light backgrounds (forms, cards) */
.form-actions .btn--ghost,
.form-card    .btn--ghost,
.detail-card  .btn--ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border-2);
}
.form-actions .btn--ghost:hover,
.form-card    .btn--ghost:hover,
.detail-card  .btn--ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--border-2);
}

.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(220,38,38,.3);
}
.btn--danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.btn--sm  { padding: .3rem .65rem; font-size: .72rem; min-height: 30px; }
.btn--lg  { padding: .7rem 1.5rem; font-size: .85rem; min-height: 44px; }
.btn--full { width: 100%; }

/* ── Page header ─────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.5rem;
  color: var(--ink);
  margin: 0;
  line-height: 1.15;
}
.page-header p {
  color: var(--muted);
  margin: .2em 0 0;
  font-size: .9rem;
}
.page-header__eyebrow {
  font-family: var(--display);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--red);
  margin: 0 0 .2em;
}
.header-actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-shrink: 0;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: .82rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: .35rem;
  transition: color .1s;
}
.back-link:hover { color: var(--blue); }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 1.75rem 0 .75rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.section-header h2 {
  font-family: var(--display);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0;
}

/* ── KPI stat cards ──────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.kpi-card__label {
  font-family: var(--display);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  margin-bottom: .35rem;
}
.kpi-card__value {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi-card__sub {
  font-size: .78rem;
  color: var(--muted);
  margin-top: .3rem;
}
.kpi-card--accent .kpi-card__value { color: var(--red); }
.kpi-card--action .kpi-card__value { color: var(--blue); }
.kpi-card--green  .kpi-card__value { color: var(--green); }

/* ── Filter tabs ─────────────────────────────────────────────────── */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }

.filter-tab {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem .9rem;
  font-family: var(--display);
  font-size: .73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .1s, border-color .1s;
  white-space: nowrap;
}
.filter-tab:hover { color: var(--ink); }
.filter-tab.active { color: var(--ink); border-bottom-color: var(--red); }

.filter-tab__count {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .66rem;
  padding: .08rem .4rem;
  border-radius: 99px;
  font-family: var(--body);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.filter-tab.active .filter-tab__count {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* ── Table card ──────────────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Wrap tables in this for mobile horizontal scroll */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.leads-table thead {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.leads-table th {
  text-align: left;
  padding: .65rem 1rem;
  font-family: var(--display);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  white-space: nowrap;
}
.leads-table td {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.leads-table tr:last-child td { border-bottom: none; }
.leads-table tbody tr:hover { background: var(--surface-2); }
.leads-table tbody tr.is-deleting { opacity: .35; pointer-events: none; }

/* ── Cell helpers ────────────────────────────────────────────────── */
.cell-date    { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.cell-name    { font-weight: 600; color: var(--ink); }
.cell-contact { color: var(--muted); font-size: .85rem; }
.cell-contact a { color: var(--blue); text-decoration: none; }
.cell-contact a:hover { text-decoration: underline; }
.cell-message {
  color: var(--muted);
  font-size: .85rem;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-actions { white-space: nowrap; }
.cell-link { color: var(--blue); text-decoration: none; font-size: .88rem; }
.cell-link:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.total-row td {
  padding: .75rem 1rem;
  border-top: 2px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Status select (inline table) ───────────────────────────────── */
.status-select {
  font-family: var(--display);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .28rem 1.6rem .28rem .6rem;
  border-radius: 99px;
  border: 1.5px solid currentColor;
  cursor: pointer;
  appearance: none;
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235c6b82'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .45rem center;
}
.status-select[data-status="new"]       { color: var(--s-new);       border-color: var(--s-new); }
.status-select[data-status="contacted"] { color: var(--s-contacted); border-color: var(--s-contacted); }
.status-select[data-status="estimated"] { color: var(--s-estimated); border-color: var(--s-estimated); }
.status-select[data-status="closed"]    { color: var(--s-closed);    border-color: var(--s-closed); }
.status-select.saving { opacity: .5; pointer-events: none; }

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--muted);
}
.empty-state p { margin: 0; font-size: .95rem; }

/* ── Alert banners ───────────────────────────────────────────────── */
.alert {
  position: relative;
  padding: .8rem 2.25rem .8rem 1rem; /* right padding leaves room for close btn */
  border-radius: var(--r);
  font-size: .9rem;
  margin-bottom: 1.25rem;
  transition: opacity .3s, transform .3s;
}
.alert--success { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green-border); }
.alert--warning { background: var(--amber-bg);  color: var(--amber);  border: 1px solid var(--amber-border); }
.alert--danger  { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.alert-close {
  position: absolute;
  top: .6rem;
  right: .6rem;
  background: none;
  border: none;
  cursor: pointer;
  color: currentColor;
  opacity: .55;
  padding: .2rem;
  border-radius: 3px;
  line-height: 0;
}
.alert-close:hover { opacity: 1; }

/* ── Password visibility toggle ─────────────────────────────────── */
.input-pw-wrap {
  position: relative;
  display: block;
}
.input-pw-wrap .form-input,
.input-pw-wrap input {
  padding-right: 2.75rem;
  width: 100%;
}
.input-pw-toggle {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: .3rem;
  cursor: pointer;
  color: var(--muted);
  border-radius: var(--r);
  line-height: 0;
  transition: color .15s;
}
.input-pw-toggle:hover { color: var(--ink); }
.input-pw-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

/* ── Submit-button loading spinner ──────────────────────────────── */
.btn--loading {
  opacity: .72;
  cursor: not-allowed;
  pointer-events: none;
}
.btn--loading::after {
  content: '';
  display: inline-block;
  width: .8em;
  height: .8em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ui-spin .65s linear infinite;
  margin-left: .45rem;
  vertical-align: middle;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* ── Character counter ───────────────────────────────────────────── */
.char-counter {
  font-size: .75rem;
  color: var(--muted);
  text-align: right;
  margin-top: .2rem;
  transition: color .2s;
}
.char-counter--warn { color: var(--danger); }

/* ── Detail cards ────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.detail-grid--2 { grid-template-columns: repeat(2, 1fr); }
.detail-grid--3 { grid-template-columns: repeat(3, 1fr); }

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-xs);
}
.detail-card--full { grid-column: 1 / -1; }

.detail-card__title {
  font-family: var(--display);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--subtle);
  margin: 0 0 .85rem;
}

.detail-fields { margin: 0; display: grid; gap: .6rem; }
.detail-field {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: .5rem;
  font-size: .88rem;
}
.detail-field dt { color: var(--muted); }
.detail-field dd { margin: 0; font-weight: 500; color: var(--ink); }
.detail-field dd a { color: var(--blue); text-decoration: none; }
.detail-field dd a:hover { text-decoration: underline; }
.detail-notes { margin: 0; font-size: .9rem; color: var(--ink); white-space: pre-wrap; line-height: 1.6; }
.value--money { font-weight: 700; color: var(--ink); font-size: 1.1rem; font-variant-numeric: tabular-nums; }

/* ── Forms ───────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.75rem;
  max-width: 860px;
  box-shadow: var(--shadow-sm);
}

.form-section {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
  margin-top: 1.25rem;
}
.form-section__title {
  font-family: var(--display);
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  margin: 0 0 1rem;
}

.form-grid {
  display: grid;
  gap: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}

/* single-column by default (mobile) */
.form-grid--2 { grid-template-columns: 1fr; }

/* two columns on wider screens */
@media (min-width: 600px) {
  .form-grid--2 { grid-template-columns: repeat(2, 1fr); }
}

.form-group { display: grid; gap: .3rem; }
.form-group--full { grid-column: 1 / -1; }
.form-group.has-error .form-input { border-color: var(--danger) !important; }
.form-group.has-error .form-input:focus { box-shadow: 0 0 0 3px rgba(220,38,38,.12); }

.form-label {
  font-family: var(--display);
  font-size: .73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink);
}
.form-label--check {
  display: flex;
  align-items: center;
  gap: .45rem;
  text-transform: none;
  font-family: var(--body);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0;
}
.req { color: var(--red); }

.form-input {
  font-family: var(--body);
  font-size: 1rem;          /* 16px — prevents iOS zoom */
  padding: .65rem .85rem;
  min-height: 44px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  transition: border-color .12s, box-shadow .12s;
  box-shadow: var(--shadow-in);
  -webkit-appearance: none;
  appearance: none;
}
.form-input::placeholder { color: var(--subtle); }
.form-input:hover:not(:focus) { border-color: var(--border-2); }
.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(8,8,141,.1);
}

.form-select { cursor: pointer; }
.form-textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}

.form-error {
  font-size: .78rem;
  color: var(--danger);
}
.form-hint { font-size: .8rem; color: var(--muted); margin: .1rem 0 0; line-height: 1.4; }

.form-actions {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  padding-top: 1.25rem;
  margin-top: .5rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ── Material dialog ─────────────────────────────────────────────── */
.material-dialog {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0;
  max-width: 560px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow-lg);
  background: var(--surface);
}
.material-dialog::backdrop {
  background: rgba(11,20,36,.55);
}
.material-dialog form { padding: 1.75rem; }
.material-dialog h3 {
  margin: 0 0 1.25rem;
  font-size: 1.1rem;
  color: var(--ink);
}

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--display);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .18rem .55rem;
  border-radius: 99px;
  white-space: nowrap;
  line-height: 1.4;
}

.badge--active    { background: var(--green-bg); color: var(--green); }
.badge--inactive  { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge--converted { background: #eff6ff; color: #1d4ed8; }
.badge--neutral   { background: var(--surface-2); color: var(--muted); }
.badge--discount  { background: var(--danger-bg); color: var(--danger); }

/* project status */
.badge--pending     { background: #eff6ff; color: #1d4ed8; }
.badge--scheduled   { background: var(--amber-bg); color: var(--amber); }
.badge--in-progress { background: #f5f3ff; color: #7c3aed; }
.badge--completed   { background: var(--green-bg); color: var(--green); }
.badge--cancelled   { background: var(--danger-bg); color: var(--danger); }

/* lead status */
.badge--new        { background: #eff6ff; color: #1d4ed8; }
.badge--contacted  { background: #fff7ed; color: #c2410c; }
.badge--estimated  { background: #f5f3ff; color: #7c3aed; }
.badge--closed     { background: var(--green-bg); color: var(--green); }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  left: 1.25rem;
  max-width: 380px;
  margin-left: auto;
  background: var(--navy);
  color: #e8f0fb;
  padding: .8rem 1.1rem;
  border-radius: var(--r-lg);
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #991b1b; }

/* ── Skill chips ─────────────────────────────────────────────────── */
.skill-chip {
  display: inline-block;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 99px;
  padding: .25rem .85rem;
  font-size: .78rem;
  font-weight: 600;
  margin: 3px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  user-select: none;
}
.skill-chip:hover { border-color: var(--blue); color: var(--blue); }
.skill-chip.selected { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ── Login page ──────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 2fr 3fr;
}

/* Brand panel */
.login-brand {
  background: var(--navy-deep);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3.5rem 3rem;
  position: relative;
  overflow: hidden;
}
.login-brand::before {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: rgba(255,255,255,.04);
  top: -100px;
  right: -140px;
  pointer-events: none;
}
.login-brand::after {
  content: '';
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: rgba(227,16,16,.09);
  bottom: 60px;
  left: -80px;
  pointer-events: none;
}
.login-brand__name {
  font-family: var(--display);
  font-size: 2.6rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: relative;
  z-index: 1;
}
.login-brand__rule {
  width: 2.75rem;
  height: 3px;
  background: var(--red);
  border-radius: 2px;
  margin: .75rem 0 1.1rem;
  position: relative;
  z-index: 1;
}
.login-brand__tagline {
  font-family: var(--body);
  font-size: 1.05rem;
  color: rgba(255,255,255,.5);
  line-height: 1.6;
  position: relative;
  z-index: 1;
  max-width: 280px;
}

/* Form panel */
.login-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  background: var(--bg);
  min-height: 100vh;
}
.login-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 2.75rem 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}
.login-card__eyebrow {
  font-family: var(--display);
  font-size: .72rem;
  font-weight: 700;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: .12em;
  margin-bottom: .4rem;
}
.login-card h1 {
  font-size: 1.8rem;
  color: var(--ink);
  margin-bottom: 1.75rem;
  line-height: 1.1;
  font-family: var(--display);
  font-weight: 600;
}

/* Error */
.login-error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  padding: .7rem .9rem;
  border-radius: var(--r);
  font-size: .875rem;
  margin-bottom: 1.25rem;
}

/* Form fields */
.login-form { display: grid; gap: 1.25rem; }
.login-form__group { display: grid; gap: .35rem; }
.login-form__label {
  font-family: var(--display);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
.login-form__input {
  font-family: var(--body);
  font-size: 1rem;
  padding: .75rem 1rem;
  min-height: 48px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--ink);
  width: 100%;
  transition: border-color .12s, box-shadow .12s, background .12s;
  box-shadow: var(--shadow-in);
}
.login-form__input:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(8,8,141,.1);
}
.login-submit {
  width: 100%;
  padding: .9rem;
  background: var(--navy-deep);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-family: var(--display);
  font-size: .92rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, opacity .15s;
  box-shadow: 0 2px 10px rgba(17,25,43,.35);
  margin-top: .25rem;
}
.login-submit:hover {
  background: #0d1825;
  box-shadow: 0 4px 18px rgba(17,25,43,.45);
}
.login-submit:active { opacity: .88; }

/* Mobile: single column */
@media (max-width: 767px) {
  .login-page { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-panel { background: var(--navy-deep); }
  .login-card {
    box-shadow: none;
    padding: 2.25rem 1.75rem;
  }
  /* Small brand mark above card on mobile */
  .login-panel::before {
    content: 'Problem Solved';
    font-family: var(--display);
    font-size: .85rem;
    font-weight: 700;
    color: rgba(255,255,255,.55);
    text-transform: uppercase;
    letter-spacing: .12em;
    margin-bottom: 1.5rem;
  }
}

/* ── Code / API blocks ───────────────────────────────────────────── */
.api-key-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: .65rem .9rem;
}
.api-key-value {
  flex: 1;
  font-family: "Courier New", Courier, monospace;
  font-size: .85rem;
  word-break: break-all;
}
.code-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1rem 1.2rem;
  font-family: "Courier New", Courier, monospace;
  font-size: .82rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}

/* ── Responsive collapses ────────────────────────────────────────── */
@media (max-width: 767px) {
  .detail-grid--2,
  .detail-grid--3 { grid-template-columns: 1fr; }
  .detail-card--full { grid-column: 1; }
}

/* ── Print ───────────────────────────────────────────────────────── */
@media print {
  .topbar, .sidebar, .menu-toggle, .nav-backdrop, .toast { display: none !important; }
  .admin-main { padding: 0; }
  .form-card, .detail-card, .table-card { box-shadow: none; border: 1px solid #ccc; }
}

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.1rem;
  padding-top: .9rem;
  border-top: 1px solid var(--line);
}
.pager__summary { font-size: .84rem; color: var(--muted); }
.pager__summary strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.pager__controls { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.pager__link {
  display: inline-block;
  min-width: 2rem;
  padding: .32rem .58rem;
  text-align: center;
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-decoration: none;
  /* A control's edge has to be identifiable, so this uses --control-border
     (3:1 against the surface) rather than the decorative --border. */
  border: 1px solid var(--control-border);
  border-radius: 5px;
  background: var(--surface);
  transition: background .12s, border-color .12s;
}
.pager__link:hover { background: var(--paper); border-color: var(--ink); }
.pager__link.is-current {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-weight: 600;
}
/* Disabled, not invisible. WCAG exempts inactive controls from the text
   minimum, but at 1.84:1 the Prev button could not be seen at all, so a
   visitor could not tell it existed. This reads as clearly secondary while
   staying legible, and the arrow keeps its meaning. */
.pager__link.is-disabled {
  color: var(--control-disabled);
  background: var(--paper);
  border-color: var(--border-2);
  pointer-events: none;
}
.pager__gap { padding: 0 .2rem; color: var(--muted); font-size: .85rem; }
@media (max-width: 560px) {
  .pager { justify-content: center; }
  .pager__summary { width: 100%; text-align: center; }
}

/* ── Project calendar ─────────────────────────────────────────────────────── */
.cal-title {
  font-size: 1.15rem;
  margin: 0 0 .6rem;
  color: var(--ink);
}
.cal-legend {
  display: flex; flex-wrap: wrap; gap: .3rem 1rem;
  margin-bottom: .9rem; font-size: .78rem; color: var(--muted);
}
.cal-legend__item { display: inline-flex; align-items: center; gap: .35rem; }
.cal-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* Status colours, shared by legend dots and day chips */
.cal-dot--pending,      .cal-chip--pending      { background: #d29922; }
.cal-dot--scheduled,    .cal-chip--scheduled    { background: #0969da; }
.cal-dot--in_progress,  .cal-chip--in_progress  { background: #8250df; }
.cal-dot--completed,    .cal-chip--completed    { background: #1a7f37; }
.cal-dot--cancelled,    .cal-chip--cancelled    { background: #8b949e; }

.cal-scroll { overflow-x: auto; }
.cal {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  table-layout: fixed;
}
.cal thead th {
  padding: .5rem .6rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-weight: 600;
}
.cal-cell {
  vertical-align: top;
  height: 104px;
  padding: .35rem .4rem;
  border: 1px solid var(--line);
  font-size: .8rem;
}
.cal-cell.is-outside { background: var(--paper); }
.cal-cell.is-outside .cal-cell__num { color: var(--subtle); }
/* --danger-bg is a red-tinted surface in BOTH themes; #fff8f6 was a pale
   pink that turned the current day into a white block in dark mode. */
.cal-cell.is-today { background: var(--danger-bg); box-shadow: inset 0 0 0 2px var(--red); }
.cal-cell__num {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  margin-bottom: .25rem;
  display: flex; align-items: center; gap: .35rem;
}
.cal-cell__today {
  font-size: .6rem; text-transform: uppercase; letter-spacing: .05em;
  background: var(--red, #e63012); color: #fff;
  border-radius: 3px; padding: 0 4px; font-weight: 700;
}
.cal-chip {
  display: block;
  color: #fff;
  text-decoration: none;
  font-size: .7rem;
  line-height: 1.25;
  padding: 2px 5px;
  border-radius: 3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-chip:hover { filter: brightness(1.12); }
.cal-more { font-size: .68rem; color: var(--muted); }

@media (max-width: 700px) {
  .cal-cell { height: 84px; }
  .cal-chip { font-size: .64rem; }
}
