/* Calm, dense enough for a work tool, large touch targets where she taps while on the phone. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #dde1e7;
  --line-strong: #c4cad3;
  --text: #1c232c;
  --muted: #5d6875;
  --accent: #1f5f8b;
  --accent-strong: #174a6d;
  --accent-soft: #e5eef5;
  --ok: #1e6b43;
  --ok-soft: #e3f2e9;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --danger: #a5302a;
  --danger-soft: #fbe7e5;
  --info: #3d4f9f;
  --info-soft: #e8ebf8;
  --focus: #2b7fd0;
  --radius: 8px;
  --radius-small: 6px;
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.06), 0 2px 8px rgba(20, 30, 45, 0.05);
  --shadow-panel: -8px 0 32px rgba(20, 30, 45, 0.14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 15px; }
p { margin: 0 0 var(--s2); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s4) 0; max-width: 1240px; margin: 0 auto; }
.brand { font-weight: 700; letter-spacing: 0.01em; color: var(--accent); font-size: 16px; }
.campaign select { min-height: 36px; padding: 4px 30px 4px 10px; border: 1px solid var(--line); border-radius: var(--radius-small); background-color: var(--surface); max-width: 60vw; font-weight: 500; }
.env { margin-left: auto; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.tabs { display: flex; gap: var(--s1); padding: 0 var(--s3); max-width: 1240px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 10px var(--s3) 9px; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab-short { display: none; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.tab.on .tab-count { background: var(--accent-soft); color: var(--accent); }

.main { max-width: 1240px; margin: 0 auto; padding: var(--s4) var(--s4) 96px; }
.view { display: flex; flex-direction: column; gap: var(--s5); }

/* Blocks and cards */
.block-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.block-note { color: var(--muted); margin-top: calc(-1 * var(--s2)); }
.count { display: inline-block; min-width: 24px; padding: 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; line-height: 22px; text-align: center; font-weight: 500; font-variant-numeric: tabular-nums; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.subhead { margin: var(--s4) 0 var(--s2); font-size: 14px; color: var(--muted); text-transform: none; }
ul.plain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
details.block > summary { cursor: pointer; display: flex; align-items: center; gap: var(--s2); list-style: none; margin-bottom: var(--s3); }
details.block > summary::-webkit-details-marker { display: none; }
details.block > summary::before { content: "▸"; color: var(--muted); }
details.block[open] > summary::before { content: "▾"; }
h2.inline { display: inline; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-small);
  background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8b2621; color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent-strong); }
.btn-quiet { color: var(--muted); }
.btn-small { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.more { align-self: flex-start; margin-top: var(--s2); }
.link, .link-strong { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-align: left; }
.link:hover, .link-strong:hover { text-decoration: underline; }
.link-strong { font-weight: 600; font-size: 16px; color: var(--text); }
.link-strong:hover { color: var(--accent); }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 20px; white-space: nowrap; border: 1px solid transparent; }
.badge-neutral { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Phone links */
.tel { display: inline-flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 500; text-decoration: none; white-space: nowrap; }
.tel:hover { text-decoration: underline; }
.tel-big { font-size: 18px; font-weight: 600; padding: 6px 0; }
.tel-kind { font-size: 12px; color: var(--muted); font-weight: 500; }

/* Today */
.call-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.call-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--s2) var(--s4); align-items: center; padding: var(--s3) var(--s4); border-top: 1px solid var(--line); }
.call-row:first-child { border-top: 0; }
.call-main { min-width: 0; }
.call-person { margin-top: 2px; }
.call-when, .call-task { margin-top: 2px; font-size: 14px; color: var(--muted); }
.call-task { color: var(--text); }
.call-phone { text-align: right; }
.call-actions { display: flex; gap: var(--s2); }
.due.overdue, .overdue { color: var(--danger); font-weight: 500; }
.due-today { color: var(--accent); font-weight: 600; }

/* Empty, loading, errors */
.empty { padding: var(--s5) var(--s4); text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.empty-title { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.empty-body { max-width: 52ch; margin: 0 auto; }
.empty .btn { margin-top: var(--s3); }
.loading { display: flex; align-items: center; gap: var(--s2); color: var(--muted); padding: var(--s5) 0; justify-content: center; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.error-note { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; padding: var(--s2) var(--s3); margin: var(--s2) 0; border-radius: var(--radius-small); background: var(--danger-soft); color: var(--danger); border: 1px solid #f0c8c4; }
.field-error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }

/* Leads table */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); align-items: center; }
.search { flex: 1 1 260px; }
.search input, .select-inline select { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-small); background: var(--surface); }
.select-inline select { width: auto; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.toolbar-end { display: flex; align-items: center; gap: var(--s3); margin-left: auto; }
.result-count { font-size: 14px; font-variant-numeric: tabular-nums; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.table-wrap .more { margin: var(--s3); }
table.leads { width: 100%; border-collapse: collapse; }
table.leads th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); border-bottom: 1px solid var(--line); padding: 0; position: sticky; top: 0; }
.sort { display: flex; align-items: center; gap: 4px; width: 100%; padding: 10px 12px; background: none; border: 0; cursor: pointer; font-weight: 600; color: inherit; text-align: left; }
.sort:hover { color: var(--text); }
.sort-mark { font-size: 10px; }
table.leads th:not(:has(.sort)) { padding: 10px 12px; }
table.leads td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
table.leads td .link-strong { font-size: 14px; }
table.leads tbody tr { cursor: pointer; }
table.leads tbody tr:hover { background: #f8fafc; }
table.leads tbody tr:last-child td { border-bottom: 0; }

/* Lead panel. The page behind stays put while the panel scrolls. */
body:has(.panel) { overflow: hidden; }
.scrim { position: fixed; inset: 0; background: rgba(20, 30, 45, 0.28); z-index: 30; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(640px, 100%);
  background: var(--bg); box-shadow: var(--shadow-panel); display: flex; flex-direction: column; outline: none;
}
.panel-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s2) var(--s3); background: var(--surface); border-bottom: 1px solid var(--line); }
.panel-body { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s5); overscroll-behavior: contain; }
.back { padding-left: 8px; }
.company h2 { font-size: 22px; margin-bottom: 4px; }
.company-meta { display: flex; flex-wrap: wrap; gap: 4px var(--s3); font-size: 14px; color: var(--muted); }
.company-phone { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2); margin-top: var(--s2); }
.company-notes { margin-top: var(--s2); white-space: pre-wrap; }
.section { display: flex; flex-direction: column; gap: var(--s3); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.contact-head { display: flex; justify-content: space-between; gap: var(--s2); align-items: flex-start; }
.contact-name { font-size: 16px; }
.contact-lines { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px var(--s4); margin-top: var(--s2); font-size: 14px; }
.contact-note { margin-top: var(--s2); white-space: pre-wrap; }
/* Notes on a person: line breaks kept, and a long unbroken word or address wraps instead of widening the card. */
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.note-agent { margin-top: 4px; }
.contact-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
.contact-inactive { background: var(--surface-2); box-shadow: none; }
.contact-inactive .tel { color: var(--muted); text-decoration: line-through; }
.confirm { margin-top: var(--s3); padding: var(--s3); border-radius: var(--radius-small); background: var(--warn-soft); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.history li { padding: var(--s3) var(--s4); border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.history li p { margin: 4px 0 0; white-space: pre-wrap; }
.history-head { display: flex; flex-wrap: wrap; gap: 6px var(--s2); align-items: center; font-size: 14px; }
.research-note { white-space: pre-wrap; }
.requeue { margin-top: var(--s3); }

/* Forms */
.form-card h4 { margin-bottom: var(--s3); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea, .lookup-form input, .copy-row input {
  width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-small); background: var(--surface);
}
.field textarea { resize: vertical; min-height: 64px; }
.field-invalid input, .field-invalid select, .field-invalid textarea, input[aria-invalid="true"] { border-color: var(--danger); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-top: var(--s3); }
.call-form { display: flex; flex-direction: column; gap: var(--s3); }
.call-form .form-actions { margin-top: 0; }
.choice { border: 0; margin: 0; padding: 0; min-width: 0; }
.choice legend { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line-strong); border-radius: var(--radius-small); overflow: hidden; }
.segmented button { min-height: 44px; border: 0; background: var(--surface); cursor: pointer; font-weight: 500; }
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button.on { background: var(--accent); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip { min-height: 38px; padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 500; }
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.chip-sub { color: var(--muted); font-weight: 400; margin-left: 2px; }
.custom-time { margin-top: var(--s3); }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: flex-end; }
.inline-form .field { flex: 1 1 240px; }
.inline-form .full { flex-basis: 100%; }
.field-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: var(--s2); align-items: end; margin-bottom: var(--s2); }

/* Number lookup */
.lookup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.lookup-who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px var(--s3); }
.lookup-who strong { font-size: 16px; }
.lookup-links { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s3) 0; }
.lookup-form { display: flex; flex-wrap: wrap; gap: var(--s2); }
.lookup-form input { flex: 1 1 220px; width: auto; }

/* Settings */
.secret { margin: var(--s3) 0; padding: var(--s3); border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--radius-small); }
.copy-row { display: flex; gap: var(--s2); margin-bottom: var(--s2); }
.copy-row input { flex: 1; font-family: var(--mono); font-size: 13px; }
.token-list { list-style: none; margin: 0; padding: 0; }
.token-list li { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; padding: var(--s2) 0; border-top: 1px solid var(--line); }
.token-list li:first-child { border-top: 0; }
.howto { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.howto h4 { margin-bottom: 4px; }
.howto ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.howto pre { margin: var(--s2) 0 0; padding: var(--s2) var(--s3); background: var(--surface-2); border-radius: var(--radius-small); overflow-x: auto; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: var(--s4); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: var(--s2); width: min(480px, calc(100% - 32px)); }
.toast { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 10px 8px 10px 14px; border-radius: var(--radius); background: #1f2933; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); font-size: 14px; }
.toast-error { background: var(--danger); }
.toast-close { background: none; border: 0; color: inherit; font-size: 20px; line-height: 1; width: 32px; height: 32px; cursor: pointer; border-radius: 4px; }

/* Sign-in and full-page states */
.centered { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--s4); }
.centered-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: var(--s3); }

/* Narrow screens: the table becomes cards, the panel takes the whole screen. */
@media (max-width: 760px) {
  .main { padding: var(--s3) var(--s4) 96px; }
  .call-row { grid-template-columns: minmax(0, 1fr); gap: var(--s2); }
  .call-phone { text-align: left; }
  .call-actions .btn { flex: 1; }
  .panel { width: 100%; box-shadow: none; }
  .scrim { display: none; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .howto { grid-template-columns: minmax(0, 1fr); }
  .toolbar-end { margin-left: 0; width: 100%; justify-content: space-between; }
  .select-inline { flex: 1 1 140px; }
  .select-inline select { width: 100%; }
  table.leads thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.leads, table.leads tbody, table.leads tr, table.leads td { display: block; width: 100%; }
  table.leads tr { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 6px var(--s3); }
  table.leads tbody tr:last-child { border-bottom: 0; }
  table.leads td { padding: 0; border: 0; }
  table.leads td[data-label="Yritys"], table.leads td[data-label="Yhteyshenkilö"], table.leads td[data-label="Puhelin"] { grid-column: 1 / -1; }
  /* Both badges side by side, then the two dates side by side. */
  table.leads td[data-label="Tila"] { order: 4; }
  table.leads td[data-label="Tutkimus"] { order: 5; }
  table.leads td[data-label="Viimeksi soitettu"] { order: 6; }
  table.leads td[data-label="Seuraava soitto"] { order: 7; }
  table.leads td[data-label="Viimeksi soitettu"]::before, table.leads td[data-label="Seuraava soitto"]::before {
    content: attr(data-label); display: block; font-size: 12px; color: var(--muted);
  }
  .field-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .field-row .btn { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 420px) {
  .topbar-row { padding: var(--s2) var(--s3) 0; gap: var(--s2); }
  .tabs { padding: 0 var(--s1); gap: 0; justify-content: space-between; }
  .tab-long { display: none; }
  .tab-short { display: inline !important; }
  .tab { padding: 10px 7px 9px; font-size: 14px; gap: 4px; }
  .tab-count { min-width: 18px; padding: 0 5px; font-size: 11px; line-height: 18px; }
  .campaign select { max-width: 52vw; }
  .env { display: none; }
}

/* Same person on other leads, under a contact. */
.elsewhere { list-style: none; margin: var(--s2) 0 0; padding: 0; font-size: 14px; display: grid; gap: 4px; }
.elsewhere li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px var(--s2); }
.elsewhere .link { font-size: inherit; font-weight: 600; }
/* A badge whose text can be long (company names) wraps instead of pushing the row wider than a phone screen. */
.badge-wrap { white-space: normal; }
/* The company's identity card: its texts hold company names and Y-tunnus values, so they wrap at any width. */
.identity { margin-top: var(--s3); border-color: var(--warn); background: var(--warn-soft); }
.identity-text { overflow-wrap: anywhere; }
.identity p + p { margin-top: var(--s2); }
.identity-form { margin-top: var(--s3); }
.company h2, .call-main .link-strong, .lookup-who .link { overflow-wrap: anywhere; }
