:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #5f6368;
  --border: #dadce0;
  --accent: #1a56db;
  --accent-text: #ffffff;
  --ok-bg: #e6f4ea;
  --ok-text: #137333;
  --warn-bg: #fef7e0;
  --warn-text: #8a5300;
  --error-bg: #fce8e6;
  --error-text: #a50e0e;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1e1e1e;
    --text: #e8eaed;
    --muted: #a8acb1;
    --border: #3c4043;
    --accent: #8ab4f8;
    --accent-text: #0b1b33;
    --ok-bg: #0f2e1b;
    --ok-text: #81c995;
    --warn-bg: #3a2e05;
    --warn-text: #fdd663;
    --error-bg: #3c1412;
    --error-text: #f6aea9;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main, .page-header, .page-footer {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
}

.page-header { padding-top: 32px; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.account-email { color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }
.uses { margin: -12px 0 20px; font-size: 0.95rem; }
.uses .note { color: var(--muted); }
.uses.empty { color: var(--warn-text); font-weight: 600; }

/* Sign-in dialog */
dialog.sign-in {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
dialog.sign-in::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-close-row { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; }
.dialog-close-row h2 { margin: 0; font-size: 1.3rem; }
.dialog-intro { margin-top: 0; color: var(--muted); }
.provider-buttons { display: grid; gap: 10px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: 0.9rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.secondary-actions { margin-top: 14px; }
.switch-view { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }
.dialog-message { margin: 16px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--ok-bg); color: var(--ok-text); font-weight: 600; }
.dialog-message.error { background: var(--error-bg); color: var(--error-text); }
.page-header h1 { margin: 0; font-size: 2rem; }
.tagline { margin: 4px 0 24px; color: var(--muted); }
.page-footer { padding-top: 32px; padding-bottom: 32px; color: var(--muted); font-size: 0.9rem; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 12px 18px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.panel, .status, .result, .error-box {
  margin-top: 20px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.panel { border-top-left-radius: 0; margin-top: 0; border-top: 0; }
.panel-intro { margin-top: 0; color: var(--muted); }

/* Forms */
.field { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
input, select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.field-hint, .hint { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }
.form-error { color: var(--error-text); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }

button, .button {
  padding: 11px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: 0.6; cursor: wait; }
button.small { padding: 8px 14px; font-size: 0.95rem; }
/* Every control is at least 44 px tall, the smallest target Apple and Google recommend
   for a finger. Links and copy buttons inside a sentence keep the text's height. */
button, .button, select { min-height: 44px; }
.link-button { display: inline-flex; align-items: center; min-height: 44px; }
p .link-button, li .link-button { min-height: 0; display: inline; }
.switch-view .link-button { display: inline-flex; min-height: 44px; }
.link-button { border: 0; padding: 0; background: none; color: var(--accent); text-decoration: underline; }

/* Progress */
.status-title { margin: 0 0 12px; font-size: 1.1rem; }
.progress { list-style: none; margin: 0; padding: 0; }
.progress li { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.progress .icon { width: 20px; text-align: center; }
.progress li.done { color: var(--muted); }
.progress li.done .icon { color: var(--ok-text); }
.progress li.warn .icon { color: var(--warn-text); }
.progress li.active { font-weight: 600; }
.progress li.active .icon::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .progress li.active .icon::before { animation: none; } }

.error-box { background: var(--error-bg); color: var(--error-text); border-color: transparent; font-weight: 600; }

/* Brief */
.toolbar { display: flex; gap: 12px; justify-content: flex-end; margin-bottom: 8px; }
.brief h1 { margin-top: 0; }
.brief h2 { margin-top: 28px; padding-bottom: 4px; border-bottom: 1px solid var(--border); font-size: 1.25rem; }
.brief a { color: var(--accent); overflow-wrap: anywhere; }
.brief a.citation { text-decoration: none; font-size: 0.85em; vertical-align: super; }
.sources { padding-left: 0; list-style: none; font-size: 0.95rem; }
.sources li { margin-bottom: 8px; }
.sources li:target { background: var(--warn-bg); border-radius: 6px; }
.source-number { color: var(--muted); margin-right: 4px; }
.source-details { color: var(--muted); }
.phone-extension { color: var(--muted); }

/* Companies */
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.companies { list-style: none; padding: 0; display: grid; gap: 16px; }
.company { padding: 16px; border: 1px solid var(--border); border-radius: 10px; }
.company-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.company h3 { margin: 0; font-size: 1.15rem; }
.company > a { color: var(--accent); overflow-wrap: anywhere; }
.badge { padding: 2px 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0; }
.facts dt { font-weight: 600; color: var(--muted); }
.facts dd { margin: 0; }
.note { color: var(--muted); font-size: 0.85rem; }
.named-in { font-size: 0.9rem; color: var(--muted); }
.named-in a { color: var(--muted); }

@media (max-width: 560px) {
  .facts { grid-template-columns: 1fr; }
  .facts dd { margin-bottom: 6px; }
  .tab { padding: 10px 12px; }
  /* Phones: the main button spans the form, and sign-in takes the whole screen. */
  .actions > button.primary, dialog.sign-in button.primary { width: 100%; }
  dialog.sign-in {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
}

/* Keyboard and screen-reader users can jump past the header to the form. */
.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 8px;
  font-weight: 600;
  z-index: 20;
}
.skip-link:focus { top: 12px; }
#main:focus { outline: none; }

/* A finished run's checklist folds into one line; "Show the steps" opens it. */
.status-title-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; }
.status-title-row .status-title { margin: 0; }
.status .progress { margin-top: 12px; }

/* Hover previews: a dotted underline marks anything that explains itself. */
/* Previews open on hover or click, so they use the normal pointer, not a "?" (Anh). */
[data-tip], .citation { cursor: pointer; }
.note[data-tip], .tag[data-tip], .progress li[data-tip] {
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
}

.tip {
  position: fixed;
  z-index: 10;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.92rem;
  line-height: 1.45;
  pointer-events: none;
}
.tip.interactive { pointer-events: auto; }
.tip-title { display: block; margin-bottom: 2px; }
.tip-meta, .tip-hint, .tip-label { color: var(--muted); font-size: 0.85rem; }
.tip-label { margin-top: 8px; }
.tip-quote {
  margin: 4px 0 6px;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  font-style: italic;
}
.tip a { color: var(--accent); font-weight: 600; }

/* Website lookup under the website field */
.optional { color: var(--muted); font-weight: 400; }
.lookup:empty { display: none; }
.lookup {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
}
.lookup.busy { color: var(--muted); }
.lookup.ok { background: var(--ok-bg); color: var(--ok-text); }
.lookup.warn { background: var(--warn-bg); color: var(--warn-text); }
.lookup.ask { background: var(--bg); border: 1px solid var(--border); }
.lookup > span { flex-basis: 100%; }
.choice { padding: 6px 12px; font-size: 0.9rem; }

.notice {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-weight: 600;
}

/* Sorting discovery results */
.sort-controls { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.sort-controls label { margin: 0; }
.sort-controls select { width: auto; padding: 8px 10px; }
.companies .group-heading {
  margin-top: 8px;
  padding: 0 0 4px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}

/* Estimates: a quiet ≈ that explains itself on hover */
.estimate {
  color: var(--muted);
  font-weight: 700;
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
}
.facts .citation { font-size: 0.85em; vertical-align: super; text-decoration: none; color: var(--accent); }
/* Emails and phone numbers: plain text that copies itself when clicked. */
button.copy {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: copy;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
button.copy:hover { color: var(--accent, inherit); }
