/* Aria application layer on top of the Jarvis theme (styles.css).
   Same palette and components; adds navigation, views, cards, tables,
   badges and the safety controls. Status is never conveyed by colour alone:
   every badge carries its word. */

:root {
    color-scheme: dark; /* native controls (WebKitGTK selects) follow the dark theme */
    --ok: #3fd98a;
    --warn: #ffaa00;
    --bad: #ff4455;
    --info: #00c8ff;
    --focus: #ffd24a;
    --nav-w: 210px;
}

html, body { overflow: hidden; }
body { display: flex; flex-direction: column; }
body.estop #header { box-shadow: inset 0 -3px 0 var(--bad); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 4px; z-index: 50; background: var(--card); color: var(--primary); padding: 6px 10px; }
.skip-link:focus { left: 8px; }
a { color: var(--primary); }
button, select, input, textarea { font: inherit; }
button, select {
    background: var(--card); color: var(--text-primary); border: 1px solid var(--border);
    border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--primary-dim); }
button:disabled, select:disabled { opacity: 0.45; cursor: default; }
button.primary { background: rgba(0, 200, 255, 0.12); border-color: var(--primary-dim); color: var(--primary); }
button.danger { border-color: rgba(255, 68, 85, 0.5); color: var(--bad); }
input, textarea {
    background: var(--bg); color: var(--text-primary); border: 1px solid var(--border);
    border-radius: 6px; padding: 7px 10px; width: 100%;
}
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.mono { font-family: var(--font-mono); }
.pre { white-space: pre-wrap; word-break: break-word; }
.inline { display: inline-flex; align-items: center; gap: 6px; width: auto; }
.inline input { width: auto; }
.form-error { color: var(--bad); font-size: 13px; min-height: 1em; }

/* ── header additions ── */
#header { gap: 8px; flex-wrap: nowrap; }
#nav-toggle { display: none; }
.header-btn { font-size: 13px; padding: 5px 10px; }
.estop-btn {
    background: var(--bad); color: #fff; border: 2px solid #ff8a95; border-radius: 6px;
    font-weight: 800; letter-spacing: 1px; padding: 6px 12px; cursor: pointer;
}
.estop-btn:hover { background: #ff2233; }
.header-link { position: relative; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; width: 38px; height: 38px; border-color: var(--border); color: var(--text-secondary); }
.count {
    position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; border-radius: 9px;
    background: var(--warn); color: #111; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; padding: 0 4px;
}
#mode-select { font-size: 13px; padding: 4px 6px; }

/* ── badges ── */
.badge {
    display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.4px;
    padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border); color: var(--text-secondary);
    margin-right: 4px; white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: rgba(63, 217, 138, 0.45); }
.badge.info { color: var(--info); border-color: rgba(0, 200, 255, 0.45); }
.badge.warn { color: var(--warn); border-color: rgba(255, 170, 0, 0.5); }
.badge.bad { color: #fff; background: rgba(255, 68, 85, 0.85); border-color: var(--bad); }
.mode-badge { font-size: 12px; }

/* ── layout ── */
#app { flex: 1; display: flex; min-height: 0; }
#nav { width: var(--nav-w); background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
#nav ul { list-style: none; padding: 10px 6px; }
#nav a {
    display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 6px;
    color: var(--text-primary); text-decoration: none; font-size: 14px;
}
#nav a:hover { background: var(--card); }
#nav a[aria-current="page"] { background: var(--primary-glow); color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
#nav-backdrop { display: none; }
#main { flex: 1; overflow-y: auto; min-width: 0; padding: 16px 20px; outline: none; display: flex; flex-direction: column; }
#main > * { max-width: 1100px; width: 100%; flex-shrink: 0; }
#main > .view { display: flex; flex-direction: column; }
#main > .view-chat { flex: 1 1 auto; min-height: 0; }
.view-chat > .chat-layout { flex: 1; }
.header-sub { margin-top: 2px; }
.header-link svg { display: block; }

.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.view-head h1 { font-size: 18px; letter-spacing: 1px; color: var(--primary); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-secondary); margin-bottom: 10px; }
.card h3 { font-size: 13px; margin: 8px 0 4px; }
.empty-note { color: var(--text-secondary); padding: 12px 0; font-style: italic; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; color: var(--text-secondary); font-weight: 600; border-bottom: 1px solid var(--border); padding: 6px; }
table.data td { border-bottom: 1px solid var(--border); padding: 6px; vertical-align: top; word-break: break-word; }
.card { overflow-x: auto; }

dl.kv { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 6px 12px; font-size: 13px; }
dl.kv dt { color: var(--text-secondary); }
dl.kv dd { word-break: break-word; }

/* goals */
.goal-list { list-style: none; }
.goal-row { border-bottom: 1px solid var(--border); }
.goal-link { display: flex; flex-direction: column; gap: 4px; padding: 10px 4px; text-decoration: none; color: var(--text-primary); }
.goal-link:hover { background: var(--card); }
.goal-desc { font-size: 14px; }
.goal-meta { font-size: 12px; }
.goal-objective { font-size: 15px; margin-bottom: 8px; white-space: pre-wrap; }
.result { margin-top: 12px; border-left: 3px solid var(--ok); padding-left: 10px; }
.result.bad { border-left-color: var(--bad); }
ol.timeline { list-style: none; font-size: 12px; max-height: 420px; overflow-y: auto; }
ol.timeline li { padding: 3px 0; border-bottom: 1px dashed var(--border); }
ol.phases { padding-left: 20px; font-size: 13px; }

/* human + notifications */
.request-card, .notification, .memory-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.request-card { border-left: 4px solid var(--warn); }
.request-question { font-size: 15px; margin: 8px 0; white-space: pre-wrap; }
.choice-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.answer-row { display: flex; gap: 6px; }
.notification.prio-critical { border-left: 4px solid var(--bad); }
.notification.prio-high { border-left: 4px solid var(--warn); }
.notification.acked { opacity: 0.65; }
.notification-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; margin-top: 6px; }
.notification-foot .ack { margin-left: auto; }
.row-actions { display: flex; gap: 6px; margin-top: 8px; }
.search-row { display: flex; gap: 6px; margin-bottom: 8px; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.param-form { display: flex; flex-direction: column; gap: 6px; max-width: 520px; }

/* activity */
.activity-list { list-style: none; font-size: 13px; }
.activity-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.activity-time { min-width: 72px; font-size: 11px; }
.activity-row.lvl-muted .activity-text { color: var(--text-secondary); }
.activity-details summary { cursor: pointer; font-size: 11px; color: var(--text-secondary); }
.activity-details pre { max-width: 100%; overflow-x: auto; background: var(--bg); padding: 6px; border-radius: 4px; }

/* chat (Jarvis bubbles) */
.chat-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; margin: -16px -20px; max-width: none !important; height: calc(100% + 32px); }
#message-input { resize: none; border: none; background: none; }
.jarvis-bubble { white-space: normal; }
.jarvis-bubble.failed { border-color: rgba(255, 68, 85, 0.5); }
.thread-state { font-size: 12px; color: var(--warn); margin-bottom: 4px; }
.thread-activity { list-style: none; font-size: 12px; color: var(--text-secondary); }
.thread-activity li::before { content: '› '; color: var(--primary-dim); }
.thread-activity li.lvl-bad { color: var(--bad); }
.chat-note { font-size: 11px; color: var(--text-secondary); text-align: center; padding: 4px 8px 8px; background: var(--surface); }

/* auth gate + toasts */
#auth-gate { position: fixed; inset: 0; background: rgba(5, 8, 16, 0.94); display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; overflow-y: auto; z-index: 40; padding: 16px; }
.auth-card h2 { font-size: 15px; color: var(--primary); }
#auth-gate[hidden] { display: none; }
#auth-form[hidden] { display: none; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: min(420px, 100%); display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.auth-card h1 { font-size: 18px; text-align: center; color: var(--primary); }
.auth-card .empty-logo { align-self: center; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100% - 32px)); }
.toast { background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--info); padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }

/* ── responsive: usable well below 1000px, down to phone widths ── */
@media (max-width: 900px) {
    #nav-toggle { display: inline-flex; }
    #nav { position: fixed; top: 64px; bottom: 0; left: 0; transform: translateX(-100%); transition: transform 0.2s; z-index: 30; }
    #nav { visibility: hidden; transition: transform 0.2s, visibility 0.2s; }
    body.nav-open #nav { transform: translateX(0); visibility: visible; }
    body.nav-open #nav-backdrop { display: block; position: fixed; inset: 64px 0 0 0; background: rgba(0, 0, 0, 0.5); z-index: 29; }
    #mode-select { display: none; }
    #main { padding: 12px; }
    .chat-layout { margin: -12px; height: calc(100% + 24px); }
}
@media (max-width: 560px) {
    #header { padding: 0 8px; gap: 6px; }
    .header-title { font-size: 16px; letter-spacing: 2px; }
    #status-label { display: none; }
    .estop-btn { padding: 6px 8px; font-size: 12px; white-space: nowrap; }
    .header-link { width: 32px; height: 32px; }
    #nav-toggle { width: 36px; height: 36px; }
    .mode-badge { font-size: 10px; padding: 1px 6px; }
    .header-btn { padding: 5px 6px; font-size: 12px; }
    dl.kv { grid-template-columns: 1fr; }
    .answer-row { flex-direction: column; }
}
.card p { font-size: 13px; }
.thread-steps { margin-top: 6px; font-size: 12px; }
.thread-steps summary { cursor: pointer; color: var(--text-secondary); }
