:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f8f6f1;
  --text: #1d1f24;
  --muted: #646a75;
  --border: #e3ded3;
  --accent: #0a66c2;
  --accent-text: #ffffff;
  --good: #1f7a4d;
  --good-bg: #e3f3ea;
  --maybe: #8a5a00;
  --maybe-bg: #fbefd5;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1f2228;
    --surface-2: #262a31;
    --text: #e8e9ec;
    --muted: #9aa0ab;
    --border: #30343c;
    --accent: #5aa7f0;
    --accent-text: #0b1520;
    --good: #6fcf97;
    --good-bg: #1d3328;
    --maybe: #f2c46d;
    --maybe-bg: #3a3020;
    --bad: #f28b82;
    --bad-bg: #3d2523;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body.sheet-open { overflow: hidden; }

[hidden] { display: none !important; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.4em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.9rem; margin-top: 1em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 0.6em; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); }

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

/* ---------------------------------------------------------------- controls */

input, textarea, button, .button {
  font: inherit;
  color: inherit;
}

input, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

input:focus, textarea:focus, button:focus-visible, .button:focus-visible, .job-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label { display: block; font-size: 0.9rem; color: var(--muted); }
label > input, label > textarea { margin-top: 4px; color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; margin: 0; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
}

button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.danger { color: var(--bad); }

.small-button { min-height: 36px; padding: 4px 12px; font-size: 0.85rem; }

.icon-button {
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
}

.stack { display: grid; gap: 12px; }

/* ---------------------------------------------------------------- login */

.login { display: grid; place-items: center; min-height: 100dvh; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 12px; text-align: center; }
.login-card label { text-align: left; }
.login-logo { margin: 0 auto; border-radius: 12px; }

/* ---------------------------------------------------------------- inbox */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.share-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.share-form input { flex: 1; min-width: 0; }

.notice {
  background: var(--maybe-bg);
  color: var(--maybe);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}
.notice.error { background: var(--bad-bg); color: var(--bad); }

.job-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.job-card {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  padding: 14px 16px;
  min-height: 0;
  font-weight: normal;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.job-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.job-title { font-weight: 650; overflow-wrap: anywhere; }
.job-meta { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; margin: 0; }
.job-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.when { color: var(--muted); font-size: 0.8rem; }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
}
.status-queued, .status-fetching, .status-analyzing { color: var(--accent); }
.status-failed { color: var(--bad); background: var(--bad-bg); border-color: transparent; }

.badge {
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
}
.fit-accept { background: var(--good-bg); color: var(--good); }
.fit-flag { background: var(--maybe-bg); color: var(--maybe); }
.fit-reject { background: var(--bad-bg); color: var(--bad); }

.chip.applied { color: var(--good); background: var(--good-bg); border-color: transparent; }

.empty { text-align: center; padding: 40px 16px; }

.pending { margin-bottom: 16px; }
.list-heading { font-size: 0.9rem; color: var(--muted); margin: 0 0 8px; }

.views { display: flex; gap: 6px; margin-bottom: 10px; }
.views button { flex: 1; min-height: 40px; padding: 6px 12px; border-radius: 999px; }
.views button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ---------------------------------------------------------------- sheets */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.sheet-bar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: max(4px, env(safe-area-inset-top)) 8px 4px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.sheet-bar-title { text-align: center; font-weight: 650; }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.job-head { display: flex; gap: 12px; align-items: flex-start; }
.job-head h1 { overflow-wrap: anywhere; }
.logo { border-radius: 8px; flex: none; background: var(--surface-2); }

.fit-card { border: none; }
.fit-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.fit-score { font-size: 2rem; font-weight: 750; }
.fit-score small { font-size: 1rem; font-weight: 600; opacity: 0.7; }
.fit-label { font-weight: 650; }
.fit-card .bullets { color: var(--text); }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 10px 0 0; }
.facts dt { color: var(--muted); font-size: 0.8rem; }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.bullets { margin: 0; padding-left: 1.2em; }
.bullets li { margin-bottom: 4px; }

details summary { cursor: pointer; list-style: none; }
details summary h2 { display: inline; }
details summary::after { content: " ▾"; color: var(--muted); }
details[open] summary::after { content: " ▴"; }
.description { white-space: pre-line; margin-top: 10px; overflow-wrap: anywhere; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.actions > * { flex: 1 1 140px; }

.rows { list-style: none; margin: 0 0 12px; padding: 0; }
.rows li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.rows li:last-child { border-bottom: none; }

/* ---------------------------------------------------------------- banner */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.banner-actions { display: flex; gap: 8px; }

.verdict-row { display: flex; gap: 8px; align-items: baseline; margin-top: 10px; }
.verdict-row strong { white-space: nowrap; }
.yes { color: var(--good); }
.no { color: var(--bad); }
.partial { color: var(--maybe); }

/* ---------------------------------------------------------------- agent runs */

select {
  font: inherit;
  color: var(--text);
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
label > select { display: block; width: 100%; margin-top: 4px; }
.topbar-actions { display: flex; gap: 4px; }
.run-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.run { border-top: 1px solid var(--border); padding-top: 10px; }
.run-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.run p { margin: 4px 0; }
.run-queued, .run-running { color: var(--accent); }
.run-failed { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.run-done { color: var(--good); background: var(--good-bg); border-color: transparent; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(92vw, 480px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
}
