:root {
  --bg: #faf9f6;
  --bg-raised: #ffffff;
  --ink: #1b1d1c;
  --ink-soft: #55534c;
  --line: #e4e0d6;
  --line-strong: #cfc9ba;
  --accent: #4636e3;
  --accent-ink: #ffffff;
  --accent-soft: #eae6fc;
  --status-contacted: #5b7db1;
  --status-proposal: #b8862b;
  --status-won: #1f8a5c;
  --status-lost: #9a938a;
  /* Solid (not alpha) tint pairs for the saved-prospect stage chip — same
     pattern as --accent-soft, chosen for a real, verified contrast ratio
     rather than an rgba() overlay whose contrast depends on whatever's
     behind it. */
  --stage-first-fg: #3a5a8a; --stage-first-bg: #e6edf6;
  --stage-followup1-fg: #8a6220; --stage-followup1-bg: #f7ecd9;
  --stage-followup2-fg: #146442; --stage-followup2-bg: #e1f3ea;
  --shadow: 0 1px 2px rgba(27, 29, 28, 0.04), 0 8px 24px rgba(27, 29, 28, 0.06);
  --radius: 10px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-doc: Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --bg-raised: #1e2123;
    --ink: #ecebe6;
    --ink-soft: #a8a49a;
    --line: #33362f;
    --line-strong: #46493f;
    --accent: #8d82ff;
    --accent-ink: #15102e;
    --accent-soft: #262048;
    --status-contacted: #7fa0d6;
    --status-proposal: #d9a748;
    --status-won: #34d399;
    --status-lost: #7c766c;
    --stage-first-fg: #7fa0d6; --stage-first-bg: #1c2740;
    --stage-followup1-fg: #d9a748; --stage-followup1-bg: #332711;
    --stage-followup2-fg: #34d399; --stage-followup2-bg: #0f2e22;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #16181a; --bg-raised: #1e2123; --ink: #ecebe6; --ink-soft: #a8a49a;
  --line: #33362f; --line-strong: #46493f; --accent: #8d82ff; --accent-ink: #15102e;
  --accent-soft: #262048; --status-contacted: #7fa0d6; --status-proposal: #d9a748;
  --status-won: #34d399; --status-lost: #7c766c;
  --stage-first-fg: #7fa0d6; --stage-first-bg: #1c2740;
  --stage-followup1-fg: #d9a748; --stage-followup1-bg: #332711;
  --stage-followup2-fg: #34d399; --stage-followup2-bg: #0f2e22;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}
:root[data-theme="light"] {
  --bg: #faf9f6; --bg-raised: #ffffff; --ink: #1b1d1c; --ink-soft: #55534c;
  --line: #e4e0d6; --line-strong: #cfc9ba; --accent: #4636e3; --accent-ink: #ffffff;
  --accent-soft: #eae6fc; --status-contacted: #5b7db1; --status-proposal: #b8862b;
  --status-won: #1f8a5c; --status-lost: #9a938a;
  --stage-first-fg: #3a5a8a; --stage-first-bg: #e6edf6;
  --stage-followup1-fg: #8a6220; --stage-followup1-bg: #f7ecd9;
  --stage-followup2-fg: #146442; --stage-followup2-bg: #e1f3ea;
  --shadow: 0 1px 2px rgba(27,29,28,.04), 0 8px 24px rgba(27,29,28,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
h1, h2 { text-wrap: balance; margin: 0; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { max-width: 1080px; margin: 0 auto; padding: 32px 24px 80px; }
.panel { display: none; }
.panel.is-active { display: block; }
.panel-head { max-width: 640px; margin-bottom: 28px; }
.panel-head h1 { font-size: 24px; letter-spacing: -0.01em; margin-bottom: 8px; }
.panel-head p { color: var(--ink-soft); font-size: 14.5px; line-height: 1.55; margin: 0; }

.workspace { display: grid; grid-template-columns: minmax(260px, 380px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 800px) { .workspace { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Topbar / brand */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 14px 24px;
  border-bottom: 1px solid var(--line); background: var(--bg-raised);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark { display: flex; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-tag { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }

.powered-by {
  display: flex; align-items: baseline; gap: 5px; text-decoration: none;
  font-size: 11px; color: var(--ink-soft); white-space: nowrap; margin-right: 8px;
}
.powered-by strong { color: var(--ink); font-weight: 700; }
.powered-by:hover strong { color: var(--accent); }
@media (max-width: 900px) { .powered-by { display: none; } }

.tabs { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tab-btn {
  border: none; background: transparent; color: var(--ink-soft);
  padding: 8px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: background .15s, color .15s; white-space: nowrap;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.is-active { background: var(--accent); color: var(--accent-ink); }

.theme-toggle {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--bg-raised); color: var(--ink-soft); cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
#themeIconSun, #themeIconMoon { display: none; }
:root[data-theme="dark"] #themeIconSun { display: block; }
:root:not([data-theme="dark"]) #themeIconMoon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #themeIconSun { display: block; }
  :root:not([data-theme="light"]) #themeIconMoon { display: none; }
}

/* Password gate */
.gate {
  position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.gate.is-unlocked { display: none; }
.gate-card {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px; box-shadow: var(--shadow);
}
.gate-mark { display: inline-flex; margin-bottom: 14px; }
.gate-card h1 { font-size: 20px; margin-bottom: 6px; }
.gate-card p { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 18px; }
.gate-card input[type="password"] {
  width: 100%; padding: 11px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--ink); font-size: 14px; text-align: center; margin-bottom: 12px;
}
.gate-card input[type="password"]:focus { border-color: var(--accent); }
.gate-card .primary-btn { width: 100%; padding: 11px 14px; font-size: 14px; }
.gate-error { color: #c0392b; margin: 12px 0 0; display: none; }
.gate-error.is-visible { display: block; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 200;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Form / output / button components */
.form-card, .output-card {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 6px; color: var(--ink); }
.field .optional { font-weight: 400; color: var(--ink-soft); }
.field input[type="text"], .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--ink); font-size: 14px; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input[type="text"]:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field-hint { font-size: 12px; color: var(--ink-soft); margin-top: 5px; }

.output-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.output-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.ghost-btn {
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
  padding: 7px 13px; border-radius: 7px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.primary-btn {
  border: none; background: var(--accent); color: var(--accent-ink);
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.07); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Message output cards */
.messages-stack { display: flex; flex-direction: column; gap: 16px; }
.message-card { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.message-card .msg-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 12px; }
.message-card .msg-title h3 { font-size: 13.5px; font-weight: 700; margin: 0; }
.message-card .msg-when { font-size: 12px; color: var(--ink-soft); }
.message-card pre {
  white-space: pre-wrap; word-wrap: break-word; font-family: var(--font-ui); font-size: 14px;
  line-height: 1.6; color: var(--ink); margin: 0 0 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px 16px;
}
.empty-state { color: var(--ink-soft); font-size: 13.5px; text-align: center; padding: 40px 20px; }

/* Saved messages list */
.saved-list { display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
.saved-card { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.saved-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.saved-who { display: flex; flex-direction: column; gap: 2px; }
.saved-who strong { font-size: 14.5px; }
.saved-who span { font-size: 12.5px; color: var(--ink-soft); }
.saved-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dept-chip {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.stage-chip {
  display: inline-block; font-weight: 700; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.stage-chip.st-first { background: var(--stage-first-bg); color: var(--stage-first-fg); }
.stage-chip.st-followup1 { background: var(--stage-followup1-bg); color: var(--stage-followup1-fg); }
.stage-chip.st-followup2 { background: var(--stage-followup2-bg); color: var(--stage-followup2-fg); }
.saved-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.saved-messages { margin-top: 14px; display: none; flex-direction: column; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.saved-messages.is-open { display: flex; }

/* Guide tab */
.guide { display: flex; flex-direction: column; gap: 22px; max-width: 720px; }
.guide-section {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px;
}
.guide-section h2 { display: flex; align-items: center; gap: 10px; font-size: 16px; margin-bottom: 8px; }
.guide-number {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 700; flex-shrink: 0;
}
.guide-section > p { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 12px; }
.guide-section ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.guide-section li { font-size: 13.5px; line-height: 1.55; }
.guide-note { background: var(--accent-soft); border-color: transparent; }
.ui-ref {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 12.5px; padding: 1px 7px; border-radius: 5px;
}

footer.app-foot { text-align: center; color: var(--ink-soft); font-size: 12px; padding: 24px 0 4px; }
footer.app-foot a { color: var(--ink-soft); }
