/* IntegrateOS design baseline.
   One stylesheet, no build step, no framework — the smallest mechanism that
   makes the product feel like one product (Target Architecture V1, P19).
   Mobile-first; the desktop layout is the enhancement. */

:root {
  /* Color */
  --ink: #16202b;
  --ink-soft: #55677a;
  --line: #d7dee6;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --brand: #15364d;
  --brand-ink: #ffffff;
  --accent: #0b5d8a;
  --info: #0b5d8a;
  --info-bg: #e4edf4;
  --ok: #1d7a4c;
  --ok-bg: #e6f4ec;
  --warn: #8a5a00;
  --warn-bg: #fdf3dc;
  --bad: #a52f22;
  --bad-bg: #fbeceb;
  --idle: #55677a;
  --idle-bg: #eef1f4;
  --focus: var(--accent);
  /* Status — one vocabulary for badges, queues, and placeholders */
  --status-ready: var(--ok);
  --status-ready-bg: var(--ok-bg);
  --status-attention: var(--warn);
  --status-attention-bg: var(--warn-bg);
  --status-blocked: var(--bad);
  --status-blocked-bg: var(--bad-bg);
  --status-waiting: var(--idle);
  --status-waiting-bg: var(--idle-bg);
  --status-info: var(--info);
  --status-info-bg: var(--info-bg);
  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --leading-tight: 1.25;
  --leading-body: 1.5;
  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 43, .09);
  --gap: var(--space-4);
  --touch: 44px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: var(--text-md)/var(--leading-body) var(--font-sans);
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 22px 0 8px; }
h3 { font-size: .95rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }

.muted { color: var(--ink-soft); font-size: .9em; }
.skip-link {
  position: absolute; left: -999px;
  background: var(--brand); color: var(--brand-ink); padding: 10px 14px;
}
.skip-link:focus { left: 8px; top: 8px; z-index: 100; }

/* Visible focus everywhere — keyboard users must never lose their place. */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}

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

/* ── shell ──────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--brand); color: var(--brand-ink); padding: 10px 16px;
}
.topbar .brand {
  color: var(--brand-ink); font-weight: 700; text-decoration: none;
  display: flex; align-items: center; gap: 9px; font-size: 1.02rem;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px; background: #ffffff1f;
  display: grid; place-items: center; font-size: .8rem; font-weight: 700;
}
.topbar .spacer { flex: 1; }
.env-badge {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  background: #ffffff26; padding: 3px 8px; border-radius: 999px;
}
.user-menu summary {
  cursor: pointer; list-style: none; color: var(--brand-ink); font-size: .9rem;
  padding: 6px 4px;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu { position: relative; }
.user-popover {
  position: absolute; right: 0; top: 34px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; min-width: 190px; z-index: 40;
}

.layout { display: block; }
.sidebar {
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 12px;
}
.sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav-heading {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-soft); margin: 10px 6px 4px; width: 100%;
}
.sidebar a, .sidebar .disabled {
  display: block; padding: 8px 10px; border-radius: 8px;
  text-decoration: none; color: var(--ink); font-size: .93rem;
}
.sidebar a:hover { background: var(--idle-bg); }
.sidebar a[aria-current="page"] { background: #e4edf4; color: var(--accent); font-weight: 600; }
.sidebar .disabled { color: var(--ink-soft); cursor: not-allowed; }

main { max-width: 1040px; margin: 0 auto; padding: 18px 16px 56px; }
.page-header { margin-bottom: 4px; }
.page-header .lede { color: var(--ink-soft); margin: 0 0 14px; }
.footer {
  max-width: 1040px; margin: 0 auto; padding: 0 16px 26px;
  color: var(--ink-soft); font-size: .82rem;
}

@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 232px 1fr; min-height: calc(100vh - 46px); }
  .sidebar { border-bottom: 0; border-right: 1px solid var(--line); padding: 14px 10px; }
  .sidebar nav { display: block; }
  main { padding: 26px 30px 60px; }
}

/* ── surfaces ───────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 0 0 var(--gap);
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 400px; margin: 8vh auto; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.cards { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card.tap { display: block; text-decoration: none; color: inherit; }
.card.tap:hover { border-color: var(--accent); }
.card.inert { background: #fbfcfd; border-style: dashed; box-shadow: none; }

/* ── tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── badges ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 600; white-space: nowrap;
  background: var(--idle-bg); color: var(--idle);
}
.badge.ok      { background: var(--ok-bg);   color: var(--ok); }
.badge.warn    { background: var(--warn-bg); color: var(--warn); }
.badge.bad     { background: var(--bad-bg);  color: var(--bad); }
.badge.unknown { background: var(--idle-bg); color: var(--idle); }

/* ── controls ───────────────────────────────────────────────────────── */
label { display: block; margin: 10px 0 0; font-weight: 600; font-size: .88rem; }
input, select, textarea {
  width: 100%; padding: 10px 11px; margin-top: 5px; font-size: 1rem;
  border: 1px solid #c3ccd6; border-radius: 8px; background: #fff; color: var(--ink);
}
button, .button {
  display: inline-block; padding: 10px 15px; font-size: .95rem; font-weight: 600;
  border: 1px solid transparent; border-radius: 8px; background: #e3e9ef;
  color: var(--ink); cursor: pointer; text-decoration: none; margin-top: 10px;
}
button.primary, .button.primary { background: var(--accent); color: #fff; }
button.danger { background: var(--bad); color: #fff; }
button.small, .button.small { padding: 5px 10px; font-size: .82rem; margin-top: 0; }
button.linklike {
  background: none; border: 0; color: var(--accent); text-decoration: underline;
  padding: 2px; font-weight: 400; font-size: .88rem;
}
button:disabled, .button:disabled { opacity: .5; cursor: not-allowed; }
.rowform { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.rowform label { flex: 1 1 150px; margin-top: 0; }
.rowform button { margin-top: 0; }

/* ── messaging ──────────────────────────────────────────────────────── */
.flash { border-radius: 8px; padding: 11px 13px; margin: 0 0 12px; border: 1px solid; }
.flash.ok    { background: var(--ok-bg);   border-color: #b3ddc5; color: #14532d; }
.flash.error { background: var(--bad-bg);  border-color: #eebbb5; color: #7f231a; }
.notice {
  background: #eef4f9; border: 1px solid #c5dbeb; border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 12px 14px; margin: 0 0 var(--gap); font-size: .92rem;
}
.notice strong { display: block; margin-bottom: 3px; }
.empty {
  text-align: center; padding: 32px 18px; color: var(--ink-soft);
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface);
}
.empty strong { display: block; color: var(--ink); margin-bottom: 5px; }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 6px 16px; font-size: .92rem; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; padding: 0; list-style: none; }
.pill-list li {
  background: var(--idle-bg); border-radius: 6px; padding: 3px 8px;
  font-size: .8rem; font-family: ui-monospace, Menlo, monospace;
}

/* ── queue tabs ─────────────────────────────────────────────────────── */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 14px; }
.tab {
  padding: 6px 11px; border-radius: 7px; text-decoration: none;
  color: var(--ink-soft); font-size: .9rem; border: 1px solid transparent;
}
.tab:hover { background: var(--idle-bg); }
.tab.current {
  background: #e4edf4; color: var(--accent); font-weight: 600;
  border-color: #c9dced;
}
.tab-count {
  display: inline-block; margin-left: 5px; padding: 0 6px; border-radius: 9px;
  background: var(--idle-bg); color: var(--idle); font-size: .78rem;
}

/* Fixture provenance. Deliberately louder than an ordinary notice: nobody
   may mistake development data for live SISC financials. */
.notice.fixture { background: #fff8e6; border-color: #e6cf95; color: #6b4e05; }

textarea { width: 100%; font: inherit; resize: vertical; }

.ea-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--gap);
}
.ea-list { list-style: none; margin: 0; padding: 0; }
.ea-list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.ea-list li:last-child { border-bottom: 0; }
.ea-thread { max-width: 720px; }
.ea-msg { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin: 0 0 10px; }
.ea-msg.user { background: #e4edf4; }
.ea-ask { max-width: 720px; display: grid; gap: 8px; margin: 16px 0; }
.ea-ask button {
  justify-self: start; background: var(--brand); color: var(--brand-ink);
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

pre.artifact {
  margin: 0; padding: 12px; border-radius: 8px; background: #f6f8fa;
  border: 1px solid var(--line); overflow-x: auto; font-size: .82rem;
  font-family: var(--font-mono);
  white-space: pre; line-height: 1.45;
}

/* ── design system V1 patterns ──────────────────────────────────────── */
.ds-kicker {
  margin: 0 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}
h1 { font-size: var(--text-xl); line-height: var(--leading-tight); }
.ds-form label { font-size: var(--text-sm); }
input:not([type="hidden"]), select, textarea { min-height: var(--touch); }
button.primary, .button.primary, .topbar-ask, .shell-mobile a, .shell-mobile summary {
  min-height: var(--touch);
}

.topbar-ask {
  color: var(--brand-ink);
  text-decoration: none;
  border: 1px solid #ffffff55;
  border-radius: 999px;
  padding: 6px 12px;
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: var(--text-sm);
}
.topbar-ask:hover { background: #ffffff1f; }

.card-lead { border-color: var(--accent); }

.ds-status-ready { background: var(--status-ready-bg); color: var(--status-ready); }
.ds-status-attention { background: var(--status-attention-bg); color: var(--status-attention); }
.ds-status-blocked { background: var(--status-blocked-bg); color: var(--status-blocked); }
.ds-status-waiting { background: var(--status-waiting-bg); color: var(--status-waiting); }
.ds-status-info { background: var(--status-info-bg); color: var(--status-info); }

.ds-empty p { margin: 0; }
.ds-error {
  background: var(--bad-bg);
  border: 1px solid #eebbb5;
  border-left: 4px solid var(--bad);
  border-radius: var(--radius);
  padding: var(--space-4);
  color: #7f231a;
}
.ds-error strong, .ds-error h1 { display: block; color: inherit; margin: 0 0 var(--space-2); }
.ds-error p { margin: 0; }

.ds-loading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--ink-soft);
  font-size: var(--text-sm);
}
.ai-composer .ds-loading { display: none; }
.ai-composer.is-loading .ds-loading { display: flex; }
.ds-spinner {
  width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: ds-spin .8s linear infinite;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }

.ds-table-scroll { overflow-x: auto; }
.ds-table { width: 100%; }

.ai-slot { max-width: 40rem; }
.ws-ask .ai-slot { max-width: none; }
.ai-slot .ea-thread { margin: var(--space-3) 0; }
.ai-composer { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.ai-composer button { justify-self: start; }

.ws-home, .ws-stack, .ws-intent { display: grid; gap: var(--space-4); }
.ws-search { margin: 0; }
.ws-search button { min-height: var(--touch); margin-top: 0; justify-self: start; }
.ws-context { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; margin: 0 0 var(--space-3); padding: 0; }
.ws-context a, .ws-context span {
  display: inline-flex; align-items: center; min-height: var(--touch);
  padding: 0 var(--space-3); border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); text-decoration: none;
}
.ws-context [aria-current="true"] { border-color: var(--accent); color: var(--accent); font-weight: 700; }
@media (min-width: 800px) {
  .ws-intent { grid-template-columns: 1fr 1fr; }
  .ws-intent .ws-section[data-section="do"] { grid-column: 1 / -1; }
}
.ws-section { margin: 0; }
.ws-section[data-emphasis="primary"] { border-left: 4px solid var(--accent); }
.ws-section[data-emphasis="supporting"] { background: #fbfcfd; }
.ws-section-head h2 { margin-top: 0; }
.ws-items { list-style: none; margin: 0; padding: 0; }
.ws-item { padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
.ws-item:last-child { border-bottom: 0; padding-bottom: 0; }
.ws-item p { margin: var(--space-1) 0 0; }
.layer-list { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.ws-backlog { margin-top: var(--space-5); color: var(--ink-soft); font-size: var(--text-sm); }
.ws-backlog summary { cursor: pointer; font-weight: 600; color: var(--ink); min-height: var(--touch); display: flex; align-items: center; }

.shell-mobile {
  display: flex;
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.shell-mobile a, .shell-mobile summary {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
  font-size: var(--text-sm);
  padding: var(--space-2);
}
.shell-mobile a[aria-current="page"] { color: var(--accent); }
.shell-more { flex: 1; position: relative; }
.shell-more summary { list-style: none; cursor: pointer; }
.shell-more summary::-webkit-details-marker { display: none; }
.shell-more-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 4px);
  width: min(20rem, 100vw);
  max-height: 70vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-2);
}
@media (max-width: 899px) {
  body.has-mobile-nav { padding-bottom: calc(var(--touch) + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
}
@media (min-width: 900px) {
  .shell-mobile { display: none; }
}
