/* Application styles. Layout: left sidebar + main column (see .ai/11). */
@import url('tokens.css');

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.45;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { color: var(--fg); }
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.muted { color: var(--fg-muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.ok { color: var(--ok); }
.err { color: var(--accent); }
.warn-text { color: var(--gold-fg); }

/* ---- shell: sidebar + main ------------------------------------------- */
.shell { display: flex; flex: 1; }
.side {
    width: 248px; flex: none;
    background: var(--surface-soft);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
}
.side .brand {
    padding: 22px 18px 16px; border-bottom: 1px solid var(--line);
    display: flex; flex-direction: column; align-items: center; text-align: center;
}
.side .brand .logo { margin-bottom: 12px; }
.side .brand b { display: block; font-size: 16px; line-height: 1.25; }
.side .brand .role {
    display: inline-block; margin-top: 6px;
    font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--gold-fg);
}
.side nav { padding: 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.side nav a, .side nav .navbtn {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; border-radius: var(--radius-sm);
    text-decoration: none; font-weight: 500; font-size: 14px; color: var(--fg);
    border-left: 3px solid transparent;
}
.side nav a:hover { background: var(--surface); }
.side nav a.on { border-left-color: var(--accent); background: var(--surface); color: var(--accent); }
.side nav a .count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--fg-muted); }
.side nav a .devid { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--fg-muted); font-weight: 400; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side nav a .devid .dot { margin-right: 4px; }
.side .sidefoot { margin-top: auto; padding: 14px 18px 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--fg-muted); }
.side .sidefoot a { color: var(--fg-muted); }
.side .sidefoot .btn.link { color: var(--fg-muted); text-decoration-color: var(--line-strong); font-size: 12px; text-align: left; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* logo: square box; the image is scaled to fit entirely inside it */
.logo {
    --logo: 44px;
    width: var(--logo); height: var(--logo); border-radius: var(--radius);
    display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex: none;
    font-family: var(--mono); font-size: calc(var(--logo) * 0.36);
}
.logo.letter { background: var(--inverse-bg); color: var(--inverse-fg); }
.logo.image { background: #fff; padding: 4px; border: 1px solid var(--line); }
.logo img { display: block; width: 100%; height: 100%; object-fit: contain; }
.logo.sm { --logo: 40px; }
.logo.lg { --logo: 96px; }
.side .brand .logo { --logo: 96px; }

/* header (every page) */
.hdr .logo { --logo: 48px; }
.hdr {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
}
.hdr .org { flex: 1; min-width: 0; }
.hdr .org b { display: block; font-size: 18px; line-height: 1.2; }
.hdr .org span { color: var(--fg-muted); font-size: 13px; }
.mark { font-weight: 700; font-size: 15px; letter-spacing: -0.02em; text-decoration: none; white-space: nowrap; }
.hdr .mark { font-size: 28px; }
.hdr .tools { display: flex; align-items: center; gap: 14px; }
.mark .sim { color: var(--fg); }
.mark .table { color: var(--accent); }

/* device entry (Device page): horizontal row, hint underneath */
.device-row {
    display: flex; flex-direction: column; gap: 6px;
    padding: 14px 16px; margin: 0 0 24px;
    background: var(--surface-soft); border: 1px solid var(--line); border-radius: var(--radius);
}
.device-row .entry { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.device-row label { font-weight: 500; }
.device-row .field { width: 260px; max-width: 100%; }
.device-row .meta { font-size: 13px; }
.device-row .hint { font-size: 12px; color: var(--fg-muted); }

/* heartbeat */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--off); }
.dot.live { background: var(--ok); }
.dot.idle { background: var(--idle); }
.dot.off { background: var(--off); }

/* inputs */
.field {
    font: inherit; color: var(--fg); padding: 8px 10px;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--surface); min-width: 0;
}
.field.mono { font-family: var(--mono); font-size: 13px; }
.field:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field[aria-invalid='true'] { border-color: var(--accent); }
textarea.field { resize: vertical; }
select.field { padding-right: 24px; }
input[type='checkbox'], input[type='radio'] { accent-color: var(--accent); }

/* buttons */
.btn {
    font-weight: 500; padding: 9px 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--fg);
    cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--fg-muted); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.icon { padding: 6px 7px; line-height: 0; display: inline-flex; align-items: center; justify-content: center; }
.btn.icon.danger:hover { border-color: var(--accent); color: var(--accent); }
.icon { display: inline-flex; line-height: 0; vertical-align: middle; }
.btn .icon + span, .btn span + .icon { margin-left: 6px; }
.btn.link { background: none; border: none; padding: 0; color: var(--fg); text-decoration: underline; text-decoration-color: var(--line-strong); }
.btn.link.danger { color: var(--accent); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

/* content */
main.content { padding: 20px 24px 120px; flex: 1; max-width: 1100px; width: 100%; }
h1.page { font-size: 24px; margin: 0 0 4px; }
h2.sub { font-size: 18px; margin: 0 0 4px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
h2.sub .meta { font-weight: 400; }
h2.module {
    font-family: var(--mono); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--accent); margin: 22px 0 10px; display: flex; align-items: center; gap: 10px;
}
h2.module::after { content: ''; flex: 1; height: 1px; background: var(--accent-soft-line); opacity: 0.6; }
h2.module .tools { font-family: var(--sans); text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--fg-muted); display: flex; gap: 8px; }
.empty { color: var(--fg-muted); padding: 30px 0; text-align: center; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 8px; position: relative;
}
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.card.archived { opacity: 0.6; }
.card .title { display: flex; align-items: flex-start; gap: 10px; font-weight: 700; font-size: 16px; }
.card .title input { margin: 4px 0 0; flex: none; }
.card .title a { text-decoration: none; flex: 1; min-width: 0; }
.card .title a:hover { text-decoration: underline; }
.card .title .badge { margin-left: auto; margin-top: 2px; flex: none; }
.meta { color: var(--fg-muted); font-size: 13px; }
.diff { letter-spacing: 2px; color: var(--fg-soft); }
.summary { font-size: 14px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.badge {
    font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 3px;
    background: var(--gold-bg); color: var(--gold-fg); white-space: nowrap;
}
.badge.draft { background: var(--gold-bg-soft); border: 1px dashed var(--gold); }
.tag { font-size: 12px; color: var(--fg-muted); }
.copystat { font-size: 13px; color: var(--fg-muted); display: flex; gap: 10px; flex-wrap: wrap; }
.copystat .mine { color: var(--ok); font-weight: 500; }
.card .lead-actions { display: flex; gap: 12px; font-size: 13px; padding-top: 6px; flex-wrap: wrap; border-top: 1px dashed var(--line-soft); }
.card .card-foot { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 4px; }
.card .card-foot .btn { margin-left: auto; }
/* "+ Add Scenario" tile: same footprint as a card, outlined instead of filled */
.card.add {
    background: transparent; border: 2px dashed var(--line-strong);
    align-items: center; justify-content: center; min-height: 128px;
    text-decoration: none; color: var(--fg-muted); font-weight: 500; font-size: 15px;
}
.card.add:hover { border-color: var(--accent); color: var(--accent); }

/* sticky selection bar */
.sticky {
    position: fixed; left: 248px; right: 0; bottom: 0; z-index: 20;
    display: flex; align-items: center; gap: 14px;
    padding: 12px 24px; background: var(--inverse-bg); color: var(--inverse-fg);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
}
.sticky .btn.link { color: var(--inverse-fg); }

/* tables */
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th {
    text-align: left; font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--fg-muted); font-weight: 400; padding: 8px 6px; border-bottom: 1px solid var(--line);
}
table.list td { padding: 10px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.list td.mono { font-size: 13px; word-break: break-all; }
table.list tr.muted td { color: var(--fg-muted); }
table.list td.num { text-align: center; }
table.list th.center, table.list td.center { text-align: center; }
table.list.middle td { vertical-align: middle; }

/* detail */
.detail-head { display: flex; align-items: flex-start; gap: 16px; margin: 10px 0 4px; flex-wrap: wrap; }
.detail-head .t { flex: 1; min-width: 240px; }
.detail dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; margin: 16px 0 0; }
.detail dt { color: var(--fg-muted); font-size: 13px; }
.detail dd { margin: 0; white-space: pre-line; }
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 16px; }
.block h4 { margin: 0 0 10px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-muted); font-weight: 400; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--fg-muted); }
@media (min-width: 720px) { .kv { grid-template-columns: 90px 1fr 90px 1fr; } }
.kv.stack { grid-template-columns: 90px 1fr; }

/* tabs and forms */
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { padding: 8px 14px; font-weight: 500; color: var(--fg-muted); border: none; background: none; border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--fg); border-color: var(--accent); }
/* source picker (add scenario, From a Table): sort and legacy filter above a
   scrolling table of name (70%) and last-loaded date (30%) */
.pick-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 12px 0 8px; font-size: 13px; color: var(--fg-muted); }
.pick-controls label { display: inline-flex; align-items: center; gap: 8px; }
.pick-controls select.field { padding: 5px 24px 5px 8px; font-size: 13px; }
.pick-controls .meta { margin-left: auto; }
.pick-scroll { max-height: 360px; overflow: auto; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--surface); }
table.list.pick { table-layout: fixed; }
table.list.pick th { position: sticky; top: 0; background: var(--surface); z-index: 1; padding: 8px 10px; }
table.list.pick td { vertical-align: middle; padding: 8px 10px; cursor: pointer; }
table.list.pick tr:hover td { background: var(--surface-soft); }
table.list.pick tr.on td { background: var(--accent-soft); }
table.list.pick tr.muted td { cursor: default; color: var(--fg-muted); }
table.list.pick .pick-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
table.list.pick .pick-name input { margin: 0; flex: none; }
table.list.pick .pick-name .mono { font-size: 13px; overflow-wrap: anywhere; }
table.list.pick .pick-name .meta { white-space: nowrap; }
.form { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; align-items: center; margin-top: 16px; }
.form label { color: var(--fg-muted); font-size: 13px; }
.form .field { width: 100%; }
.form .foot { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.form .full { grid-column: 1 / -1; }
.callout { grid-column: 1 / -1; background: var(--gold-bg-soft); border: 1px solid var(--gold-bg); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; }
.callout.red { background: var(--accent-soft); border-color: var(--accent-soft-line); }
.callout.center { text-align: center; }

/* logo picker (staff page) */
.logo-pick {
    display: flex; align-items: center; gap: 14px; position: relative;
    padding: 10px 12px; border: 2px dashed var(--line-strong); border-radius: var(--radius);
    background: var(--surface); cursor: pointer; min-height: 84px;
}
.logo-pick:hover, .logo-pick:focus-visible, .logo-pick.over { border-color: var(--accent); outline: none; }
.logo-pick.ready { border-style: solid; border-color: var(--line); background: var(--surface-soft); }
.logo-pick.bad { border-color: var(--accent); }
.logo-pick .logo { --logo: 60px; }
.logo-pick .logo.empty { background: var(--surface-soft); color: var(--fg-muted); border: 1px solid var(--line); }
.logo-pick.bad .logo.empty { color: var(--accent); }
.logo-pick .text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; font-size: 13px; color: var(--fg-muted); }
.logo-pick .text b { color: var(--fg); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-pick .state { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; margin-top: 2px; }
.logo-pick .actions { display: flex; gap: 12px; font-size: 13px; flex: none; }
@media (min-width: 820px) {
    .form { grid-template-columns: 110px 1fr 110px 1fr; }
    .form .wide { grid-column: 2 / 5; }
}
/* new organization form (admin page): name over slug in the first column, the
   logo picker beside them in the second, label centred against it */
.org-form { margin-top: 0; }
.org-form .f-logo { align-self: stretch; }
@media (min-width: 820px) {
    .org-form .l-name { grid-area: 1 / 1; }
    .org-form .f-name { grid-area: 1 / 2; }
    .org-form .l-slug { grid-area: 2 / 1; }
    .org-form .f-slug { grid-area: 2 / 2; }
    .org-form .l-logo { grid-area: 1 / 3 / 3 / 4; }
    .org-form .f-logo { grid-area: 1 / 4 / 3 / 5; }
}
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* dialog overlay */
.overlay { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; z-index: 50; padding: 16px; }
.dialog {
    background: var(--bg); border-radius: 8px; padding: 18px; width: min(560px, 100%);
    max-height: 100%; overflow: auto; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 12px; font-size: 14px;
}
.dialog h3 { margin: 0; font-size: 17px; }
.dialog .row { display: flex; flex-direction: column; gap: 4px; }
.dialog .row label { font-size: 12px; color: var(--fg-muted); font-weight: 500; }
.dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.steps li::before { content: '○ '; color: var(--off); font-family: var(--mono); }
.steps li.done::before { content: '✓ '; color: var(--ok); }
.steps li.now::before { content: '● '; color: var(--accent); }
.steps li.fail::before { content: '✗ '; color: var(--accent); }
.steps li.now { font-weight: 500; }
.item-head { font-weight: 700; margin-top: 6px; }
.result-name { font-family: var(--mono); font-size: 15px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; word-break: break-all; }
.warn { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 10px 12px; font-size: 13px; border-radius: 3px; }
.toggle { display: flex; align-items: center; gap: 8px; }
@media (max-width: 600px) {
    .overlay { padding: 0; align-items: stretch; }
    .dialog { border-radius: 0; width: 100%; min-height: 100%; }
}

/* landing */
.landing { max-width: 1000px; margin: 0 auto; padding: 36px 24px 80px; width: 100%; }
.landing h1 { font-size: 30px; margin: 0 0 6px; }
.landing .lede { color: var(--fg-muted); margin: 0 0 28px; font-size: 16px; }
.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
/* an org row is a 40px logo plus padding and border; the admin button matches it */
.roles { --org-row: 58px; }
.role-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px;
    display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--accent);
}
.role-card.staff { border-top-color: var(--fg); }
.role-card.lead { border-top-color: var(--gold); }
.role-card h2 { margin: 0; font-size: 19px; }
.role-card p { margin: 0; color: var(--fg-muted); font-size: 14px; flex: 1; }
.role-card .orgs { display: flex; flex-direction: column; gap: 6px; }
.role-card .orgs a { display: flex; align-items: center; gap: 12px; text-decoration: none; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-soft); }
.role-card .orgs a:hover { border-color: var(--accent); }
.role-card .orgs a b { display: block; font-weight: 500; line-height: 1.25; }
.role-card .orgs a .slug { display: block; font-family: var(--mono); font-size: 11px; color: var(--fg-muted); margin-top: 2px; }
.role-card .hint { font-size: 13px; color: var(--fg-muted); }
.role-card .orgs a { min-height: var(--org-row); }
.role-card .btn.full { align-self: stretch; text-align: center; text-decoration: none; display: flex; align-items: center; justify-content: center; min-height: var(--org-row); }

/* notices (access problems, staff token gate) */
.notice { max-width: 560px; margin: 40px auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.notice h2 { margin: 0; font-size: 20px; }
.notice p { margin: 0; color: var(--fg-muted); }
.notice .foot { display: flex; justify-content: flex-end; }
.notice .btn { align-self: flex-start; text-decoration: none; }

/* official copy name: fixed prefix and suffix around an editable middle */
.official { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.official .fixed { font-size: 13px; color: var(--fg-muted); white-space: nowrap; }
.official .field { flex: 1; min-width: 160px; }

/* access box (landing, access problems) */
.access { display: flex; flex-direction: column; gap: 8px; }
.access b { font-size: 15px; }
.access .inline { flex-wrap: nowrap; align-items: stretch; }
.access .inline .btn { display: inline-flex; align-items: center; }
.access .field { flex: 1; min-width: 0; }
.notice.access-notice { margin: 28px auto 0; max-width: 1000px; }

/* staff: links dialog */
.dialog.wide { width: min(720px, 100%); }
.dialog .mint { display: grid; grid-template-columns: repeat(2, minmax(0, 230px)); justify-content: center; gap: 10px; }
.dialog .mint .btn { width: 100%; }
.linkbox { background: var(--surface-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.linkbox code.link { font-family: var(--mono); font-size: 12px; word-break: break-all; flex: 1; min-width: 0; }
table.list.tokens td { padding: 6px; }
footer.foot .btn.link { color: var(--fg-muted); font-size: 12px; }

/* footer */
footer.foot { padding: 14px 24px; color: var(--fg-muted); font-size: 12px; border-top: 1px solid var(--line); display: flex; gap: 12px; flex-wrap: wrap; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: var(--inverse-bg); color: var(--inverse-fg); padding: 10px 16px; border-radius: var(--radius-sm); z-index: 60; font-size: 14px; }

/* theme toggle */
.theme-toggle { display: inline-flex; gap: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.theme-toggle button { background: var(--surface); border: none; padding: 6px 9px; cursor: pointer; color: var(--fg-muted); line-height: 0; }
.theme-toggle button.on { background: var(--inverse-bg); color: var(--inverse-fg); }

/* narrow screens: sidebar becomes a top strip */
@media (max-width: 760px) {
    .shell { flex-direction: column; min-height: 0; }
    .side { width: auto; border-right: none; border-bottom: 1px solid var(--line); }
    .side .brand { flex-direction: row; text-align: left; gap: 12px; padding: 12px 14px; }
    .side .brand .logo { margin: 0; --logo: 48px; }
    .side .brand b { flex: 1; }
    .side nav { flex-direction: row; flex-wrap: wrap; padding: 6px 8px; }
    .side nav a .devid { margin-left: 6px; max-width: 140px; }
    .side .sidefoot { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 14px; margin: 0; }
    .sticky { left: 0; }
    .hdr, .bar, main.content, .sticky, footer.foot { padding-left: 14px; padding-right: 14px; }
    .hdr .org b { font-size: 15px; }
}
