:root {
  --bg:        #0e1013;
  --panel:     #161a1f;
  --panel-2:   #1c2128;
  --line:      #272d36;
  --text:      #e6e9ee;
  --muted:     #949cab;
  --accent:    #6f9dff;
  --accent-dk: #4d7ee0;
  --good:      #4fb477;
  --warn:      #d9a441;
  --bad:       #d96a6a;
  --radius:    9px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: .1px; }

button { font-family: inherit; font-size: 13px; cursor: pointer; border-radius: 7px; border: 1px solid transparent; }
button:disabled { opacity: .5; cursor: default; }

.primary { background: var(--accent-dk); color: #fff; border-color: var(--accent-dk); padding: 8px 14px; }
.primary:hover:not(:disabled) { background: var(--accent); }
.ghost { background: transparent; color: var(--muted); border-color: var(--line); padding: 7px 12px; }
.ghost:hover { color: var(--text); border-color: #3a424e; }
.small { padding: 5px 10px; font-size: 12px; }

input, select {
  font-family: inherit; font-size: 13px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent-dk); }

.form-error { color: var(--bad); font-size: 13px; margin: 6px 0 0; }

/* ------------------------------------------------------------ login page */

.auth-page { display: grid; place-items: center; padding: 24px; }

.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 34px 30px 26px;
}
.auth-mark { color: var(--accent); margin-bottom: 14px; }
.auth-card h1 { margin: 0 0 8px; font-size: 24px; }
.auth-sub { color: var(--muted); margin: 0 0 24px; line-height: 1.55; font-size: 13px; }
.auth-card label { display: block; margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.auth-card input { margin-bottom: 16px; }
.auth-card button[type=submit] { width: 100%; margin-top: 8px; background: var(--accent-dk); color: #fff; padding: 11px; }
.auth-card button[type=submit]:hover:not(:disabled) { background: var(--accent); }
.auth-foot { color: var(--muted); font-size: 12px; text-align: center; margin: 20px 0 0; }
.auth-foot a { color: var(--accent); text-decoration: none; }
.auth-foot a:hover { text-decoration: underline; }

.form-ok { color: var(--good); font-size: 13px; margin: 6px 0 0; line-height: 1.5; }

.notice {
  font-size: 13px; line-height: 1.5; border-radius: var(--radius);
  padding: 10px 12px; margin: 0 0 20px; border: 1px solid var(--line);
}
.notice.good { color: var(--good); border-color: rgba(79,180,119,.4); background: rgba(79,180,119,.09); }
.notice.bad  { color: var(--bad);  border-color: rgba(217,106,106,.4); background: rgba(217,106,106,.09); }

.tabs { display: flex; gap: 6px; margin: 0 0 22px; background: var(--panel-2);
        border: 1px solid var(--line); border-radius: 9px; padding: 4px; }
.tabs .tab {
  flex: 1; background: transparent; color: var(--muted);
  border: none; padding: 8px 10px; border-radius: 6px; font-size: 13px;
}
.tabs .tab.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.tabs .tab:hover:not(.active) { color: var(--text); }

/* ---------------------------------------------------------------- topbar */

.topbar {
  height: 50px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 16px; }
.brand svg { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 12px; }

.engine-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 4px 11px;
}
.engine-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.engine-pill.up .dot { background: var(--good); }
.engine-pill.down .dot { background: var(--bad); }

/* ---------------------------------------------------------------- layout */

.layout { display: grid; grid-template-columns: 268px 1fr; height: calc(100% - 50px); }

/* Laptop view pins the width to 1280, which on a tall phone would otherwise
   make the page about 2700px high. Capping it keeps laptop proportions. */
html.desktop-mode .layout { height: min(calc(100% - 50px), 820px); }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.side-head h2 { margin: 0; font-size: 14px; }

.newtab-form { padding: 0 14px 12px; }
.newtab-form .row { display: flex; gap: 8px; margin-top: 8px; }

.tablist { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; min-height: 0; }
.tablist li {
  border-radius: var(--radius); padding: 9px 10px; margin-bottom: 4px;
  cursor: pointer; border: 1px solid transparent;
}
.tablist li:hover { background: var(--panel-2); }
.tablist li.active { background: var(--panel-2); border-color: var(--accent-dk); }
.tab-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-url { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tab-meta { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.badge {
  font-size: 10px; letter-spacing: .3px; text-transform: uppercase;
  border-radius: 4px; padding: 2px 6px; border: 1px solid var(--line); color: var(--muted);
}
.badge.on { color: var(--good); border-color: rgba(79,180,119,.4); background: rgba(79,180,119,.1); }
.tab-close { margin-left: auto; color: var(--muted); background: none; border: none; font-size: 15px; line-height: 1; padding: 0 2px; }
.tab-close:hover { color: var(--bad); }

.side-foot { border-top: 1px solid var(--line); padding: 12px 14px; max-height: 34%; overflow-y: auto; }
.side-foot h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-family: var(--sans); text-transform: uppercase; letter-spacing: .5px; }
.events { list-style: none; margin: 0; padding: 0; font-size: 11.5px; color: var(--muted); }
.events li { padding: 3px 0; line-height: 1.45; }
.events time { color: #6d7484; margin-right: 6px; font-family: var(--mono); font-size: 10.5px; }

/* ----------------------------------------------------------------- stage */

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.icon {
  width: 30px; height: 30px; display: grid; place-items: center;
  background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 14px;
}
.icon:hover:not(:disabled) { color: var(--text); border-color: #3a424e; }
.urlbar { flex: 1; }
.urlbar input { border-radius: 16px; padding: 7px 14px; font-size: 12.5px; font-family: var(--mono); }

.screen-wrap {
  flex: 1; min-height: 0; position: relative;
  background: #07080a; outline: none; overflow: hidden;
}
.screen-wrap:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-dk); }

/* Absolutely positioned so its height is definite. A percentage max-height on
   the image cannot resolve against a content-sized parent, which let the frame
   overflow and cover the panel below it. */
.screen-stage {
  position: absolute; inset: 10px;
  display: flex; align-items: center; justify-content: center;
}
#screen {
  max-width: 100%; max-height: 100%;
  border-radius: 6px; display: none; cursor: default;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); user-select: none;
}
#screen.live { display: block; }

/* Invisible, but a genuine textarea: that is what makes a phone raise its
   keyboard. It sits over the page and receives the taps, clicks and wheel. */
.kb-catcher {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; margin: 0;
  background: transparent; color: transparent; caret-color: transparent;
  resize: none; overflow: hidden; z-index: 3;
  font-size: 16px;             /* under 16px makes iOS zoom in on focus */
  cursor: default;
  touch-action: none;          /* the page below gets the gesture, not the browser */
  -webkit-user-select: none; user-select: none;
}
.kb-catcher:focus { outline: none; }
.screen-wrap:has(.kb-catcher:focus) { box-shadow: inset 0 0 0 2px var(--accent-dk); }

.screen-empty {
  position: absolute; inset: 0; margin: auto; height: fit-content;
  z-index: 4; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; max-width: 400px; color: var(--muted); padding: 0 24px;
}
.screen-empty h2 { font-size: 18px; margin: 0 0 8px; color: var(--text); }
.screen-empty p { margin: 0; line-height: 1.6; font-size: 13px; }

.screen-note {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(20,24,30,.94); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 18px; font-size: 12px; color: var(--muted);
}

/* ------------------------------------------------------------- keepalive */

.keepalive { border-top: 1px solid var(--line); background: var(--panel); padding: 14px 16px 16px; }
.ka-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ka-status { font-size: 12px; color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 21px; border-radius: 12px; background: var(--panel-2);
  border: 1px solid var(--line); position: relative; transition: background .15s, border-color .15s;
}
.switch .knob {
  position: absolute; top: 2px; left: 2px; width: 15px; height: 15px;
  border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s;
}
.switch input:checked + .track { background: rgba(79,180,119,.25); border-color: var(--good); }
.switch input:checked + .track .knob { transform: translateX(17px); background: var(--good); }
.switch input:focus-visible + .track { border-color: var(--accent); }
.switch-label { font-size: 13px; }

.ka-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.hint { font-size: 11.5px; color: #767e8d; line-height: 1.5; margin: 7px 0 0; }

/* ----------------------------------------------------------------- modal */

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 24px; z-index: 40; }
/* A class selector outranks the browser default for [hidden], so say it here. */
[hidden] { display: none !important; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px; width: 100%; max-width: 620px; max-height: 86vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card h3 { font-size: 13px; color: var(--muted); font-family: var(--sans); text-transform: uppercase; letter-spacing: .5px; margin: 22px 0 10px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 18px; font-family: var(--serif); }
.stat span { font-size: 11px; color: var(--muted); }

.users { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.users td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users td:last-child { text-align: right; white-space: nowrap; }

.adduser { display: grid; grid-template-columns: 1.6fr 1.6fr .6fr .9fr auto; gap: 8px; align-items: center; }

.sidebar-toggle { display: none; }
.sidebar-scrim { display: none; }

/* Every narrow-screen rule is scoped to :not(.desktop-mode), so the Laptop view
   button can opt out of the whole phone layout rather than fighting it. */
@media (max-width: 900px) {
  html:not(.desktop-mode) .layout { grid-template-columns: 1fr; }

  /* The sidebar holds the only way to open or switch a tab, so it slides in
     rather than disappearing. */
  html:not(.desktop-mode) .sidebar {
    position: fixed; top: 50px; bottom: 0; left: 0; width: 282px; z-index: 30;
    transform: translateX(-100%); transition: transform .18s ease;
  }
  html:not(.desktop-mode) .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.55); }

  html:not(.desktop-mode) .sidebar-scrim.open {
    display: block; position: fixed; inset: 50px 0 0 0;
    background: rgba(0,0,0,.5); z-index: 29;
  }

  html:not(.desktop-mode) .sidebar-toggle { display: inline-block; }
  html:not(.desktop-mode) .who,
  html:not(.desktop-mode) .engine-pill { display: none; }

  html:not(.desktop-mode) .ka-grid { grid-template-columns: 1fr; }
  html:not(.desktop-mode) .adduser { grid-template-columns: 1fr 1fr; }
}
