/* Visual style follows the Coul St OCPP dashboard (kcocpp): Tailwind gray + indigo palette. */
:root {
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-900: #111827;

  --bg: #ffffff;
  --surface: #ffffff;
  --subtle: var(--gray-50);          /* table heads, row hover */
  --text: var(--gray-900);
  --text-2: var(--gray-600);
  --muted: var(--gray-500);
  --placeholder: var(--gray-400);
  --border: var(--gray-200);
  --input-border: var(--gray-300);
  --nav-active-bg: var(--gray-100);
  --nav-hover-bg: var(--gray-50);

  --accent: #4f46e5;                 /* indigo-600 */
  --accent-hover: #6366f1;           /* indigo-500 */
  --link: #4f46e5;
  --link-hover: #6366f1;
  --accent-soft: #eef2ff;            /* indigo-50 */

  --danger: #dc2626;                 /* red-600 */
  --danger-hover: #ef4444;
  --danger-soft: rgb(239 68 68 / .1);
  --danger-border: rgb(239 68 68 / .4);
  --danger-text: #b91c1c;

  --green-bg: #dcfce7;  --green-text: #166534;  --green-dot: #22c55e;
  --amber-bg: #fef3c7;  --amber-text: #92400e;  --amber-dot: #f59e0b;
  --blue-bg: #e0e7ff;   --blue-text: #3730a3;   --blue-dot: #6366f1;
  --gray-bg: var(--gray-100); --gray-text: var(--gray-600); --gray-dot: var(--gray-400);

  --input-bg: #ffffff;
  --button-bg: #ffffff;
  --button-border: var(--gray-300);
  --logo-light: block;
  --logo-dark: none;

  --radius: 0.375rem;                /* rounded-md */
  --radius-lg: 0.5rem;               /* rounded-lg */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);
  --frame: 120rem;                   /* header + page area: the same on every page */
  --content: 80rem;                  /* readable width for forms and detail pages (max-w-7xl) */
  --gutter: 2rem;
  color-scheme: light;
}

/*
 * Theme: <html data-theme="light|dark"> forces a theme (set from the theme cookie);
 * with no attribute the OS preference is used. The dark values appear twice below
 * (OS-dark and forced-dark) because CSS can't share one block between the two.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--gray-900);
    --surface: var(--gray-900);
    --subtle: rgb(255 255 255 / .05);
    --text: #ffffff;
    --text-2: var(--gray-300);
    --muted: var(--gray-400);
    --placeholder: var(--gray-500);
    --border: rgb(255 255 255 / .1);
    --input-border: var(--gray-700);
    --nav-active-bg: rgb(255 255 255 / .1);
    --nav-hover-bg: rgb(255 255 255 / .05);

    --accent: #6366f1;
    --accent-hover: #818cf8;
    --link: #818cf8;
    --link-hover: #a5b4fc;
    --accent-soft: rgb(99 102 241 / .15);

    --danger: #ef4444;
    --danger-hover: #f87171;
    --danger-text: #fca5a5;

    --green-bg: rgb(34 197 94 / .1);  --green-text: #4ade80;
    --amber-bg: rgb(245 158 11 / .1); --amber-text: #fbbf24;
    --blue-bg: rgb(99 102 241 / .15); --blue-text: #a5b4fc;
    --gray-bg: rgb(255 255 255 / .1); --gray-text: var(--gray-400);

    --input-bg: rgb(255 255 255 / .05);
    --button-bg: rgb(255 255 255 / .05);
    --button-border: rgb(255 255 255 / .1);
    --logo-light: none;
    --logo-dark: block;

    --shadow-sm: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: var(--gray-900);
    --surface: var(--gray-900);
    --subtle: rgb(255 255 255 / .05);
    --text: #ffffff;
    --text-2: var(--gray-300);
    --muted: var(--gray-400);
    --placeholder: var(--gray-500);
    --border: rgb(255 255 255 / .1);
    --input-border: var(--gray-700);
    --nav-active-bg: rgb(255 255 255 / .1);
    --nav-hover-bg: rgb(255 255 255 / .05);

    --accent: #6366f1;
    --accent-hover: #818cf8;
    --link: #818cf8;
    --link-hover: #a5b4fc;
    --accent-soft: rgb(99 102 241 / .15);

    --danger: #ef4444;
    --danger-hover: #f87171;
    --danger-text: #fca5a5;

    --green-bg: rgb(34 197 94 / .1);  --green-text: #4ade80;
    --amber-bg: rgb(245 158 11 / .1); --amber-text: #fbbf24;
    --blue-bg: rgb(99 102 241 / .15); --blue-text: #a5b4fc;
    --gray-bg: rgb(255 255 255 / .1); --gray-text: var(--gray-400);

    --input-bg: rgb(255 255 255 / .05);
    --button-bg: rgb(255 255 255 / .05);
    --button-border: rgb(255 255 255 / .1);
    --logo-light: none;
    --logo-dark: block;

    --shadow-sm: none;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 0.875rem/1.5rem ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; font-weight: 500; }
a:hover { color: var(--link-hover); }
h1 { font-size: 1.5rem; line-height: 2rem; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 1.5rem; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
h2 { font-size: 1rem; line-height: 1.75rem; font-weight: 600; margin: 2rem 0 .75rem; }
h3 { font-size: .875rem; font-weight: 600; margin: 1rem 0 .25rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .8125rem; }
.center { text-align: center; }
.empty { color: var(--muted); padding: .25rem 0 .75rem; margin: 0; }

/* ---------- top nav (h-16, max-w-7xl) ---------- */
/* Shown on every page when not running in production (see devBanner in src/ui.js). */
.dev-banner {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .25rem .75rem;
  padding: .375rem var(--gutter); font-size: .8125rem; text-align: center;
  background: repeating-linear-gradient(-45deg, var(--amber-bg) 0 1rem, color-mix(in srgb, var(--amber-bg) 60%, transparent) 1rem 2rem);
  color: var(--amber-text); border-bottom: 1px solid color-mix(in srgb, var(--amber-dot) 50%, transparent);
}
.dev-banner strong { text-transform: uppercase; letter-spacing: .05em; }

.topbar {
  display: flex; align-items: center; gap: 2rem;
  min-height: 4rem;
  padding: .5rem max(var(--gutter), calc((100% - var(--frame)) / 2 + var(--gutter)));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .75rem; color: var(--text); font-weight: 600; }
.brand:hover { color: var(--text); }
.logo { height: 2rem; width: auto; }
.logo-light { display: var(--logo-light); }
.logo-dark { display: var(--logo-dark); }
.logo-lg { height: 2.5rem; margin: 0 auto; }
.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.nav-link {
  display: inline-block; padding: .5rem .75rem; border-radius: var(--radius);
  font: inherit; font-weight: 500; color: var(--text-2);
  background: none; border: none; cursor: pointer;
}
.nav-link:hover { background: var(--nav-hover-bg); color: var(--text); }
.nav-link.active { background: var(--nav-active-bg); color: var(--text); }
.topbar .search { flex: 1; min-width: 10rem; max-width: 20rem; }
.topbar .search input { width: 100%; }
.me { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.me form { margin: 0; }
.theme-toggle { display: inline-flex; align-items: center; gap: .375rem; padding: .5rem; }
.theme-toggle svg { width: 1.25rem; height: 1.25rem; }
.theme-toggle .label { font-weight: 500; }
.auth-theme { display: flex; justify-content: center; margin-top: 2rem; }

/*
 * Every page shares one frame with the header, so the logo, menu and page title never shift
 * between pages. Most pages keep a readable content width, left-aligned under the logo;
 * list pages with big tables (body.wide) use the whole frame.
 */
main { max-width: var(--frame); margin: 0 auto; padding: 2rem var(--gutter) 4rem; }
.content { max-width: var(--content); }
body.wide .content { max-width: none; }

/* ---------- controls ---------- */
[hidden] { display: none !important; }   /* hidden must win over display rules on buttons etc. */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--input-bg);
  border: none; border-radius: var(--radius);
  outline: 1px solid var(--input-border); outline-offset: -1px;
  padding: .375rem .75rem; line-height: 1.5rem;
}
/* Drop-downs draw their own arrow: the native one ignores padding in some browsers and sits on the edge.
   Two small gradient triangles make the chevron, in the theme's muted color. */
select {
  appearance: none; -webkit-appearance: none; padding-right: 2.25rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1.125rem) 55%, calc(100% - .8125rem) 55%;
  background-size: .3125rem .3125rem; background-repeat: no-repeat;
}
select option { background: var(--surface); color: var(--text); }
/* Same height for text boxes, date pickers and drop-downs so side-by-side fields line up. */
input:not([type=checkbox]):not([type=radio]):not([type=file]), select { height: 2.25rem; }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
input[type=checkbox], input[type=radio] { outline: none; accent-color: var(--accent); width: 1rem; height: 1rem; padding: 0; }
textarea { width: 100%; resize: vertical; }

button, .button {
  font: inherit; font-weight: 600; cursor: pointer; display: inline-block; white-space: nowrap;
  padding: .375rem .75rem; border-radius: var(--radius); border: none;
  color: var(--text); background: var(--button-bg);
  outline: 1px solid var(--button-border); outline-offset: -1px;
  box-shadow: var(--shadow-sm);
}
button:hover, .button:hover { background: var(--subtle); color: var(--text); }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary, .button.primary { background: var(--accent); color: #fff; outline: none; }
button.primary:hover, .button.primary:hover { background: var(--accent-hover); color: #fff; }
button.danger, .button.danger { color: var(--danger); }
button.block { display: flex; justify-content: center; width: 100%; }
button.link, button.nav-link { outline: none; box-shadow: none; }
button.link { background: none; padding: 0; color: var(--link); font-weight: 500; }
button.link:hover { background: none; color: var(--link-hover); }
button.link.danger { color: var(--danger); }
button.link.danger:hover { color: var(--danger-hover); }
form.inline { display: inline; }

.field { display: flex; flex-direction: column; gap: .5rem; }
.field > span { font-weight: 500; color: var(--text); }
.field.checkbox { flex-direction: row; align-items: center; gap: .5rem; }
.field.checkbox > span { font-weight: 400; color: var(--text-2); }
.stack { display: flex; flex-direction: column; gap: 1.25rem; }
/*
 * Forms (.form-grid): one field per line, label to the left of its box in a fixed column.
 * .form-row puts related fields on one line (e.g. First name | Last name, City | State | ZIP);
 * only the first field's label sits in the label column, the rest sit just before their box.
 */
.form-grid { --label-w: 8rem; display: flex; flex-direction: column; gap: .75rem; max-width: 44rem; }
.form-grid h2 { margin: 0 0 .25rem; }
.form-grid .field { flex-direction: row; align-items: center; gap: .75rem; }
.form-grid .field > span:first-child { flex: 0 0 var(--label-w); color: var(--text-2); }
.form-grid .field > input, .form-grid .field > select, .form-grid .field > textarea,
.form-grid .field > .tag-picker-body { flex: 1; min-width: 0; }
.form-grid .field > input[type=datetime-local] { flex: none; }   /* date/time pickers keep their natural width */
.form-grid .field.wide, .form-grid .tag-picker { align-items: flex-start; }
.form-grid .field.wide > span:first-child, .form-grid .tag-picker > span:first-child { padding-top: .375rem; }
.form-grid .field.checkbox, .form-grid .form-actions { margin-left: calc(var(--label-w) + .75rem); }
.form-grid .field.checkbox { gap: .5rem; }
.form-grid .field.checkbox > input { flex: none; }
.form-row { display: flex; gap: 1rem; align-items: center; }
.form-row > .field { flex: 1; min-width: 0; }
.form-row > .field + .field > span:first-child { flex: none; }
.form-row.contact > .field:first-child { flex: 1.6; }        /* Email wider than Phone */
.tag-picker-body { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.tag-picker-body > input { width: 100%; }
.links-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.link-row { display: flex; gap: .5rem; width: 100%; }
.link-row > select { flex: 0 0 10.5rem; }
.link-row > input { flex: 1; min-width: 0; }
@media (max-width: 560px) {
  /* Phones: labels back above their boxes, everything stacked. */
  .form-grid .field { flex-direction: column; align-items: stretch; gap: .375rem; }
  .form-grid .field > span:first-child { flex: none; padding-top: 0; }
  .form-grid .field.checkbox { flex-direction: row; align-items: center; }
  .form-grid .field.checkbox, .form-grid .form-actions { margin-left: 0; }
  .form-row { flex-direction: column; align-items: stretch; gap: .75rem; }
}
.form-actions { display: flex; gap: 1.5rem; align-items: center; }

.errors {
  border: 1px solid var(--danger-border); background: var(--danger-soft); color: var(--danger-text);
  border-radius: var(--radius); padding: .5rem .75rem; margin-bottom: 1rem;
}
.errors ul { margin: 0; padding-left: 1.2rem; }
.errors a { color: inherit; text-decoration: underline; }
.flash {
  border: 1px solid rgb(34 197 94 / .3); background: var(--green-bg); color: var(--green-text);
  border-radius: var(--radius); padding: .5rem .75rem; margin-bottom: 1.5rem;
}
.flash a { color: inherit; font-weight: 600; text-decoration: underline; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.5rem; margin-bottom: 1.5rem; }
.auth-box { max-width: 24rem; margin: 0 auto; padding: 6vh 0 3rem; }
.auth-title { text-align: center; font-size: 1.5rem; line-height: 2.25rem; font-weight: 700; letter-spacing: -0.025em; margin: 2.5rem 0 2rem; }
.auth-box .stack input { width: 100%; }

/* ---------- page structure ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { margin-bottom: 0; }
.page-head p { margin: .25rem 0 0; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; margin: 0 0 1.5rem; }
.filters input[type=search] { flex: 1; min-width: 12rem; }

.detail { display: grid; grid-template-columns: 20rem 1fr; gap: 2rem; align-items: start; }
.detail > section > h2:first-child, .detail > section > .section-head:first-child h2 { margin-top: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; align-items: start; }
.two-col > section > h2:first-child, .two-col > section > .section-head:first-child h2 { margin-top: 0; }
@media (max-width: 860px) {
  /* minmax(0, …) so one wide item can't stretch the whole column past the screen. */
  .detail, .two-col { grid-template-columns: minmax(0, 1fr); }
}

.info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; }
.info dt { color: var(--muted); }
.info dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.info h3 { margin-top: 1.25rem; }
.notes, .timeline .body { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-2); }

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 1.5rem;
  /* Edge shadows appear only when columns are scrolled out of view (the "local" covers hide them at the ends). */
  background:
    linear-gradient(to right, var(--surface) 30%, transparent) left / 2.5rem 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, transparent) right / 2.5rem 100% no-repeat local,
    linear-gradient(to right, rgb(0 0 0 / .15), transparent) left / .875rem 100% no-repeat scroll,
    linear-gradient(to left, rgb(0 0 0 / .15), transparent) right / .875rem 100% no-repeat scroll;
}
table { min-width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .75rem .875rem; vertical-align: top; }
th {
  font-size: .75rem; line-height: 1rem; text-transform: uppercase; letter-spacing: .025em;
  color: var(--muted); font-weight: 600; background: var(--subtle);
}
th a.sort { display: inline-flex; align-items: center; gap: .25rem; color: inherit; font-weight: inherit; white-space: nowrap; }
th a.sort:hover, th a.sort.active { color: var(--text); }
th a.sort .arrow { display: inline-block; width: .75rem; font-size: .625rem; line-height: 1; }
th.num a.sort { flex-direction: row-reverse; }
td { color: var(--muted); border-top: 1px solid var(--border); }
td:first-child { color: var(--text); font-weight: 500; }
tbody tr:hover { background: var(--subtle); }
tr.inactive td { opacity: .6; }
td.nowrap { white-space: nowrap; }
/* Long values (emails, company names…) are cut off with "…"; the full text is in a hover title. */
td.clip { max-width: 13rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td.clip.email { max-width: 15rem; }
td.clip > div { overflow: hidden; text-overflow: ellipsis; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.inline-details summary { list-style: none; cursor: pointer; color: var(--link); font-weight: 500; }
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details .quick-add { margin-top: .5rem; }
.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; padding: .75rem 0; color: var(--muted); }
.pager .pages { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.pager .pages > a, .pager .pages > span { min-width: 2rem; padding: .25rem .5rem; border-radius: var(--radius); text-align: center; }
.pager .pages > a:hover { background: var(--subtle); }
.pager .current { font-weight: 600; color: var(--text); background: var(--subtle); }
.pager .disabled { opacity: .5; }
.pager .gap { min-width: auto; padding: .25rem 0; }
.pager .per-page { display: flex; gap: .5rem; }

/* ---------- badges (rounded-full pill with dot) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .375rem;
  font-size: .75rem; line-height: 1.25rem; font-weight: 500; letter-spacing: normal; text-transform: capitalize;
  padding: 0 .5rem; border-radius: 9999px; vertical-align: middle;
  background: var(--gray-bg); color: var(--gray-text);
}
.badge .dot { width: .375rem; height: .375rem; border-radius: 9999px; background: var(--gray-dot); }
.status-lead { background: var(--amber-bg); color: var(--amber-text); }
.status-lead .dot { background: var(--amber-dot); }
.status-prospect { background: var(--blue-bg); color: var(--blue-text); }
.status-prospect .dot { background: var(--blue-dot); }
.status-customer { background: var(--green-bg); color: var(--green-text); }
.status-customer .dot { background: var(--green-dot); }
/* ---------- tags (user-defined labels; color = Tailwind 500 shade, tinted per theme) ---------- */
.tags { display: inline-flex; flex-wrap: wrap; gap: .25rem; vertical-align: middle; }
.tag {
  --c: #6b7280;
  display: inline-block; font-size: .75rem; line-height: 1.25rem; font-weight: 500; letter-spacing: normal;
  padding: 0 .5rem; border-radius: var(--radius); white-space: nowrap;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: color-mix(in srgb, var(--c) 65%, var(--text));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 30%, transparent);
}
a.tag:hover { color: color-mix(in srgb, var(--c) 85%, var(--text)); background: color-mix(in srgb, var(--c) 22%, transparent); }
.tag-red { --c: #ef4444; }    .tag-orange { --c: #f97316; } .tag-amber { --c: #f59e0b; }
.tag-green { --c: #22c55e; }  .tag-teal { --c: #14b8a6; }   .tag-blue { --c: #3b82f6; }
.tag-indigo { --c: #6366f1; } .tag-purple { --c: #a855f7; } .tag-pink { --c: #ec4899; }
h1 .tags { font-size: 1rem; }

.tag-options { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.tag-option { cursor: pointer; }
.tag-option input { position: absolute; opacity: 0; pointer-events: none; }
.tag-option .tag { padding: .125rem .625rem; font-size: .8125rem; opacity: .7; background: transparent; }
.tag-option .tag::before { content: "+ "; }
.tag-option input:checked + .tag { opacity: 1; background: color-mix(in srgb, var(--c) 14%, transparent); }
.tag-option input:checked + .tag::before { content: "✓ "; }
.tag-option:hover .tag { opacity: 1; }
.tag-option input:focus-visible + .tag { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Inline tag editor on contact/company pages */
.tag-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
/* Record name, status and tags on one line */
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; }
.title-row h1 { margin: 0; }
.button.small { font-size: .8125rem; line-height: 1.25rem; padding: .125rem .625rem; }
.tag-menu { position: relative; }
.tag-menu > summary { list-style: none; }
.tag-menu > summary::-webkit-details-marker { display: none; }
.tag-menu[open] > summary { background: var(--subtle); }
.tag-popover {
  position: absolute; z-index: 20; top: calc(100% + .5rem); left: 0;
  width: min(24rem, calc(100vw - 2rem));
  display: flex; flex-direction: column; gap: .75rem;
  padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
}
.tag-popover .tag-options { margin: 0; max-height: 14rem; overflow-y: auto; }
@media (max-width: 640px) {
  /* Phones: the panel spans the title row instead of starting at the button and running off-screen. */
  .title-row { position: relative; }
  .tag-menu { position: static; }
  .tag-popover { width: 100%; }
}
.tag-popover-head { display: flex; justify-content: space-between; align-items: baseline; }
.tag-popover-actions { display: flex; gap: 1rem; align-items: center; }
.tag-popover input[type=text] { width: 100%; }

.tag-edit { display: flex; gap: .5rem; flex-wrap: wrap; }
.tag-edit input[type=text] { width: 12rem; }

.count { font-size: .75rem; color: var(--muted); font-weight: 500; margin-left: .25rem; }
.due { margin-right: .75rem; }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.today { color: var(--amber-text); font-weight: 600; }
.due.soon { color: var(--link); }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 1rem; margin-bottom: 2.5rem; }
.stat {
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem;
  color: var(--text); display: flex; flex-direction: column-reverse; gap: .25rem; font-weight: 400;
}
.stat:hover { color: var(--text); background: var(--subtle); }
.stat strong { font-size: 1.875rem; line-height: 2.25rem; font-weight: 600; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-weight: 500; }
.stat.alert strong { color: var(--danger); }

/* ---------- tasks ---------- */
.tasks, .people, .timeline { list-style: none; margin: 0 0 .75rem; padding: 0; }
.tasks, .people { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.tasks li { display: flex; gap: .75rem; align-items: flex-start; padding: .75rem 1rem; border-top: 1px solid var(--border); }
.tasks li:first-child, .people li:first-child { border-top: none; }
.tasks li:hover, .people li:hover { background: var(--subtle); }
.tasks li.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-main { flex: 1; min-width: 0; }
.task-title { color: var(--text); }
.task-title:hover { color: var(--link); }
.task-main .small span, .task-main .small a { margin-right: .75rem; }
.check {
  width: 1.25rem; height: 1.25rem; padding: 0; margin-top: .125rem; border-radius: .25rem;
  outline: 1px solid var(--input-border); box-shadow: none;
  font-size: .75rem; line-height: 1; font-weight: 700; color: #fff;
}
.check:hover { outline-color: var(--accent); background: var(--surface); }
.done .check, .done .check:hover { background: var(--accent); outline-color: var(--accent); }
.quick-add { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1.5rem; }
.quick-add input[type=text], .quick-add input[type=password] { flex: 1; min-width: 11rem; }
.quick-add.card { padding: 1rem; }

/* ---------- activity ---------- */
.activity-form { display: flex; flex-direction: column; gap: .75rem; padding: 1rem; }
.activity-form .row, .followup .row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.followup summary { cursor: pointer; color: var(--link); font-weight: 500; }
.followup .row { margin-top: .5rem; justify-content: flex-start; }
.followup input[type=text] { flex: 1; min-width: 11rem; }
.segmented { display: inline-flex; border-radius: var(--radius); outline: 1px solid var(--input-border); outline-offset: -1px; overflow: hidden; box-shadow: var(--shadow-sm); }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span .icon { display: inline; padding: 0; border: 0; }
@media (max-width: 480px) {
  /* Phones: drop the icons and tighten spacing so all five activity types fit on one line. */
  .segmented { display: flex; width: 100%; }
  .segmented > label { flex: 1; min-width: 0; }
  .segmented > label > span { padding: .375rem .125rem; text-align: center; font-size: .75rem; }
  .segmented span .icon { display: none; }
}
.segmented > label > span { display: block; padding: .375rem .75rem; text-transform: capitalize; font-weight: 600; color: var(--text-2); border-left: 1px solid var(--input-border); }
.segmented label:first-child span { border-left: none; }
.segmented label:hover span { background: var(--subtle); }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Feed-style timeline with a connector line */
.timeline li { position: relative; padding: 0 0 1.25rem 1.75rem; }
.timeline li::before { content: ""; position: absolute; left: .3125rem; top: 1rem; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after {
  content: ""; position: absolute; left: 0; top: .375rem; width: .75rem; height: .75rem; border-radius: 9999px;
  background: var(--gray-dot); box-shadow: 0 0 0 4px var(--bg);
}
.timeline li.type-call::after { background: var(--green-dot); }
.timeline li.type-email::after { background: var(--blue-dot); }
.timeline li.type-meeting::after { background: var(--amber-dot); }
.timeline li.type-message::after, .timeline li.type-form::after { background: #a855f7; }
.timeline .meta { display: flex; gap: .75rem; flex-wrap: wrap; align-items: baseline; margin-bottom: .125rem; }
.timeline .atype { font-weight: 600; text-transform: capitalize; color: var(--text); }
.timeline .meta form { margin-left: auto; }
.subject { font-weight: 600; }

/* Import preview */
.result.preview { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.result.preview h2 { margin-top: 0; }
.result.preview h3 { margin-top: 1.5rem; }
.result .warn { color: var(--amber-text); font-weight: 500; }
.mapping { display: grid; grid-template-columns: max-content max-content 1fr; gap: .25rem 1rem; align-items: center; margin: 0 0 1rem; }
.mapping .ignore, .ignored-list .ignore { display: inline-flex; align-items: center; gap: .375rem; color: var(--muted); cursor: pointer; }
.ignored-list { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.badge.act-new { background: var(--green-bg); color: var(--green-text); }
.badge.act-update { background: var(--blue-bg); color: var(--blue-text); }
.badge.act-skip { background: var(--amber-bg); color: var(--amber-text); }
.badge { text-transform: none; }
.badge.status-lead, .badge.status-prospect, .badge.status-customer, .badge.status-inactive { text-transform: capitalize; }

/* "From the customer" messages on the contact page */
.messages { list-style: none; margin: 0 0 .75rem; padding: 0; display: flex; flex-direction: column; gap: .75rem; }
.message {
  --c: #a855f7;
  border: 1px solid color-mix(in srgb, var(--c) 30%, var(--border));
  border-left: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 6%, var(--surface));
  border-radius: var(--radius-lg); padding: .875rem 1rem;
}
.message .question { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .025em; color: var(--muted); margin-bottom: .25rem; }
.message blockquote { margin: 0; font-size: .9375rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.message .meta { display: flex; justify-content: space-between; gap: 1rem; margin-top: .5rem; }

.people li { padding: .75rem 1rem; border-top: 1px solid var(--border); display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

/* Merging duplicates */
.people li > .button.small { margin-left: auto; }
.dup-group { padding: 1rem 1.25rem; }
.dup-group > p:first-child { margin: 0 0 .5rem; }
.dup-group .people { margin-bottom: 0; }
.dup-group > p:last-child { margin: .5rem 0 0; }
.merge-table th[scope=row] { width: 9rem; vertical-align: top; }
.merge-table thead th { text-transform: none; letter-spacing: normal; font-size: .875rem; }
.merge-table thead th .role { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .025em; }
.merge-table thead th .muted { display: block; font-weight: 400; }
.merge-table td { color: var(--text); width: 40%; }
.merge-table td:first-of-type { font-weight: 400; }
.pick { display: flex; gap: .5rem; align-items: flex-start; cursor: pointer; }
.pick > input { flex: none; margin-top: .2rem; }
.pick .notes { display: block; max-height: 12rem; overflow-y: auto; }

@media (max-width: 640px) {
  :root { --gutter: 1rem; }
  .topbar { gap: .75rem; flex-wrap: wrap; }
  .topbar nav { gap: .25rem; order: 3; flex-basis: 100%; }
  .topbar .search { order: 4; max-width: none; flex-basis: 100%; }
  main { padding-top: 1.5rem; }
}

/* A newly created API token on My account */
.token-value { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
