/* Customer portal styles.
 *
 * The colour tokens, type scale and card / form / table patterns are copied
 * verbatim from the brain's app.css so the two apps read as one product. The
 * shared contract is s7-crm's docs/style-guide.md — read it before adding
 * anything here, and copy the nearest existing pattern rather than inventing a
 * token. What is deliberately NOT copied: the sidebar, the tab bars, the
 * kanban, the chat panel. This app is one page and needs none of it.
 *
 * Dark mode follows the OS rather than a user preference, because the portal
 * has no per-user settings to store it in.
 */

:root {
  --bg: #fafaf9;
  --fg: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;
  --accent: #C2410C;
  --danger: #b91c1c;
  --ok: #15803d;

  --surface: #ffffff;
  --surface-alt: #f5f5f4;
  --row-hover: #fafaf9;
  --on-accent: #ffffff;
  --on-fg: #ffffff;            /* text on a var(--fg) background, e.g. tooltips */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0a09;
    --fg: #f5f5f4;
    --muted: #a8a29e;
    --border: #292524;
    --accent: #fb923c;
    --danger: #f87171;
    --ok: #4ade80;

    --surface: #1c1917;
    --surface-alt: #292524;
    --row-hover: #292524;
    --on-accent: #0c0a09;
    --on-fg: #0c0a09;

    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 14px/1.45 system-ui, sans-serif;
  margin: 0; background: var(--bg); color: var(--fg);
}

body.centered { display: grid; place-items: center; min-height: 100vh; padding: 16px; }

main { max-width: 820px; margin: 24px auto 64px; padding: 0 24px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); margin: 28px 0 10px;
}
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px;
  background: var(--surface-alt); padding: 1px 4px; border-radius: 3px;
}
a { color: var(--fg); }
a:hover { color: var(--accent); }

/* ── Masthead ───────────────────────────────────────────────────────────── */
.masthead {
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.masthead-inner {
  max-width: 820px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.masthead-brand { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.masthead-company {
  font-size: 14px; font-weight: 600; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.masthead-sub { font-size: 11px; color: var(--muted); }
.masthead-user { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.masthead-email { font-size: 12px; color: var(--muted); }
button.signout {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  font: inherit; font-size: 12px; cursor: pointer;
  transition: border-color 120ms, color 120ms;
}
button.signout:hover { color: var(--fg); border-color: var(--accent); }

/* ── Form ───────────────────────────────────────────────────────────────── */
/* `.fieldset` is the brain's `form.meta` card, re-cut as an inner block so one
   <form> can hold several labelled groups and still save in a single submit. */
.fieldset {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  background: var(--surface); padding: 16px;
  border: 1px solid var(--border); border-radius: 6px; margin: 0 0 8px;
}
.fieldset label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
.fieldset label.full { grid-column: 1 / -1; }
.fieldset input, .fieldset textarea {
  font: inherit; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; background: var(--surface); color: var(--fg);
}
.fieldset input:focus, .fieldset textarea:focus {
  outline: none; border-color: var(--accent);
}
.fieldset input[readonly] { color: var(--muted); background: var(--surface-alt); }
.required { color: var(--danger); }

button[type=submit] {
  font: inherit; padding: 8px 16px; background: var(--accent);
  color: var(--on-accent); border: none; border-radius: 4px; cursor: pointer;
}
button[type=submit]:hover { opacity: 0.9; }
.form-actions {
  display: flex; align-items: center; gap: 14px; margin-top: 18px;
}

/* ── (i) affordance ─────────────────────────────────────────────────────── */
/* Explanations live in hover/focus tooltips rather than grey paragraphs, so the
   form starts at the top of the page. Matches the brain's /portal page. The
   body is real DOM text, not a title="" attribute, so it reaches screen readers
   and keyboard users. */
.info {
  position: relative; display: inline-flex; vertical-align: middle;
  margin-left: 6px; color: var(--muted); cursor: help;
}
.info svg { width: 14px; height: 14px; display: block; }
.info:hover, .info:focus-visible { color: var(--accent); outline: none; }
.info-tip {
  position: absolute; top: calc(100% + 8px); left: -6px; z-index: 30;
  width: max-content; max-width: 44ch;
  background: var(--fg); color: var(--on-fg);
  font-size: 12px; font-weight: 400; line-height: 1.45;
  text-transform: none; letter-spacing: normal; text-align: left;
  padding: 8px 10px; border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0; visibility: hidden; transition: opacity 120ms;
}
.info:hover .info-tip,
.info:focus-visible .info-tip,
.info:focus-within .info-tip { opacity: 1; visibility: visible; }
.info-tip::before {
  content: ""; position: absolute; bottom: 100%; left: 10px;
  border: 5px solid transparent; border-bottom-color: var(--fg);
}
/* On a narrow screen a tooltip hung off a right-hand label would run off the
   edge; flip those to the right so they open leftwards. */
.info.info-right .info-tip { left: auto; right: -6px; }
.info.info-right .info-tip::before { left: auto; right: 10px; }

/* ── Read-only summary + pencil ──────────────────────────────────────────── */
/* Once the details are complete there is nothing to fill in, so the page shows
   what is on file and a pencil to change it — the same affordance the brain uses
   on a company page. Mirrors `.icon-btn.edit-toggle` there. */
.summary-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin: 0 0 4px;
}
.summary-head h2 { margin: 0; }
button.edit-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  font: inherit; font-size: 12px; cursor: pointer; flex-shrink: 0;
  transition: border-color 120ms, color 120ms;
}
button.edit-toggle:hover { color: var(--accent); border-color: var(--accent); }
button.edit-toggle svg { width: 14px; height: 14px; }

.summary {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 16px; margin: 0 0 8px;
}
.summary dl {
  display: grid; grid-template-columns: minmax(140px, 34%) 1fr;
  gap: 0; margin: 0;
}
.summary dt {
  padding: 9px 12px 9px 0; color: var(--muted); font-size: 12px;
  border-bottom: 1px solid var(--surface-alt);
}
.summary dd {
  padding: 9px 0; margin: 0; color: var(--fg);
  border-bottom: 1px solid var(--surface-alt);
  overflow-wrap: anywhere;
}
.summary dt:last-of-type, .summary dd:last-of-type { border-bottom: none; }
.summary dd.empty { color: var(--muted); }

@media (max-width: 620px) {
  .summary dl { grid-template-columns: 1fr; }
  .summary dt { padding-bottom: 0; border-bottom: none; }
  .summary dd { padding-top: 2px; }
}

/* ── Banners ────────────────────────────────────────────────────────────── */
.banner {
  border-radius: 6px; padding: 10px 13px; font-size: 13px;
  margin: 0 0 16px; border: 1px solid transparent;
}
.banner-ok    { background: var(--surface); color: var(--ok); border-color: var(--ok); }
.banner-warn  { background: var(--surface); color: #b45309; border-color: #fcd34d; }
.banner-error { background: var(--surface); color: var(--danger); border-color: var(--danger); }

/* ── Sign-in card ───────────────────────────────────────────────────────── */
/* Mirrors the brain's .anon-card: no branding, no app name, just enough chrome
   to look intentional. */
.card {
  background: var(--surface); padding: 24px; border: 1px solid var(--border);
  border-radius: 8px; max-width: 380px; width: 100%;
}
.card h1 { margin: 0 0 6px; }
.card .card-sub { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.card form { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.card form input[type=email] {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 4px;
  font: inherit; background: var(--surface); color: var(--fg);
}
.card form input[type=email]::placeholder { color: var(--muted); }
.card form input[type=email]:focus { outline: none; border-color: var(--accent); }
.card form button[type=submit] { width: 100%; padding: 9px 14px; }
.card .status {
  min-height: 1.2em; margin: 10px 0 0; color: var(--muted); font-size: 12px;
}

@media (max-width: 620px) {
  .fieldset { grid-template-columns: 1fr; }
  main { padding: 0 16px; }
  .masthead-inner { padding: 12px 16px; }
  .masthead-email { display: none; }
}
