/* Matrix Browser — Matrix brand look, same tokens as Matrix Chat (docs/design.md). */
:root {
  --bg: #0a0a0a;
  --panel: #171717;
  --panel-2: #242424;
  --line: #3d3d3d;
  --text: #f5f5f5;
  --muted: #b0b0b0;
  --accent: #ffffff;
  --accent-2: #d9d9d9;
  --top: #000000;
  --ok: #34c77b;
  --warn: #f5a524;
  --danger: #ef3d5a;
  --radius: 10px;
  --display: "Archivo", "Inter", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--text); text-underline-offset: 3px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); }

.btn { background: var(--accent); color: #000; border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--accent-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn.danger:hover { background: rgba(239, 61, 90, .12); }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; }
input[type=text], input[type=email], select { width: 100%; background: var(--panel-2); border: 1px solid #555; border-radius: 8px; padding: 10px 12px; }
input::placeholder { color: #8a8a8a; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Shell */
.shell { display: grid; grid-template-columns: 84px 1fr; grid-template-rows: 56px 1fr; height: 100vh; height: 100dvh; }
.topbar { grid-column: 1 / -1; background: var(--top); border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 16px; gap: 12px; }
.topbar .brand { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: -.2px; text-decoration: none; font-size: 17px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }
.conn { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn.ok i { background: var(--ok); }
.conn.down i { background: var(--danger); }
.nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 8px 6px; gap: 4px; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 12px; }
.nav a.active { background: var(--panel-2); color: var(--text); }
.nav svg { width: 24px; height: 24px; }
.main { overflow: auto; min-width: 0; }
.page { padding: 20px; max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 16px; flex-wrap: wrap; }
.page h1 { font: 800 24px/1.1 var(--display); text-transform: uppercase; letter-spacing: -.3px; margin: 0; }
.page-head .counts { color: var(--muted); font-size: 13px; }

/* Profile cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.thumb { position: relative; aspect-ratio: 16 / 10; background: #000; display: block; border: 0; padding: 0; width: 100%; cursor: pointer; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.thumb:hover::after { content: "Open"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); font-weight: 600; }
.card .info { display: flex; align-items: center; gap: 10px; padding: 12px 14px 6px; }
.card .title { font-size: 16px; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--muted); font-size: 12px; padding: 0 14px; min-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px 14px; }
.card .foot .grow { flex: 1; }
.card.add { align-items: center; justify-content: center; min-height: 240px; border-style: dashed; color: var(--text); font-weight: 600; gap: 6px; background: transparent; cursor: pointer; }
.card.add:hover { background: var(--panel); }
.card.add .plus { font-size: 32px; color: var(--muted); line-height: 1; }
.pill { font-size: 12px; border-radius: 999px; padding: 3px 9px; background: var(--panel-2); color: var(--muted); white-space: nowrap; flex: none; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.off { color: var(--danger); }
.empty { color: var(--muted); padding: 40px 16px; text-align: center; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 50; padding: 24px; }
.modal { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.modal h2 { margin: 0; font: 800 20px/1.1 var(--display); text-transform: uppercase; letter-spacing: -.3px; }
.modal label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.modal p { margin: 0; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }

/* Full view */
.viewer { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.vbar { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--top); border-bottom: 1px solid var(--line); flex-wrap: wrap;
  padding-top: max(6px, env(safe-area-inset-top)); }
.vtitle { display: flex; align-items: center; gap: 8px; min-width: 0; }
.vtitle b { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.vnav { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.urlform { flex: 1; min-width: 120px; }
.vnav input, .vnav select { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.vnav select { width: auto; max-width: 200px; }
.vctl { display: flex; align-items: center; gap: 8px; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; outline: none; touch-action: none; background: #000; }
.stage img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; image-rendering: auto; }
.stage.watching img { cursor: not-allowed; }
.stage-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; text-align: center; padding: 20px; }
.kbd-input { position: fixed; left: -1000px; bottom: 0; width: 10px; height: 10px; opacity: 0; font-size: 16px; }
#kbd { display: none; }

/* Badge on the Devices nav item (pairing requests waiting) */
.nav a { position: relative; }
.badge { position: absolute; top: 6px; right: 14px; min-width: 18px; height: 18px; border-radius: 999px; background: var(--warn); color: #000;
  font: 700 11px/18px "Inter", sans-serif; font-style: normal; text-align: center; padding: 0 5px; }

/* Sign in / waiting screens */
.gate { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.gate-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 12px; }
.gate-card h1 { margin: 0 0 4px; font: 800 26px/1.1 var(--display); text-transform: uppercase; letter-spacing: -.3px; }
.gate-card p { margin: 0; }
.gate-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.gate-card input { width: 100%; background: var(--panel-2); border: 1px solid #555; border-radius: 8px; padding: 10px 12px; font-size: 16px; }
.gate-card .mono { font-family: ui-monospace, Menlo, monospace; color: var(--text); }

/* Visibility checklist */
.checklist { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.modal label.check, .check { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--text); font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.check .grow { flex: 1; }

/* Devices page */
.section-title { font: 800 16px/1.2 var(--display); text-transform: uppercase; letter-spacing: -.2px; margin: 24px 0 10px; }
.devlist { display: grid; gap: 10px; max-width: 900px; }
.dev { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.dev.pending { border-left: 4px solid var(--warn); }
.dev .who2 { flex: 1; min-width: 180px; }
.dev .who2 b { display: block; }
.dev .who2 span { color: var(--muted); font-size: 12px; }
.dev select { width: auto; padding: 6px 10px; font-size: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #555; margin-right: 6px; vertical-align: middle; }
.dot.on { background: var(--ok); }
.card .vis { font-size: 12px; color: var(--muted); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 52px 1fr 60px; }
  .nav { grid-row: 3; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); padding: 4px; background: #000;
    padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .nav a { flex: 1; padding: 6px 2px; }
  .page { padding: 16px; }
  .topbar .who { display: none; }
  input[type=text], input[type=email], select { font-size: 16px; }
  .vtitle b { max-width: 140px; }
  .vnav { order: 3; flex-basis: 100%; }
  .vnav input, .vnav select { font-size: 16px; }
  .urlform { min-width: 0; }
  .vnav select { max-width: 96px; }
  .vnav .icon-btn { width: 32px; }
  .vctl { margin-left: auto; }
  #kbd { display: inline-grid; }
}
@media (hover: none) { #kbd { display: inline-grid; } .thumb:hover::after { display: none; } }
.page-head .grow { flex: 1; }

/* Settings: add an approved email */
.addrow { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.addrow input { flex: 1 1 180px; min-width: 0; }

/* Sign-in: resend / change-email links */
.gate-links { display: flex; justify-content: center; gap: 18px; margin-top: 14px; }
.linkbtn { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; padding: 4px; }
.linkbtn:hover:not(:disabled) { color: var(--text); text-decoration: underline; }
.linkbtn:disabled { color: #5a5a5a; cursor: default; }
.dev label.dl { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }

/* Recordings player */
.rec-modal { width: min(960px, 96vw); max-height: 92vh; overflow: auto; }
.rec-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.rec-head h2 { margin: 0; }
.rec-stage { position: relative; background: #000; border-radius: 8px; aspect-ratio: 16 / 9; display: grid; place-items: center; overflow: hidden; }
.rec-stage img { width: 100%; height: 100%; object-fit: contain; }
.rec-none { color: var(--muted); font-size: 13px; }
.rec-info { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin: 8px 0 4px; }
.rec-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
#recSlider { width: 100%; }
.rec-ctl { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.rec-ctl select { width: auto; }
.rec-head .grow { flex: 1; }

/* Rec on / off on profile cards */
.recbtn .recdot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); margin-right: 6px; vertical-align: 1px; }
.recbtn.on { color: var(--text); }
.recbtn:not(.on) { color: var(--muted); }
.card .foot { flex-wrap: wrap; row-gap: 6px; }

/* Dialogs taller than the screen scroll (Save stays reachable) */
.modal-back { overflow-y: auto; }
.modal { max-height: calc(100dvh - 48px); overflow-y: auto; }
.check.fixed { opacity: .75; cursor: default; }
#quality { width: auto; padding: 6px 8px; font-size: 13px; }
