/* The shell (top bar, side nav and chip strip, language toggle, view container, placeholder text), then the
   account screens. Components arrive with the first screen that uses them. */

:root { --shell-top: 54px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; background: var(--a-bg); color: var(--a-text); font-family: var(--a-font-ui); font-size: 15px; line-height: 1.45; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--a-surface); }
button { font: inherit; color: inherit; }
h1 { margin: 0; font-size: 1.5rem; line-height: 1.2; text-wrap: balance; }
p { margin: 0; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--a-brand); outline-offset: 2px; }

.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 14px; min-height: var(--shell-top);
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--a-surface); border-bottom: 1px solid var(--a-line);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.02em; }
.logo-mark { display: inline-block; width: 22px; height: 22px; border-radius: var(--a-radius-sm); background: var(--a-brand); }
#workspace-slot, #workspace-slot[hidden] + #user-slot { margin-left: auto; }

.ws { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ws-label { color: var(--a-text-muted); font-size: 0.85rem; }
.ws-select { min-width: 0; max-width: 260px; padding: 6px 10px; background: var(--a-surface-2); color: var(--a-text); border: 1px solid var(--a-line); border-radius: var(--a-radius-sm); font: inherit; font-size: 0.9rem; text-overflow: ellipsis; }

.lang { display: flex; border: 1px solid var(--a-line); border-radius: var(--a-radius-sm); overflow: hidden; }
.lang button { min-width: 44px; min-height: 44px; border: 0; padding: 5px 10px; background: var(--a-surface); color: var(--a-text-muted); font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.lang button[aria-pressed="true"] { background: var(--a-brand); color: var(--a-on-brand); }
/* .lang clips its children, so the ring sits inside the button. */
.lang button:focus-visible { outline-offset: -2px; }
.lang button[aria-pressed="true"]:focus-visible { outline-color: var(--a-on-brand); }

.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100vh - var(--shell-top)); }
.side {
  position: sticky; top: var(--shell-top); align-self: start; display: flex; flex-direction: column; gap: 14px;
  min-height: calc(100vh - var(--shell-top)); max-height: calc(100vh - var(--shell-top)); overflow-y: auto;
  padding: 14px 10px 24px max(10px, env(safe-area-inset-left, 0px));
  background: var(--a-surface); border-right: 1px solid var(--a-line);
}
.grp { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--a-radius-sm); color: var(--a-text); text-decoration: none; }
.nav-link[href]:hover { background: var(--a-surface-2); }
.nav-link[aria-current="page"] { background: var(--a-brand-soft); color: var(--a-brand); font-weight: 600; }
.nav-link[aria-disabled="true"] { color: var(--a-text-muted); cursor: default; }

.signed-out .shell { grid-template-columns: minmax(0, 1fr); }

.user-menu { position: relative; }
.user-menu summary { display: block; max-width: 40vw; padding: 5px 10px; border: 1px solid var(--a-line); border-radius: var(--a-radius-sm); overflow: hidden; font-size: 0.9rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; list-style: none; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 6; display: flex; flex-direction: column; min-width: 220px; max-width: calc(100vw - 32px); padding: 6px; background: var(--a-surface); border: 1px solid var(--a-line); border-radius: var(--a-radius-sm); }
.menu-email { padding: 6px 10px; color: var(--a-text-muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.menu-item { display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--a-radius-sm); background: none; color: var(--a-text); font-size: 0.95rem; text-align: left; text-decoration: none; cursor: pointer; }
.menu-item:hover { background: var(--a-surface-2); }

.view { min-width: 0; padding-block: 22px 60px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.screen { display: flex; flex-direction: column; gap: 18px; max-width: 1180px; margin: 0 auto; }
.placeholder { color: var(--a-text-muted); }

.form-card { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 420px; margin: 24px auto 0; padding: 22px; background: var(--a-surface); border: 1px solid var(--a-line); border-radius: var(--a-radius); }
.form-intro { color: var(--a-text-muted); }
.form-link { display: inline-flex; align-items: center; align-self: center; min-height: 44px; color: var(--a-brand); }
.field { display: flex; flex-direction: column; gap: 6px; overflow-wrap: anywhere; }
.field label, .field-label { font-size: 0.9rem; font-weight: 600; }
.field-hint { color: var(--a-text-muted); font-size: 0.85rem; }
.input { min-height: 44px; padding: 8px 12px; border: 1px solid var(--a-line); border-radius: var(--a-radius-sm); background: var(--a-bg); color: var(--a-text); font: inherit; font-size: 1rem; }
.btn { min-height: 44px; padding: 8px 16px; border: 0; border-radius: var(--a-radius-sm); background: var(--a-brand); color: var(--a-on-brand); font-weight: 600; cursor: pointer; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-link { display: inline-flex; align-items: center; align-self: flex-start; text-decoration: none; }
.form-message { padding: 10px 12px; border-radius: var(--a-radius-sm); font-size: 0.9rem; }
.form-message.bad { background: var(--a-bad-soft); }
.form-message.ok { background: var(--a-ok-soft); }
.form-message, .input { scroll-margin: calc(var(--shell-top) + 72px) 0 16px; }
.form-message:focus { outline: 2px solid var(--a-bad); outline-offset: 2px; }

.field-error { color: var(--a-bad); font-size: 0.85rem; }
.input[aria-invalid="true"] { border-color: var(--a-bad); }
textarea.input { resize: vertical; }
.input:disabled { opacity: 0.7; }

.btn-secondary { background: var(--a-surface); color: var(--a-text); border: 1px solid var(--a-line); }
.card { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 16px; background: var(--a-surface); border: 1px solid var(--a-line); border-radius: var(--a-radius); }
.card h2 { margin: 0; font-size: 1.05rem; }
.alert { padding: 10px 12px; border-radius: var(--a-radius-sm); font-size: 0.9rem; }
.alert.warn { background: var(--a-warn-soft); }
.gen-progress { display: flex; align-items: center; gap: 10px; background: var(--a-brand-soft); }
.gen-dot { flex: none; width: 10px; height: 10px; border-radius: var(--a-radius-full); background: var(--a-brand); animation: gen-pulse 1.2s ease-in-out infinite; }
@keyframes gen-pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .gen-dot { animation: none; } }
.gen-panel { overflow-wrap: anywhere; }
.gen-panel .input { width: 100%; min-width: 0; max-width: 100%; }
.gen-drafts { display: flex; flex-direction: column; gap: 12px; }
.gen-draft { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 12px; border: 1px dashed var(--a-line); border-radius: var(--a-radius-sm); }
.pill { display: inline-flex; padding: 3px 9px; border-radius: var(--a-radius-pill); background: var(--a-surface-2); color: var(--a-text-muted); font-size: 0.8rem; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 44px; padding: 6px 14px; border: 1px solid var(--a-line); border-radius: var(--a-radius-pill); background: var(--a-surface); color: var(--a-text); font-size: 0.9rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--a-text); border-color: var(--a-text); color: var(--a-bg); }
.chip:disabled { cursor: default; opacity: 0.7; }
.tile { min-width: 0; padding: 14px; background: var(--a-bg); border: 1px solid var(--a-line); border-radius: var(--a-radius); }
.tile-label { color: var(--a-text-muted); font-family: var(--a-font-mono); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; }
.tile-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-sub { color: var(--a-text-muted); font-size: 0.85rem; }
.kv { display: grid; grid-template-columns: minmax(0, 200px) minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.kv dt { color: var(--a-text-muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.kv dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }

.steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.step { min-height: 36px; padding: 5px 11px; border: 0; border-radius: var(--a-radius-pill); background: var(--a-surface-2); color: var(--a-text); font-size: 0.85rem; cursor: pointer; }
.step[data-state="done"] { background: var(--a-ok-soft); color: var(--a-ok); }
.step[data-state="current"] { background: var(--a-brand); color: var(--a-on-brand); font-weight: 600; }
.ob-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.ob-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ob-wide { grid-column: 1 / -1; }
.ob-stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ob-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.ob-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.ob-section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.ob-value { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ob-threshold { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.ob-threshold .field { flex: 1 1 240px; min-width: 0; }
.av-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; }
.av-head > :first-child { flex: 1 1 320px; }
.av-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 14px; align-items: start; }
.av-tab { max-width: 100%; min-width: 0; border-radius: var(--a-radius); text-align: left; overflow-wrap: anywhere; }
.av-dot { display: inline-block; flex: none; width: 10px; height: 10px; margin-right: 6px; border-radius: var(--a-radius-full); }
.av-dot[data-av="a"], .av-dot[data-av="d"] { background: var(--a-av-a); }
.av-dot[data-av="b"], .av-dot[data-av="e"] { background: var(--a-av-b); }
.av-dot[data-av="c"], .av-dot[data-av="f"] { background: var(--a-av-c); }
.av-dot:not([data-av="a"], [data-av="b"], [data-av="c"], [data-av="d"], [data-av="e"], [data-av="f"]) { background: var(--a-text-muted); }
.av-slug, .mono { font-family: var(--a-font-mono); font-size: 0.85rem; overflow-wrap: anywhere; }
.av-quotes { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; overflow-wrap: anywhere; }
.av-quotes li { display: flex; flex-direction: column; gap: 2px; padding-left: 10px; border-left: 2px solid var(--a-line); }
.av-quote { display: flex; flex-direction: column; gap: 6px; }
.av-quote-row { display: flex; flex-wrap: wrap; gap: 6px; }
.av-quote-row select { flex: 1 1 200px; min-width: 0; max-width: 100%; }
.chip-static { display: inline-flex; align-items: center; min-height: 0; padding: 3px 10px; cursor: default; }
.chip-static[data-on="true"] { background: var(--a-text); border-color: var(--a-text); color: var(--a-bg); }
.pill.ok { background: var(--a-ok-soft); color: var(--a-ok); }
.pill.warn { background: var(--a-warn-soft); color: var(--a-warn); }
.alert.ok { background: var(--a-ok-soft); }
.link-button { padding: 0; border: 0; background: none; color: var(--a-brand); text-align: left; text-decoration: underline; overflow-wrap: anywhere; cursor: pointer; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { color: var(--a-text-muted); font-weight: 600; text-align: left; }
.table th, .table td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--a-line); vertical-align: top; }
.table .num { padding-right: 0; text-align: right; font-variant-numeric: tabular-nums; }

.pill.bad { background: var(--a-bad-soft); color: var(--a-bad); }
.mx-wrap { overflow-x: auto; }
.mx { display: grid; grid-template-columns: 140px repeat(4, minmax(170px, 1fr)); gap: 8px; min-width: 840px; }
.mx-head { padding: 6px; color: var(--a-text-muted); font-family: var(--a-font-mono); font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; }
.mx-row-head { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; padding: 10px 6px; }
.mx-avatar { display: flex; align-items: center; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.mx-cell { display: flex; flex-direction: column; gap: 6px; min-width: 0; min-height: 96px; padding: 10px; border: 1px solid var(--a-line); border-radius: var(--a-radius-sm); background: var(--a-surface); color: var(--a-text); font-size: 0.9rem; text-align: left; cursor: pointer; }
button.mx-cell:hover:not(:disabled) { background: var(--a-surface-2); }
.mx-cell[aria-pressed="true"] { border-color: var(--a-brand); box-shadow: inset 0 0 0 1px var(--a-brand); }
.mx-cell[data-empty="true"] { color: var(--a-text-muted); border-style: dashed; }
div.mx-cell { cursor: default; }
.mx-cell[data-status="ARCHIVED"], .mx-cell[data-status="LOSER"] { background: var(--a-bg); color: var(--a-text-muted); }
.mx-angle { display: none; color: var(--a-text-muted); font-family: var(--a-font-mono); font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; }
.mx-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.mx-pills:empty { display: none; }
.mx-hook { overflow-wrap: anywhere; }
.mx-code { margin-top: auto; color: var(--a-text-muted); font-family: var(--a-font-mono); font-size: 0.72rem; overflow-wrap: anywhere; }
.mx-versions, .mx-losers { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.mx-versions li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mx-losers li { display: flex; flex-direction: column; gap: 2px; padding-left: 10px; border-left: 2px solid var(--a-line); overflow-wrap: anywhere; }
.mx-cards { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.mx-cards > li { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding-left: 10px; border-left: 2px solid var(--a-line); overflow-wrap: anywhere; }
.mx-card .input { width: 100%; min-width: 0; max-width: 100%; }
.mx-cards .draft-value { display: block; }
.check > span { min-width: 0; overflow-wrap: anywhere; }
#mx-asset .draft-value { display: block; }
.mx-lessons { margin: 0; padding-left: 18px; color: var(--a-text-muted); font-size: 0.9rem; }

.draft { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.draft-row { display: grid; grid-template-columns: minmax(0, 170px) minmax(0, 1fr) auto; gap: 4px 12px; align-items: start; padding: 8px 0; border-top: 1px solid var(--a-line); }
.draft-reference { background: var(--a-bg); }
.draft-reference dt, .draft-reference dd { padding-inline: 8px; }
.draft-link { display: inline-flex; align-items: center; align-self: flex-start; min-width: 44px; min-height: 44px; font-size: 0.85rem; overflow-wrap: anywhere; }
.missing-link { display: inline-flex; align-items: center; min-height: 44px; overflow-wrap: anywhere; }
.draft-warning { align-self: flex-start; }
.draft-block { margin: 8px 0 0; font-size: 0.95rem; overflow-wrap: anywhere; }
.draft-row dt { color: var(--a-text-muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.draft-row dd { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin: 0; }
.draft-value { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.draft-count { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.draft-hint { display: block; }
.draft-title { margin: 0; font-size: 1rem; font-family: var(--a-font-mono); overflow-wrap: anywhere; }
.draft-section { margin: 0; font-size: 1.15rem; }
.btn-copy { min-height: 36px; padding: 4px 12px; font-size: 0.85rem; white-space: nowrap; }
.ob-actions .btn-copy { min-height: 44px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--a-brand); }
.check-title { display: block; font-weight: 600; }

.mb-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.mb-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 160px) minmax(0, 240px); gap: 8px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--a-line); }
.mb-row:first-child { border-top: 0; }
.mb-who { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.mb-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; }
.mb-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.mb-wide { grid-column: 1 / -1; }
.mb-row > .pill { justify-self: start; }
.mb-link { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 12px; background: var(--a-surface-2); border-radius: var(--a-radius-sm); }

@media (max-width: 860px) {
  .ob-grid, .av-grid { grid-template-columns: minmax(0, 1fr); }
  /* A phone reads the matrix as a list: each cell names its own angle. */
  .mx { grid-template-columns: minmax(0, 1fr); min-width: 0; }
  .mx-head { display: none; }
  .mx-row-head { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0 2px; }
  .mx-angle { display: block; }
  .mx-cell { min-height: 0; }
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side {
    position: static; flex-direction: row; gap: 10px; min-height: 0; max-height: none; overflow-x: auto;
    padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
    border-right: 0; border-bottom: 1px solid var(--a-line);
  }
  .grp { flex-direction: row; flex-wrap: wrap; gap: 4px; align-items: center; min-width: 0; }
  .nav-link { padding: 6px 10px; white-space: nowrap; }
}

/* The switcher takes its own row on a phone, so a long name never pushes the top bar wider than the screen. */
@media (max-width: 520px) {
  .ob-fields, .ob-tiles, .kv { grid-template-columns: minmax(0, 1fr); }
  .draft-row { grid-template-columns: minmax(0, 1fr) auto; }
  .draft-row > :first-child { grid-column: 1 / -1; }
  .mb-row { grid-template-columns: minmax(0, 1fr); }
  .mb-actions { justify-content: flex-start; }
  .kv dd { margin-bottom: 8px; }
  .top { flex-wrap: wrap; }
  #workspace-slot { order: 3; flex: 1 0 100%; margin-left: 0; }
  #workspace-slot + #user-slot { margin-left: auto; }
  .ws-label { display: none; }
  .ws-select { flex: 1; max-width: none; }
}

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