/* AiLookout — app page components: layout helpers, tables, stat tiles, timeline, forms,
   stepper, pick callouts, editor grid, remote chrome, detail header, how-to steps.
   Reads tokens from app.css. */

/* ---------- Layout helpers ---------- */

.stack { display: grid; gap: 16px; align-content: start; }
.split { display: grid; gap: 16px; align-items: start; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.grow { flex: 1; }
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 0.85em; }
.strong { font-weight: 600; color: var(--text); }
.danger { color: var(--bad); }
.hint { margin: 0; font-size: 0.8rem; color: var(--text-3); line-height: 1.5; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; display: inline-block; vertical-align: bottom; }
.section-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin: 0 0 8px; font-weight: 600; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.loading { display: inline-flex; align-items: center; gap: 10px; color: var(--text-3); padding: 24px 0; }
.loading::before {
    content: ""; width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tables ---------- */

.table-wrap { width: 100%; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th, .tbl td { padding: 11px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.tbl thead th {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); font-weight: 600;
    background: var(--surface-2); white-space: nowrap; border-bottom-color: var(--border);
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background 100ms ease; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .actions .btn { padding: 5px 10px; font-size: 0.85rem; }
.tbl .actions .btn svg { width: 15px; height: 15px; }
.tbl-compact th, .tbl-compact td { padding: 8px 12px; font-size: 0.85rem; }
.tbl .err { color: var(--bad); }
.tbl a.row-link { color: var(--text); font-weight: 600; }
.tbl a.row-link:hover { color: var(--accent); }
.tbl td.muted-cell { color: var(--text-3); }
.tbl .empty-row td { text-align: center; color: var(--text-3); padding: 28px 16px; }
.tbl-title { padding: 14px 16px; margin: 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tbl-title h2 { margin: 0; }

/* ---------- Stat tiles ---------- */

.stat-tile {
    --tile: var(--accent); --tile-soft: var(--accent-soft);
    position: relative; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; overflow: hidden;
    padding: 18px 20px 20px; color: inherit;
}
.stat-tile::before { content: ""; position: absolute; left: 0; top: 0; right: 0; height: 4px; background: var(--tile); }
.stat-tile .label { grid-column: 1; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.stat-tile .value { grid-column: 1; font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-tile .caption { grid-column: 1; font-size: 0.8rem; color: var(--text-3); min-height: 1.2em; }
.stat-tile .caption .warn { color: var(--bad); font-weight: 600; }
.stat-tile .icon {
    grid-column: 2; grid-row: 1 / span 3; align-self: start; width: 40px; height: 40px; border-radius: 10px;
    display: grid; place-items: center; background: var(--tile-soft); color: var(--tile);
}
.stat-tile .icon svg { width: 20px; height: 20px; }
.stat-tile.t-vivid { --tile: var(--vivid); --tile-soft: var(--vivid-soft); }
.stat-tile.t-warn { --tile: var(--warn); --tile-soft: var(--warn-soft); }
.stat-tile.t-bad { --tile: var(--bad); --tile-soft: var(--bad-soft); }
.stat-tile.t-info { --tile: var(--info); --tile-soft: var(--info-soft); }

/* ---------- Timeline ---------- */

.timeline { display: grid; position: relative; }
.tl-item { position: relative; display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 0 10px; padding: 8px 0; }
.tl-item::before { content: ""; position: absolute; left: 9px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.tl-item:first-child::before { top: 14px; }
.tl-item:last-child::before { bottom: calc(100% - 14px); }
.tl-item:only-child::before { display: none; }
.tl-dot {
    position: relative; z-index: 1; width: 20px; height: 20px; border-radius: 50%; margin-top: 1px;
    background: var(--surface); border: 2px solid var(--slate); display: grid; place-items: center;
}
.tl-dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--slate); }
.tl-dot.newitem { border-color: var(--accent); } .tl-dot.newitem::after { background: var(--accent); }
.tl-dot.watchhealed { border-color: var(--warn); } .tl-dot.watchhealed::after { background: var(--warn); }
.tl-dot.watchbroken, .tl-dot.loginrequired { border-color: var(--bad); } .tl-dot.watchbroken::after, .tl-dot.loginrequired::after { background: var(--bad); }
.tl-dot.test { border-color: var(--vivid); } .tl-dot.test::after { background: var(--vivid); }
.tl-body { min-width: 0; }
.tl-body .title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.tl-body .meta { color: var(--text-3); font-size: 0.8rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-time { color: var(--text-3); font-size: 0.8rem; white-space: nowrap; margin-top: 2px; }

/* ---------- Attention / generic lists ---------- */

.list { display: grid; }
.list-item { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.list-item:first-child { padding-top: 0; }
.list-item > div { min-width: 0; }
.list-item .title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.list-item .meta { color: var(--text-3); font-size: 0.8rem; }
.list-item .meta.err { color: var(--bad); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.all-good { display: flex; align-items: center; gap: 10px; color: var(--text-2); margin: 0; }
.all-good .ok-ring { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.all-good .ok-ring svg { width: 16px; height: 16px; }

.running-dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
    animation: pulse 1.1s ease-in-out infinite; margin-right: 6px; vertical-align: middle;
}
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.75); } }

/* ---------- Switch ---------- */

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; vertical-align: middle; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background 120ms ease; }
.switch span::after {
    content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 120ms ease;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + span { opacity: 0.5; cursor: default; }

/* ---------- Forms ---------- */

.form-grid { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; margin: 0; }
.field + .field { margin-top: 14px; }
.form-grid .field + .field { margin-top: 0; }
.field > span, .field > label.lbl { font-size: 0.8rem; font-weight: 600; color: var(--text-2); letter-spacing: 0.01em; }
.field > span .muted { font-weight: 400; }
.text-input,
.field input[type="text"], .field input[type="password"], .field input[type="url"], .field select, .field textarea {
    width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--text); font: inherit; font-size: 0.925rem; line-height: 1.4;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.text-input::placeholder, .field input::placeholder { color: var(--text-3); }
.text-input:hover, .field input:hover, .field select:hover { border-color: var(--text-3); }
.text-input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.text-input:disabled { background: var(--surface-2); color: var(--text-3); }
select.text-input, .field select {
    appearance: none; padding-right: 36px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
.field small, .field .hint { color: var(--text-3); font-size: 0.8rem; }
.field small a, .hint a { font-weight: 500; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-2); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.check-list { display: grid; gap: 8px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 18px; }
.form-actions .saved { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-size: 0.875rem; font-weight: 500; }
.form-actions .saved svg { width: 15px; height: 15px; }
.saved-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-height: 40px; }

.form-card h2 { margin: 0 0 14px; }
.form-card h2 + .muted { margin-top: -8px; }
.form-card h3 { margin: 20px 0 8px; }
.form-card.narrow { max-width: 600px; }
.form-card .section-break { margin: 24px 0 14px; padding-top: 20px; border-top: 1px solid var(--border); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
    display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 12px;
    border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    font: inherit; font-size: 0.875rem; cursor: pointer; text-align: left; transition: border-color 120ms ease, background 120ms ease;
}
.chip:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.chip.is-active { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--ring); }
.chip span { font-size: 0.775rem; }

.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-meta {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: 0.8rem; max-width: 100%;
}
.chip-meta svg { width: 13px; height: 13px; flex: none; color: var(--text-3); }
.chip-meta a, .chip-meta .trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.chip-meta.err { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.chip-meta.err svg { color: inherit; }

/* ---------- Stepper (wizard + teach bar) ---------- */

.stepper { display: flex; align-items: flex-start; gap: 0; margin-bottom: 20px; overflow-x: auto; padding-bottom: 2px; }
.stepper .step-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; min-width: 72px; text-align: center; }
.stepper .step-item:not(:last-child)::after {
    content: ""; position: absolute; top: 14px; left: calc(50% + 16px); right: calc(-50% + 16px); height: 2px;
    background: var(--border-strong); border-radius: 2px;
}
.stepper .step-item.done:not(:last-child)::after { background: var(--accent); }
.stepper .num {
    width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
    font-size: 0.8rem; font-weight: 600; background: var(--surface); border: 2px solid var(--border-strong); color: var(--text-3);
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}
.stepper .num svg { width: 14px; height: 14px; }
.stepper .lbl { font-size: 0.775rem; font-weight: 500; color: var(--text-3); line-height: 1.3; }
.stepper .active .num { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.stepper .active .lbl { color: var(--text); font-weight: 600; }
.stepper .done .num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stepper .done .lbl { color: var(--accent-strong); }
.stepper.compact { margin-bottom: 14px; }
.stepper.compact .num { width: 24px; height: 24px; font-size: 0.7rem; }
.stepper.compact .step-item:not(:last-child)::after { top: 12px; left: calc(50% + 14px); right: calc(-50% + 14px); }
.stepper.compact .lbl { font-size: 0.725rem; }

/* ---------- Pick summary callout ---------- */

.pick-summary {
    position: relative; display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px;
    padding: 14px 16px 14px 18px; font-size: 0.9rem; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--vivid-soft) 70%, var(--surface)));
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.pick-summary::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--grad); }
.pick-summary strong { color: var(--accent-strong); font-weight: 600; }
.pick-summary code { font-size: 0.75rem; word-break: break-all; background: color-mix(in srgb, var(--surface) 70%, transparent); }
.pick-summary .inline-form { margin-top: 4px; }
.samples { margin: 0; padding-left: 18px; font-size: 0.825rem; color: var(--text-2); list-style: disc; }
.samples li { margin-bottom: 2px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form .text-input { width: auto; flex: 1; min-width: 160px; }

.callout {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm);
    background: var(--info-soft); color: var(--text-2); font-size: 0.875rem; border: 1px solid color-mix(in srgb, var(--info) 20%, transparent);
}
.callout svg { width: 16px; height: 16px; flex: none; color: var(--info); margin-top: 2px; }
.callout p { margin: 0; }

.steps-list { padding-left: 0; margin: 0 0 14px; font-size: 0.875rem; counter-reset: s; }
.steps-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); counter-increment: s; }
.steps-list li:last-child { border-bottom: 0; }
.steps-list li::before {
    content: counter(s); flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent-strong); font-size: 0.7rem; font-weight: 600;
}
.steps-list code { font-size: 0.75rem; }

.summary { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; font-size: 0.9rem; margin: 0 0 16px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface-2); }
.summary dt { color: var(--text-3); font-weight: 500; }
.summary dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.summary code { font-size: 0.75rem; }

/* ---------- Editor grid + remote card ---------- */

.editor-grid { display: grid; gap: 20px; align-items: start; }
.remote-card { min-width: 0; padding: 16px; }
.remote-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.remote-head h2 { margin: 0; display: inline-flex; align-items: center; gap: 8px; }
.remote-head h2 svg { width: 18px; height: 18px; color: var(--vivid); }
.remote-intro { display: grid; gap: 12px; padding: 24px 20px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); text-align: center; color: var(--text-2); }
.remote-intro p { margin: 0; max-width: 52ch; margin-inline: auto; }
.remote-intro .btn { justify-self: center; }
.teach-note { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); font-size: 0.875rem; }
.teach-note svg { width: 16px; height: 16px; flex: none; color: var(--accent); margin-top: 1px; }

/* ---------- Detail header ---------- */

.detail-head { display: grid; gap: 12px; margin-bottom: 20px; padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.detail-head .title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.detail-head h1 { margin: 0; }
.detail-head .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.detail-head .msg { margin: 0; }

.kv { margin: 0; display: grid; gap: 6px; font-size: 0.85rem; }
.kv div { display: flex; gap: 8px; min-width: 0; }
.kv dt { color: var(--text-3); flex: none; min-width: 96px; }
.kv dd { margin: 0; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv.tight { gap: 2px; font-size: 0.8rem; }
.kv.tight dt { min-width: 0; }
.kv.tight dt::after { content: ":"; }

.deliveries { display: flex; flex-wrap: wrap; gap: 4px; }
.count-line { margin: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.count-line .big { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- How-to (numbered steps card) ---------- */

.howto h2 { margin-bottom: 14px; }
.howto ol { margin: 0; padding: 0; list-style: none; counter-reset: h; display: grid; gap: 14px; }
.howto li { position: relative; display: flex; gap: 12px; color: var(--text-2); font-size: 0.9rem; line-height: 1.5; counter-increment: h; }
.howto li::before {
    content: counter(h); flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
    background: var(--grad); color: #fff; font-size: 0.75rem; font-weight: 700;
}
.howto li:not(:last-child)::after { content: ""; position: absolute; left: 12px; top: 30px; bottom: -14px; width: 2px; background: var(--border); }
.howto li strong { color: var(--text); }
.howto li > span { padding-top: 3px; }

/* ---------- Error / not found ---------- */

.error-page { max-width: 560px; margin: 48px auto; text-align: center; padding: 40px 24px; }
.error-page .code { font-size: 3rem; font-weight: 700; letter-spacing: -0.04em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1; margin-bottom: 8px; }
.error-page h1 { margin-bottom: 8px; }
.error-page p { color: var(--text-2); }
.error-page details { text-align: left; margin-top: 20px; font-size: 0.875rem; color: var(--text-2); }
.error-page summary { cursor: pointer; font-weight: 500; color: var(--text); }

/* ---------- Responsive ---------- */

@media (min-width: 900px) {
    .split { grid-template-columns: minmax(0, 1fr) 340px; }
    .split-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .editor-grid { grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); }
    .editor-grid.wide-remote { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
    .stepper .lbl { font-size: 0.8rem; }
}

/* Key marker next to a field name: small, vertically centred, spaced from the name. */
.key-badge {
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 11px;
    line-height: 16px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

/* ---------- Alert rules, snooze, channel types ---------- */

.badge-slate { background: var(--slate-soft); color: var(--slate); }
.badge-nowmatches { background: var(--accent-soft); color: var(--accent-strong); }
.rule-editor { display: grid; gap: 18px; }
.rule-section { display: grid; gap: 12px; }
.rule-section + .rule-section { padding-top: 16px; border-top: 1px solid var(--border); }
.rule-section .section-title { margin: 0; }
.rule-section .field + .field { margin-top: 0; }
.rule-terms { min-height: 64px; resize: vertical; font-family: inherit; line-height: 1.5; }
.rule-fields { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.rule-checks { gap: 10px; }
.rule-error { color: var(--bad); font-size: 0.8rem; padding-left: 24px; }
.rule-quiet { display: grid; grid-template-columns: repeat(2, minmax(0, 160px)); gap: 12px; }
.rule-quiet input[type="time"] { width: 100%; }
.rule-quiet input:disabled { opacity: 0.55; cursor: not-allowed; }
.rule-summary { margin: 0; font-size: 0.9rem; color: var(--text-2); }
.rule-summary strong { color: var(--text); }
.wizard-rules { margin: 0 0 18px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pill-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.btn-group { display: inline-flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.btn-group-label { font-size: 0.75rem; font-weight: 600; color: var(--text-3); padding: 0 6px 0 8px; }
.type-select { display: flex; flex-wrap: wrap; gap: 8px; }
.type-select .chip { flex-direction: row; align-items: center; gap: 8px; }
.type-icon { width: 14px; height: 14px; flex: none; }
.type-pill { gap: 6px; }

/* Notifications empty state: one button per delivery type. */
.notify-choices { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 4px; }
