/* VibeStack Agent — shared layout and tokens (E1/E8).
   Light: Catppuccin Latte, accent #8839ef. Dark: Tokyo Night, accent #7aa2f7. */

/* Inter is served from this app, as in VibeStack Account. */
@font-face {
  font-family: "Inter";
  src: url("/assets/fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #eff1f5;
  --surface: #ffffff;
  --text: #4c4f69;
  --muted: #5c5f77;
  --border: #ccd0da;
  --line: #ccd0da;
  --accent: #8839ef;
  --on-accent: #ffffff;
  --danger: #d20f39;
  --radius-lg: 12px;
  --radius: 8px;
  --ok-bg: #dff3d9;
  --ok-fg: #2a6a1a;
  --warn-bg: #fdecc8;
  --warn-fg: #7a4d00;
  --off-bg: #e6e9ef;
  --off-fg: #4c4f69;
  --head-bg: #e6e9ef;
  --focus: #8839ef;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1b26;
    --surface: #24283b;
    --text: #c0caf5;
    --muted: #a9b1d6;
    --border: #3b4261;
    --line: #3b4261;
    --accent: #7aa2f7;
    --on-accent: #1a1b26;
    --danger: #f7768e;
    --ok-bg: #2b3b2a;
    --ok-fg: #9ece6a;
    --warn-bg: #40361f;
    --warn-fg: #e0af68;
    --off-bg: #2f3349;
    --off-fg: #c0caf5;
    --head-bg: #1f2335;
    --focus: #7aa2f7;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); }
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
main.wrap { flex: 1; padding-top: 28px; padding-bottom: 48px; }

.skip-link { position: absolute; left: -9999px; top: 0; background: var(--surface); color: var(--text); padding: 8px 14px; z-index: 50; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }
.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; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-row { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { color: var(--text); font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; font-size: 1rem; }
.brand-mark { display: none; }
.brand::before { content: "◆"; color: var(--accent); }
.main-nav { flex: 1; display: flex; gap: 4px; }
.main-nav a { color: var(--muted); text-decoration: none; font-weight: 600; padding: 8px 6px; border-bottom: 2px solid transparent; }
.main-nav a:hover { color: var(--text); }
.main-nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.header-account { display: flex; align-items: center; gap: 12px; margin-left: auto; min-width: 0; }

.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 6px; border-radius: 10px; border: 1px solid transparent; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::marker { content: ""; }
.user-menu > summary:hover { border-color: var(--border); }
.avatar { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.who { display: inline-flex; flex-direction: column; line-height: 1.15; text-align: left; min-width: 0; }
.user-name { font-weight: 600; font-size: .875rem; white-space: nowrap; }
.org-name { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.caret { font-size: .7rem; color: var(--muted); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 230px; display: grid; gap: 2px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(15, 20, 30, .18); }
.menu a, .menu .menu-link { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent; border-radius: 6px; color: var(--text); text-decoration: none; font: inherit; font-size: .875rem; cursor: pointer; white-space: nowrap; }
.menu a:hover, .menu .menu-link:hover { background: var(--head-bg); }
.menu form { margin: 0; }

/* Headings and shared blocks */
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 12px; }
h2 { font-size: 1.2rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 20px 0 8px; }
.lead { font-size: 1.2rem; color: var(--muted); margin-top: 0; }
.hero { padding: 24px 0 8px; max-width: 680px; }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 1.6rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.card p { margin: 0; color: var(--muted); }
.back-link { display: inline-block; margin: 0 0 10px; font-weight: 600; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

.notice { background: var(--head-bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 18px; margin: 0 0 16px; }
.notice p { margin: 0 0 6px; }
.notice p:last-child { margin-bottom: 0; }
.notice-ok { border-color: var(--ok-fg); background: var(--ok-bg); color: var(--ok-fg); }
.notice-error { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 20px; }
.panel h2 { margin: 0 0 8px; font-size: 1.1rem; }
.panel p { margin: 0 0 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Buttons */
.btn, button.btn, summary.btn {
  appearance: none;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  line-height: 1.2;
  min-height: 40px;
  padding: 6px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  white-space: normal;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.btn:hover, button.btn:hover, summary.btn:hover { background: var(--head-bg); }
.btn-primary, .btn.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover, .btn.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-small, .btn.btn-small { min-height: 36px; padding: 4px 12px; font-size: .85rem; }
.btn:disabled, button.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.btn-danger-outline, .btn-danger-outline {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 600;
}
.btn.btn-danger-outline:hover, .btn-danger-outline:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-danger, .btn.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-solid, .btn.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; }
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }
summary.btn::marker { content: ""; }
.cancel { color: var(--accent); font-weight: 600; text-decoration: none; }
.cancel:hover { text-decoration: underline; }
.inline { display: inline-flex; margin: 0; }
form { margin: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lbl, .field label, legend { font-weight: 600; font-size: .9rem; color: var(--text); }
.field input, .field select, .field textarea, .agent-form input[type="text"], .agent-form input[type="number"], .agent-form select, .agent-form textarea {
  font: inherit;
  font-size: .95rem;
  min-height: 44px;
  padding: 8px 12px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-sizing: border-box;
}
.agent-form textarea, .field textarea { resize: vertical; min-height: 96px; }
.hint { display: block; color: var(--muted); font-size: .875rem; line-height: 1.45; }
.hint-inline { color: var(--muted); font-size: .875rem; font-weight: 400; }
.field-error { color: var(--danger); font-size: .875rem; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding-top: 4px; }

.agent-form { display: grid; gap: 20px; margin: 24px 0 56px; max-width: 760px; }
.agent-form .field { display: grid; gap: 8px; }
.na-title { margin: 6px 0 10px; }
.na-lead { max-width: 62ch; margin: 0; }
fieldset.panel { margin: 0; padding: 14px 16px 16px; display: grid; gap: 10px; }
fieldset.panel legend { padding: 0 6px; }
.check { display: flex; align-items: flex-start; gap: 10px; }
.check input { margin: 3px 0 0; flex: none; width: auto; min-height: 0; }
.check-disabled { color: var(--muted); }
.budgets { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }

/* Agents page */
.connect-form { display: grid; gap: 12px; max-width: 520px; }
.org-total-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.org-total-form .field { max-width: 260px; }
.org-total-readonly { margin: 0 0 8px; }
.list-tools { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 12px; }
.list-tools h2 { margin: 0; font-size: 1.1rem; }
.stop-all { position: relative; }
.warn-box { margin-top: 12px; border: 1px solid var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); color: var(--danger); border-radius: var(--radius); padding: 14px; max-width: 420px; }
.warn-box p { margin: 0 0 10px; font-weight: 600; }
.stop-all-disabled { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.agent-table { width: 100%; border-collapse: collapse; }
.agent-table th { background: var(--head-bg); color: var(--muted); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; text-align: left; padding: 10px 14px; }
.agent-table td { padding: 12px 14px; border-top: 1px solid var(--border); vertical-align: top; }
.agent-table td a { font-weight: 600; }
.nowrap { white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-active { background: var(--ok-bg); color: var(--ok-fg); }
.pill-paused { background: var(--warn-bg); color: var(--warn-fg); }
.pill-stopped { background: var(--off-bg); color: var(--off-fg); }
.empty-state { text-align: left; }
.empty-state p:last-child { margin-bottom: 0; }

/* Agent page */
.agent-page { display: grid; gap: 20px; padding-block: 8px 40px; min-width: 0; max-width: 1000px; }
.agent-page * { min-width: 0; }
.agent-page section { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; background: var(--surface); }
.crumb { margin: 0; font-size: .9rem; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.head-top { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; justify-content: space-between; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; max-width: 100%; }
.muted { color: var(--muted); font-size: .9rem; margin: 0 0 8px; }
.note-line { margin: 14px 0 0; max-width: 72ch; }
.delete-agent { margin-top: 12px; }
.stop-confirm { position: relative; display: inline-block; }
.stop-confirm > summary { cursor: pointer; }
.confirm-box { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: 320px; max-width: 90vw; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: 0 10px 30px rgba(15, 20, 30, .18); }
.confirm-box p { margin: 0 0 12px; font-size: .9rem; }
.confirm-box .row { display: flex; gap: 8px; flex-wrap: wrap; }
.confirm-box form { display: inline-flex; }

.edit-panel { max-width: 760px; }
.facts { display: grid; grid-template-columns: 220px 1fr; margin: 0 0 12px; border-top: 1px solid var(--border); }
.facts dt { margin: 0; padding: 11px 16px 11px 0; border-bottom: 1px solid var(--border); color: var(--muted); font-size: .88rem; font-weight: 500; }
.facts dd { margin: 0; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: .92rem; overflow-wrap: anywhere; }
.budget-input { font: inherit; font-size: .92rem; width: 110px; min-height: 32px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--head-bg); color: var(--muted); }
.budget-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin: 0 0 12px; }
.budget-form .field { flex: 0 1 200px; }

.run-now { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.run-now .field { flex: 1 1 300px; }
.run-now .field input { height: 44px; }
.run-btn { min-height: 44px; padding: 0 20px; }
.run-hint { margin: 10px 0 0; }
.ok { margin: 16px 0 0; padding: 10px 14px; border-radius: var(--radius); background: var(--ok-bg); color: var(--ok-fg); border: 1px solid color-mix(in srgb, var(--ok-fg) 35%, transparent); font-size: .9rem; }
.ok:empty { display: none; }
.report-text { margin: 0 0 8px; overflow-wrap: anywhere; }
.report-links { margin: 8px 0; padding-left: 20px; }
.report-links li { margin: 2px 0; }
.report-links a { overflow-wrap: anywhere; }

.log-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; margin: 0 0 14px; }
.log-tools .field { flex: 0 1 240px; flex-direction: row; align-items: flex-end; gap: 8px; }
.log-tools .field label { align-self: center; }
.exports { display: flex; gap: 8px; flex-wrap: wrap; }
.log-table { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.log-row { display: grid; grid-template-columns: 150px 1fr 1.4fr 110px; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: .88rem; align-items: baseline; }
.log-row:last-child { border-bottom: 0; }
.log-head { background: var(--head-bg); color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.log-row span { overflow-wrap: anywhere; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }

/* Footer */
.site-footer { border-top: 1px solid var(--border); color: var(--muted); padding: 20px 0; font-size: 14px; }
.footer-row { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; justify-content: space-between; }
.footer-brand { margin: 0; }
.fmark { margin-right: 6px; color: var(--accent); }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover, .footer-links a:focus { text-decoration: underline; }

/* Phone */
@media (max-width: 700px) {
  body { font-size: 15px; }
  h1 { font-size: 1.55rem; }
  .lead { font-size: 1.05rem; }
  main.wrap { padding-top: 20px; padding-bottom: 36px; }
  .header-row { gap: 8px 12px; padding-block: 6px; }
  .main-nav { order: 3; flex-basis: 100%; }
  .main-nav a { padding: 6px 4px; }
  .header-account { gap: 8px; }
  .avatar { width: 26px; height: 26px; font-size: .75rem; }
  .user-name { font-size: .78rem; }
  .org-name { display: block; font-size: .72rem; }
  .caret { display: none; }
  .menu { min-width: 210px; }
  .page-head .btn { width: 100%; }
  .org-total-form { flex-direction: column; align-items: stretch; gap: 12px; }
  .org-total-form .field { max-width: none; }
  .org-total-form .btn { width: 100%; }

  .agent-table thead { display: none; }
  .agent-table, .agent-table tbody, .agent-table tr, .agent-table td { display: block; width: 100%; box-sizing: border-box; }
  .agent-table tr { padding: 12px 14px; border-top: 1px solid var(--border); }
  .agent-table tr:first-child { border-top: 0; }
  .agent-table td { border: 0; padding: 4px 0; }
  .agent-table td::before { content: attr(data-label); display: block; color: var(--muted); font-size: .8rem; }

  .agent-page { padding-block: 0 24px; }
  .agent-page section { padding: 14px; }
  .head-top { flex-direction: column; }
  .head-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .head-actions .btn, .head-actions .inline, .head-actions .inline .btn, .head-actions .stop-confirm > summary { width: 100%; min-height: 44px; }
  .head-actions .inline { display: block; }
  .stop-confirm { grid-column: 1 / -1; }
  .stop-confirm > summary { width: 100%; }
  .confirm-box { left: 0; right: auto; width: 100%; max-width: 340px; }
  .facts { grid-template-columns: 1fr; border-top: 0; }
  .facts dt { border-bottom: 0; padding: 11px 0 0; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
  .facts dd { border-bottom: 1px solid var(--border); padding: 2px 0 11px; font-size: .95rem; }
  .budget-form { flex-direction: column; align-items: stretch; gap: 12px; }
  .budget-form .field { flex: 1 1 auto; }
  .budget-form .btn { width: 100%; }

  .run-now { flex-direction: column; align-items: stretch; gap: 12px; }
  .run-now .field { flex: 1 1 auto; }
  .run-now .field input { height: 44px; }
  .run-btn { width: 100%; min-height: 44px; }

  .log-tools { flex-direction: column; align-items: stretch; gap: 12px; }
  .log-tools .field { flex: 1 1 auto; }
  .exports .btn { flex: 1 1 0; }
  .log-row { grid-template-columns: 1fr; gap: 2px; padding: 12px 14px; }
  .log-head { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .log-row span { display: block; font-size: .9rem; }
  .log-row span::before { content: attr(data-label) ": "; color: var(--muted); font-weight: 600; }
  .log-row .tag { display: inline-block; font-weight: 600; }
  .log-row .tag::before { content: none; }
  .log-row span:first-child { font-weight: 700; }
}

@media (max-width: 480px) {
  .actions { flex-direction: column; align-items: stretch; }
  .actions .btn-primary { width: 100%; }
  .actions .cancel { text-align: center; }
  .exports .btn { flex: 1 1 auto; }
}
