/* REDEYE app layout on top of brand.css. Black and greys carry the UI; red is for primary actions, alerts and the mark. */
:root { --re-surface-3: #23232a; --re-dim: #5d5d66; --re-line: rgba(42, 42, 49, .7); }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body.re { overflow-x: hidden; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
a { color: var(--re-text); text-underline-offset: 3px; }
a:hover { color: #fff; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }
button { font: inherit; }
.re-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.re-btn--primary:disabled:hover { background: var(--re-red); }
.re-btn--sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.re-small { font-size: 12px; }
.re-strong { font-weight: 600; color: #ececf0; }
.re-block { display: block; }
.re-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.re-right { text-align: right; }
.re-center { text-align: center; }
.re-nowrap { white-space: nowrap; }

/* ---------- header ---------- */
.re-top { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 22px;
  padding: max(10px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 10px max(22px, env(safe-area-inset-left));
  background: rgba(10, 10, 11, .92); border-bottom: 1px solid var(--re-border); backdrop-filter: blur(8px); }
.re-top__brand { display: flex; flex-shrink: 0; }
.re-top .re-logo { height: 30px; }
.re-nav { display: flex; gap: 4px; flex: 1; min-width: 0; }
.re-nav a { padding: 6px 12px; border-radius: 8px; color: var(--re-muted); text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap; }
.re-nav a:hover { color: var(--re-text); background: var(--re-surface); }
[data-page="dashboard"] [data-nav="dashboard"], [data-page="obsidian"] [data-nav="obsidian"], [data-page="billing"] [data-nav="billing"] {
  color: #ececf0; background: var(--re-surface-2); box-shadow: inset 0 -2px 0 var(--re-red); }
.re-top__me { display: flex; align-items: center; gap: 12px; flex-shrink: 0; font-size: 13px; }
.re-top__me .re-user { color: var(--re-muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.re-top__me a { color: var(--re-muted); text-decoration: none; }
.re-top__me a:hover { color: var(--re-text); }
.re-tier { color: var(--re-text); }
.re-tier--pro { color: var(--re-warn); border-color: rgba(242, 179, 61, .45); }
.re-tier--enterprise { color: #fff; border-color: var(--re-red); background: rgba(122, 6, 20, .35); }

/* ---------- page ---------- */
.re-main { width: 100%; max-width: 1320px; margin: 0 auto; padding: 22px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.re-pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.re-pagehead h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; color: #ececf0; }
.re-pagehead p { margin: 4px 0 0; color: var(--re-muted); font-size: 14px; }
.re-card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.re-card__head h2 { font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--re-muted); }
.re-card__tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.re-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.re-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }

/* stat tiles */
.re-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.re-stat { padding: 14px 16px; }
.re-stat__k { font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--re-muted); }
.re-stat__v { font: 600 24px/1.25 var(--re-mono); color: #ececf0; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.re-stat__s { font-size: 12px; color: var(--re-muted); }
.re-stat--ok .re-stat__v { color: var(--re-ok); }
.re-stat--warn .re-stat__v { color: var(--re-warn); }
.re-stat--alert { border-color: rgba(229, 17, 43, .5); }
.re-stat--alert .re-stat__v { color: var(--re-red-glow); }

/* tables + lists */
.re-table-wrap { overflow-x: auto; margin: 0 -4px; }
.re-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.re-table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--re-muted);
  padding: 8px 10px; border-bottom: 1px solid var(--re-border); white-space: nowrap; }
.re-table td { padding: 10px; border-bottom: 1px solid var(--re-line); vertical-align: middle; }
.re-table tr:last-child td { border-bottom: 0; }
.re-table tbody tr:hover td { background: rgba(27, 27, 32, .5); }
.re-test { min-height: 1em; margin-top: 4px; color: var(--re-muted); }
.re-test.is-ok { color: var(--re-ok); }
.re-test.is-bad { color: var(--re-red-glow); }
.re-list { list-style: none; margin: 0; padding: 0; display: grid; }
.re-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--re-line); font-size: 13px; }
.re-list li:last-child { border-bottom: 0; }
.re-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--re-dim); flex-shrink: 0; vertical-align: middle; }
.re-dot--ok { background: var(--re-ok); box-shadow: 0 0 6px rgba(60, 207, 122, .5); }
.re-dot--warn { background: var(--re-warn); }
.re-dot--bad { background: var(--re-red); box-shadow: 0 0 6px rgba(229, 17, 43, .6); }
.re-pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; font-size: 12px; color: var(--re-muted); }

/* forms */
.re-input, .re-select, .re-textarea { width: 100%; padding: 9px 12px; background: var(--re-bg); color: var(--re-text);
  border: 1px solid var(--re-border); border-radius: 8px; font: 14px var(--re-font); }
.re-select { width: auto; max-width: 100%; }
.re-textarea { resize: vertical; min-height: 44px; }
.re-input:focus, .re-select:focus, .re-textarea:focus { outline: none; border-color: var(--re-muted); box-shadow: 0 0 0 2px rgba(229, 17, 43, .22); }
.re-field { display: grid; gap: 6px; font-size: 13px; color: var(--re-muted); }
.re-alert { padding: 10px 12px; border: 1px solid rgba(229, 17, 43, .5); background: rgba(122, 6, 20, .2); border-radius: 8px; font-size: 13px; }
.re-alert a { font-weight: 600; }
.re-note { padding: 10px 12px; border: 1px dashed var(--re-border); border-radius: 8px; font-size: 13px; color: var(--re-muted); }

/* chat */
.re-chat { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 14px; }
.re-sessions { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; align-content: start; max-height: 420px; overflow-y: auto; }
.re-session { width: 100%; display: grid; gap: 2px; text-align: left; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--re-border);
  background: var(--re-bg); color: var(--re-text); cursor: pointer; }
.re-session:hover { border-color: var(--re-muted); }
.re-session.is-active { background: var(--re-surface-2); border-color: var(--re-muted); box-shadow: inset 2px 0 0 var(--re-red); }
.re-convo { display: grid; gap: 10px; min-width: 0; }
.re-msgs { height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px;
  background: var(--re-bg); border: 1px solid var(--re-border); border-radius: 8px; }
.re-msg { max-width: 85%; padding: 9px 12px; border-radius: 10px; font-size: 14px; }
.re-msg__body { white-space: pre-wrap; overflow-wrap: anywhere; }
.re-msg__meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font: 11px var(--re-mono); color: var(--re-dim); }
.re-msg--user { align-self: flex-end; background: var(--re-surface-2); border: 1px solid var(--re-border); }
.re-msg--assistant { align-self: flex-start; background: var(--re-surface); border: 1px solid var(--re-border); border-left: 2px solid var(--re-muted); }
.re-chat__form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.re-chat__form .re-select { grid-column: 1 / -1; width: 100%; }

/* API key */
.re-key { display: grid; gap: 10px; margin-top: 12px; }
.re-key__row { display: flex; gap: 8px; }
.re-key__row .re-input { font-family: var(--re-mono); font-size: 13px; }
.re-code { margin: 0; padding: 10px 12px; background: var(--re-bg); border: 1px solid var(--re-border); border-radius: 8px;
  font: 12px/1.5 var(--re-mono); color: var(--re-muted); overflow-x: auto; white-space: pre; }

/* billing */
.re-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.re-plan { display: flex; flex-direction: column; gap: 12px; }
.re-plan.is-current { border-color: var(--re-muted); box-shadow: inset 0 2px 0 var(--re-red); }
.re-plan__name { font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--re-muted); }
.re-plan__price .re-mono { font-size: 30px; font-weight: 600; color: #ececf0; }
.re-plan__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; font-size: 13px; }
.re-plan__list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--re-line); }
.re-plan__list li span:first-child { color: var(--re-muted); }
.re-plan__list b { font: 500 13px var(--re-mono); }
.re-plan__act { margin-top: auto; }
.re-plan__act .re-btn { width: 100%; justify-content: center; }
.re-yes { color: var(--re-ok); font-weight: 700; }
.re-no { color: var(--re-dim); }
.re-usage { display: grid; gap: 6px; }
.re-usage-list { margin-top: 16px; gap: 14px; }
.re-usage__top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.re-usage__n { font-family: var(--re-mono); color: var(--re-muted); }
.re-bar { height: 8px; background: var(--re-surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--re-border); }
.re-bar > i { display: block; height: 100%; width: 0; background: #b9b9c2; border-radius: inherit; transition: width .4s ease; }
.re-bar--hot > i { background: var(--re-red); }
.re-plan-now { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.re-plan-now b { font: 600 26px var(--re-mono); color: #ececf0; text-transform: capitalize; }
.re-kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 16px; margin: 0; font-size: 13px; }
.re-kv dt { color: var(--re-muted); }
.re-kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- login ---------- */
.re-auth { flex: 1; display: grid; place-items: center; padding: 32px 16px; }
.re-auth__card { width: min(400px, 100%); display: grid; gap: 18px; padding: 28px; }
.re-auth__logo { justify-self: center; display: grid; gap: 10px; justify-items: center; }
.re-auth__logo .re-beam { width: 100%; margin: 0; }
.re-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--re-bg); border: 1px solid var(--re-border); border-radius: 9px; padding: 3px; }
.re-tab { padding: 7px; border: 0; border-radius: 7px; background: none; color: var(--re-muted); font-weight: 600; cursor: pointer; }
.re-tab.is-active { background: var(--re-surface-2); color: #ececf0; }
.re-auth form { display: grid; gap: 14px; }
.re-auth form .re-btn { justify-content: center; }
.re-auth__foot { text-align: center; font-size: 12px; color: var(--re-dim); }

/* ---------- modal + toasts ---------- */
.re-modal-back { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .66); backdrop-filter: blur(3px); }
.re-modal { width: min(440px, 100%); display: grid; gap: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, .6); }
.re-modal__title { font-size: 17px; color: #ececf0; }
.re-modal p { margin: 0; font-size: 14px; }
.re-modal__actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toasts { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 400; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { max-width: 360px; padding: 10px 14px; background: var(--re-surface-2); border: 1px solid var(--re-border); border-radius: 8px;
  font: 12.5px/1.45 var(--re-mono); color: var(--re-text); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: re-tin .2s ease-out; overflow-wrap: anywhere; }
.toast .t-sub { color: var(--re-muted); font-size: 11px; margin-top: 3px; }
.toast--ok { border-left: 2px solid var(--re-ok); }
.toast--alert { border-color: rgba(229, 17, 43, .6); border-left: 2px solid var(--re-red); }
.re--full #toasts { right: 300px; }
.re-table .re-badge { white-space: nowrap; }
@keyframes re-tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Obsidian Web (vendored Obsidian Eye markup, REDEYE tokens) ---------- */
body.re--full { height: 100vh; height: 100dvh; overflow: hidden; }
.ob { --tx-4: #6b6b74; --font-mono: var(--re-mono); flex: 1; min-height: 0; position: relative; background:
  radial-gradient(circle at 50% 45%, rgba(122, 6, 20, .10), transparent 60%), var(--re-bg); }
.ob .btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 7px; border: 1px solid var(--re-border);
  background: rgba(19, 19, 22, .92); color: var(--re-text); font: 600 12px var(--re-font); cursor: pointer; white-space: nowrap; }
.ob .btn:hover { border-color: var(--re-muted); color: #fff; }
.ob .btn.primary { background: var(--re-red); border-color: var(--re-red); color: #fff; }
.ob .btn.primary:hover { background: var(--re-red-glow); }
.ob .btn.sm { padding: 3px 9px; font-size: 11px; }
#graph-view { position: absolute; inset: 0; display: block; overflow: hidden; }
#graph-canvas { position: absolute; inset: 0; cursor: grab; touch-action: none; }
#graph-canvas.dragging { cursor: grabbing; }
#graph-toolbar { position: absolute; top: 14px; left: 14px; right: 300px; z-index: 27; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; pointer-events: none; }
#graph-toolbar > * { pointer-events: auto; }
.ob-add { display: flex; gap: 6px; padding: 4px; background: rgba(19, 19, 22, .92); border: 1px solid var(--re-border); border-radius: 9px; }
.ob-add select, .ob-add input { background: var(--re-bg); color: var(--re-text); border: 1px solid var(--re-border); border-radius: 6px; padding: 5px 8px; font: 12px var(--re-mono); min-width: 0; }
.ob-add input { width: 200px; }
.ob-add select:focus, .ob-add input:focus { outline: none; border-color: var(--re-muted); }
.ob-tools { display: flex; gap: 6px; flex-wrap: wrap; }
#graph-legend { position: absolute; bottom: 14px; left: 14px; z-index: 20; display: flex; flex-direction: column; gap: 5px; padding: 10px 14px;
  background: rgba(19, 19, 22, .9); border: 1px solid var(--re-border); border-radius: 9px; backdrop-filter: blur(6px); }
.legend-item { display: flex; align-items: center; gap: 8px; font: 10.5px var(--re-mono); color: var(--re-muted); }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
#graph-stats { position: absolute; bottom: 14px; right: 300px; z-index: 20; display: flex; gap: 14px; padding: 8px 14px;
  background: rgba(19, 19, 22, .9); border: 1px solid var(--re-border); border-radius: 9px; font: 10.5px var(--re-mono); color: var(--re-muted); }
#graph-stats b { color: #ececf0; font-weight: 600; }
#node-card { position: absolute; top: calc(var(--tb, 50px) + 10px); left: 14px; z-index: 25; width: 270px; display: none; overflow: hidden;
  background: rgba(19, 19, 22, .96); border: 1px solid var(--re-border); border-radius: var(--re-radius); backdrop-filter: blur(10px); box-shadow: 0 16px 40px rgba(0, 0, 0, .5); }
#node-card.show { display: block; }
#node-card .nc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--re-line); }
#node-card .nc-type { font: 9.5px var(--re-mono); letter-spacing: .18em; text-transform: uppercase; color: var(--tx-4); }
#node-card .nc-label { margin-top: 3px; font: 600 13px var(--re-mono); color: #ececf0; word-break: break-all; }
#node-card .nc-body { max-height: 240px; overflow-y: auto; padding: 8px 14px; }
.nc-attr { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--re-line); font: 11px var(--re-mono); }
.nc-attr:last-child { border-bottom: 0; }
.nc-attr .k { color: var(--tx-4); flex-shrink: 0; }
.nc-attr .v { color: var(--re-text); text-align: right; word-break: break-all; }
#node-card .nc-foot { display: flex; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--re-line); }
.nc-close { padding: 2px 4px; border: 0; background: none; color: var(--tx-4); cursor: pointer; font-size: 13px; }
.nc-close:hover { color: #fff; }
#transform-dock { position: absolute; top: 14px; right: 14px; bottom: 14px; z-index: 20; width: 272px; display: flex; flex-direction: column; overflow: hidden;
  background: rgba(19, 19, 22, .94); border: 1px solid var(--re-border); border-radius: var(--re-radius); backdrop-filter: blur(10px); }
#transform-dock .dock-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--re-line); }
#transform-dock .dock-head h3 { font: 600 10.5px var(--re-mono); letter-spacing: .22em; text-transform: uppercase; color: var(--re-muted); }
#dock-target { margin-top: 5px; font: 11px var(--re-mono); color: var(--tx-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#dock-target b { color: #ececf0; font-weight: 600; }
#dock-search { margin: 10px 12px 4px; width: calc(100% - 24px); padding: 6px 9px; background: var(--re-bg); color: var(--re-text);
  border: 1px solid var(--re-border); border-radius: 6px; font: 12px var(--re-mono); }
#dock-search:focus { outline: none; border-color: var(--re-muted); }
#dock-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 8px 10px; display: grid; gap: 2px; align-content: start; }
.t-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border: 1px solid transparent; border-radius: 7px;
  background: none; color: var(--re-text); text-align: left; cursor: pointer; }
.t-item:hover { background: var(--re-surface-2); border-color: var(--re-border); }
.t-item.disabled { opacity: .4; cursor: default; }
.t-item.disabled:hover { background: none; border-color: transparent; }
.t-item.running { border-color: var(--re-muted); animation: re-trun 1.2s ease-in-out infinite; }
@keyframes re-trun { 0%, 100% { background: var(--re-surface-2); } 50% { background: var(--re-surface-3); } }
.t-main { display: grid; gap: 1px; min-width: 0; flex: 1; }
.t-name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-out { font: 10px var(--re-mono); color: var(--tx-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-badge { flex-shrink: 0; padding: 1px 6px; border: 1px solid var(--re-border); border-radius: 4px; font: 600 9.5px var(--re-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--re-muted); }
.t-badge.premium { color: var(--re-red-glow); border-color: rgba(229, 17, 43, .55); background: rgba(122, 6, 20, .25); }
.dock-empty { padding: 14px 6px; font: 11px var(--re-mono); color: var(--tx-4); }
#dock-foot { display: flex; justify-content: space-between; gap: 8px; padding: 9px 14px; border-top: 1px solid var(--re-line); font: 10.5px var(--re-mono); color: var(--re-muted); }
#dock-foot:empty { display: none; }
#dock-foot b { color: #ececf0; }

/* toolbar extras: correlate, auto switch, counts, more menu */
.ob .btn.icon { min-width: 30px; justify-content: center; padding: 6px 8px; font-size: 14px; line-height: 1; }
.ob .btn:disabled { opacity: .4; cursor: default; }
.ob .btn:disabled:hover { border-color: var(--re-border); color: var(--re-text); }
.ob .btn.corr { border-color: rgba(229, 17, 43, .55); }
.ob .btn.corr:hover { border-color: var(--re-red); box-shadow: 0 0 12px rgba(229, 17, 43, .25); }
.ob .btn:focus-visible, .ob button:focus-visible, .ob input:focus-visible { outline: 2px solid var(--re-red-glow); outline-offset: 1px; }
.ob-count { min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--re-surface-3); color: var(--re-muted); font: 600 10px/16px var(--re-mono); text-align: center; }
.ob-switch { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px 5px 6px; border: 1px solid var(--re-border); border-radius: 7px;
  background: rgba(19, 19, 22, .92); font: 600 12px var(--re-font); color: var(--re-muted); cursor: pointer; user-select: none; }
.ob-switch input { appearance: none; -webkit-appearance: none; width: 26px; height: 15px; margin: 0; border-radius: 99px; background: var(--re-surface-3);
  border: 1px solid var(--re-border); position: relative; cursor: pointer; transition: background .15s; }
.ob-switch input::after { content: ""; position: absolute; top: 1px; left: 1px; width: 11px; height: 11px; border-radius: 50%; background: var(--re-muted); transition: transform .15s, background .15s; }
.ob-switch input:checked { background: var(--re-red-deep); border-color: var(--re-red); }
.ob-switch input:checked::after { transform: translateX(11px); background: #fff; }
.ob-switch:has(input:checked) { color: #ececf0; }
.ob-more { position: relative; }
.ob-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; min-width: 190px; display: grid; padding: 5px;
  background: rgba(19, 19, 22, .98); border: 1px solid var(--re-border); border-radius: 9px; box-shadow: 0 16px 40px rgba(0, 0, 0, .55); }
.ob-menu button { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 0; border-radius: 6px;
  background: none; color: var(--re-text); font: 500 13px var(--re-font); text-align: left; cursor: pointer; }
.ob-menu button:hover, .ob-menu button:focus-visible { background: var(--re-surface-2); color: #fff; outline: none; }
.ob kbd, .ob-keys kbd { padding: 1px 6px; border: 1px solid var(--re-border); border-bottom-width: 2px; border-radius: 5px; background: var(--re-bg); font: 600 11px var(--re-mono); color: var(--re-text); }
.ob-keys { grid-template-columns: 110px minmax(0, 1fr); margin-bottom: 10px; }

/* side panel: entities + correlations */
.ob-side { position: absolute; top: calc(var(--tb, 50px) + 10px); left: 14px; bottom: 60px; z-index: 22; width: 318px; display: flex; flex-direction: column; overflow: hidden;
  background: rgba(19, 19, 22, .96); border: 1px solid var(--re-border); border-radius: var(--re-radius); backdrop-filter: blur(10px); box-shadow: 0 16px 40px rgba(0, 0, 0, .45); }
.ob.side-open #node-card { left: 344px; }
.ob.side-open #graph-legend { display: none; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 10px; border-bottom: 1px solid var(--re-line); }
.side-tabs { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 3px; background: var(--re-bg); border: 1px solid var(--re-border); border-radius: 8px; }
.side-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 4px; border: 0; border-radius: 6px; background: none;
  color: var(--re-muted); font: 600 12px var(--re-font); cursor: pointer; }
.side-tabs button.is-active { background: var(--re-surface-2); color: #ececf0; box-shadow: inset 0 -2px 0 var(--re-red); }
.side-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 10px 0; }
.side-pane input[type=search] { width: 100%; padding: 7px 10px; background: var(--re-bg); color: var(--re-text); border: 1px solid var(--re-border); border-radius: 7px; font: 12px var(--re-mono); }
.side-pane input[type=search]:focus { outline: none; border-color: var(--re-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border: 1px solid var(--re-border); border-radius: 99px; background: none;
  color: var(--re-muted); font: 500 11px var(--re-font); cursor: pointer; }
.chip i, .ob .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.chip.is-on { color: #ececf0; border-color: var(--re-muted); background: var(--re-surface-2); }
.side-meta { font: 10.5px var(--re-mono); color: var(--tx-4); }
.side-meta b { color: #ececf0; }
.side-meta .link { padding: 0; border: 0; background: none; color: var(--re-text); font: inherit; text-decoration: underline; cursor: pointer; margin-left: 6px; }
.side-list { flex: 1; min-height: 0; overflow-y: auto; display: grid; gap: 3px; align-content: start; margin: 0 -4px; padding: 0 4px 10px; overscroll-behavior: contain; }
.side-empty { padding: 14px 4px; font-size: 12.5px; color: var(--re-muted); line-height: 1.55; }
.side-empty b { color: #ececf0; }
.side-note { margin: 0 -10px; padding: 8px 12px; border-top: 1px solid var(--re-line); font-size: 11px; color: var(--tx-4); }
.ent-row, .corr-row { width: 100%; display: flex; align-items: center; gap: 9px; padding: 7px 8px; border: 1px solid transparent; border-radius: 7px;
  background: none; color: var(--re-text); text-align: left; cursor: pointer; }
.ent-row:hover, .corr-row:hover { background: var(--re-surface-2); border-color: var(--re-border); }
.ent-row.is-sel { background: var(--re-surface-2); border-color: var(--re-muted); box-shadow: inset 2px 0 0 var(--re-red); }
.ent-main { flex: 1; min-width: 0; display: grid; }
.ent-label { font: 600 12px var(--re-mono); color: #ececf0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ent-sub { font-size: 10.5px; color: var(--tx-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ent-n { flex-shrink: 0; min-width: 20px; padding: 0 5px; border: 1px solid var(--re-border); border-radius: 4px; font: 600 10px/16px var(--re-mono); color: var(--re-muted); text-align: center; }
.ent-n.corr { border-style: dashed; color: #ececf0; }
.corr-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 8px; border-color: var(--re-line); }
.corr-pair { display: grid; gap: 2px; min-width: 0; font: 600 11.5px var(--re-mono); color: #ececf0; }
.corr-pair > span { display: flex; align-items: center; gap: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.corr-score { display: grid; justify-items: end; gap: 4px; font: 11px var(--re-mono); }
.corr-score b { color: #fff; font-size: 13px; }
.w-bar { width: 52px; height: 4px; border-radius: 99px; background: var(--re-surface-3); overflow: hidden; }
.w-bar i { display: block; height: 100%; background: linear-gradient(90deg, #8b8b94, #ededed); }
.corr-why { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px; }
.why { padding: 1px 6px; border: 1px dashed var(--re-border); border-radius: 4px; font-size: 10.5px; color: var(--re-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.why em { font-style: normal; font-family: var(--re-mono); color: var(--re-text); }
.corr-th { display: grid; gap: 4px; font-size: 11.5px; color: var(--re-muted); }
.corr-th span { display: flex; justify-content: space-between; }
.corr-th b { font: 600 12px var(--re-mono); color: #ececf0; }
.corr-th input { width: 100%; accent-color: var(--re-red); height: 22px; }
.ob-export { display: grid; gap: 10px; }
.ob-export__row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ob-export__ta { min-height: 220px; font-size: 11.5px; white-space: pre; overflow: auto; }
.re-modal:has(.ob-export) { width: min(640px, 100%); }
.re-modal { max-height: calc(100dvh - 32px); overflow-y: auto; }

/* dock head extras */
#transform-dock .dock-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 8px; }
#transform-dock .dock-head h3 { grid-column: 1; }
#dock-target { grid-column: 1; }
#dock-all { grid-column: 2; grid-row: 1 / span 2; }
.dock-grab { display: none; }
.ob-menu .ob-narrow { display: none; }
@media (max-width: 640px) { .ob-menu .ob-narrow { display: flex; } .ob .ob-wide { display: none; } }
.t-badge.incl { color: #ececf0; border-color: var(--re-muted); background: var(--re-surface-3); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .re-grid { grid-template-columns: minmax(0, 1fr); }
  .re-chat { grid-template-columns: minmax(0, 1fr); }
  .re-sessions { grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); overflow-x: auto; max-height: none; padding-bottom: 4px; }
}
@media (max-width: 640px) {
  .re-top { flex-wrap: wrap; gap: 8px 12px; padding: 8px 16px; }
  .re-top .re-logo { height: 24px; }
  .re-top__me { margin-left: auto; }
  .re-top__me .re-user { display: none; }
  .re-nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .re-nav a { padding: 5px 10px; font-size: 13px; }
  .re-main { padding: 16px; gap: 14px; }
  .re-card { padding: 16px; }
  .re-stat__v { font-size: 20px; }
  .re-msgs { height: 300px; }
  .re-msg { max-width: 92%; }
  .re-key__row { flex-wrap: wrap; }
}


/* Tables become cards on narrow screens: api.js copies each th into its column's td[data-label]. */
@media (max-width: 640px) {
  .re-table-wrap { overflow: visible; margin: 0; }
  .re-table thead { display: none; }
  .re-table, .re-table tbody, .re-table tr, .re-table td { display: block; width: 100%; }
  .re-table tr { padding: 8px 12px; margin-bottom: 8px; border: 1px solid var(--re-border); border-radius: 8px; background: var(--re-bg); }
  .re-table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--re-line); text-align: right; overflow-wrap: anywhere; }
  .re-table td::before { content: attr(data-label); flex-shrink: 0; text-align: left; font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--re-muted); }
  .re-table td:not([data-label])::before, .re-table td[data-label=""]::before { content: none; }
  .re-table td:last-child { border-bottom: 0; }
  .re-table td[colspan] { justify-content: center; text-align: center; }
  .re-table tbody tr:hover td { background: none; }
}

/* ---------- Obsidian Web on phones: full-height graph, compact toolbar, bottom sheets ---------- */
.ob { --sl: max(8px, env(safe-area-inset-left)); --sr: max(8px, env(safe-area-inset-right)); --sb: max(8px, env(safe-area-inset-bottom)); }
@media (min-width: 641px) and (max-width: 1000px) {
  #graph-toolbar { right: 300px; }
  .ob-add input { width: 150px; }
  .ob-side { width: 290px; }
  .ob.side-open #node-card { left: 316px; }
}
@media (max-width: 640px) {
  .re--full .re-top { flex-wrap: nowrap; padding-bottom: 8px; }
  .re--full .re-nav { order: 0; flex-basis: auto; }
  .re--full .re-nav a { padding: 6px 8px; }
  #graph-toolbar { top: 8px; left: var(--sl); right: var(--sr); gap: 6px; flex-wrap: nowrap; flex-direction: column; align-items: stretch; }
  .ob-add { flex: none; }
  .ob-add select { width: 92px; flex-shrink: 0; }
  .ob-add input { flex: 1; width: auto; font-size: 16px; } /* 16px stops iOS zooming on focus */
  .ob-tools { flex-wrap: nowrap; gap: 5px; overflow-x: auto; scrollbar-width: none; }
  .ob-tools::-webkit-scrollbar { display: none; }
  .ob-tools > * { flex-shrink: 0; }
  .ob-tools > .ob-more { margin-left: auto; position: static; }
  .ob-menu { top: 100%; right: 0; left: auto; margin-top: 6px; }
  #graph-legend { display: none; }
  #graph-stats { top: auto; bottom: calc(var(--sb) + 64px); right: var(--sr); gap: 10px; padding: 4px 9px; font-size: 9.5px; }
  .ob.dock-open #graph-stats, #node-card.show ~ #graph-stats { display: none; }
  /* dock: a bottom sheet that shows its head when collapsed */
  #transform-dock { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 56px; border-radius: 14px 14px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom); transition: max-height .22s ease; box-shadow: 0 -12px 34px rgba(0, 0, 0, .5); }
  .ob.dock-open #transform-dock { max-height: min(62%, 460px); }
  #transform-dock .dock-head { position: relative; grid-template-columns: minmax(0, 1fr) auto; padding: 12px var(--sr) 8px var(--sl); min-height: 56px; border-bottom-color: transparent; }
  .ob.dock-open #transform-dock .dock-head { border-bottom-color: var(--re-line); }
  #transform-dock .dock-head h3 { display: none; }
  #dock-target { margin: 0; align-self: center; grid-row: 1 / span 2; font-size: 12px; }
  .dock-grab { display: block; position: absolute; inset: 0 112px 0 0; border: 0; background: none; cursor: pointer; }
  .dock-grab span { position: absolute; top: 5px; left: 50%; width: 36px; height: 4px; margin-left: 18px; border-radius: 99px; background: var(--re-border); }
  #dock-all { position: relative; z-index: 1; }
  #dock-search, #dock-foot { display: none; }
  .ob.dock-open #dock-search { display: block; margin: 8px var(--sr) 4px var(--sl); width: auto; font-size: 16px; }
  .ob.dock-open #dock-foot:not(:empty) { display: flex; }
  #dock-list { padding: 4px calc(var(--sr) - 4px) 10px calc(var(--sl) - 4px); }
  /* node card + side panel: bottom sheets above the dock */
  /* the node card sits on top of the collapsed dock, so the dock head (Expand all, open transforms) stays reachable */
  #node-card { top: auto; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom, 0px)); width: auto; z-index: 21; border-radius: 14px 14px 0 0;
    border-bottom: 1px solid var(--re-line); max-height: 46%; display: none; flex-direction: column; box-shadow: 0 -16px 40px rgba(0, 0, 0, .6); }
  #node-card.show { display: flex; }
  .ob.dock-open #node-card { display: none; }
  #node-card .nc-head { padding: 14px var(--sr) 10px var(--sl); }
  #node-card .nc-body { flex: 1; max-height: none; min-height: 0; padding: 6px var(--sr) 6px var(--sl); }
  #node-card .nc-foot { padding: 10px var(--sr) 4px var(--sl); }
  #node-card .nc-foot .btn { flex: 1; justify-content: center; }
  .ob-side { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: min(72%, 560px); z-index: 30; border-radius: 14px 14px 0 0; border-bottom: 0;
    padding-bottom: var(--sb); box-shadow: 0 -16px 40px rgba(0, 0, 0, .6); }
  .side-head { padding: 10px var(--sr) 8px var(--sl); }
  .side-pane { padding: 10px var(--sr) 0 var(--sl); }
  .side-pane input[type=search] { font-size: 16px; }
  .side-note { margin: 0 calc(-1 * var(--sr)) 0 calc(-1 * var(--sl)); padding: 8px var(--sr) 4px var(--sl); }
  .ob.side-open #node-card { left: 0; }
  .re--full #toasts { left: var(--sl); right: var(--sr); bottom: calc(var(--sb) + 64px); max-width: none; }
  .re--full #toasts .toast { max-width: none; }
}
/* Touch screens: every control at least 44px tall. */
@media (pointer: coarse), (max-width: 640px) {
  .ob .btn, .ob-switch, .ob-add select, .ob-add input, .ob-menu button, .side-tabs button, .chip, .ent-row, .t-item, .side-pane input[type=search], #dock-search,
  .re-btn, .re-input, .re-select, .re-tab, .re-nav a, .re-top__me a { min-height: 44px; }
  .ob .btn.icon { min-width: 44px; font-size: 17px; }
  .ob .btn.sm { min-height: 40px; padding: 4px 12px; font-size: 12px; }
  .nc-close { min-width: 44px; min-height: 44px; margin: -12px -12px -12px 0; font-size: 16px; }
  .re-nav a, .re-top__me a { display: inline-flex; align-items: center; }
  .chip { padding: 4px 12px; font-size: 12px; }
  .corr-th input { height: 36px; }
}
