/* Gardvord UI.
   No external fonts, no CDN, no inline styles - the CSP forbids all three,
   and the hub has to work with the internet unplugged. */

:root {
  color-scheme: light dark;

  --bg: #0e1014;
  --bg-raised: #161a21;
  --bg-sunken: #0a0c10;
  --border: #242a34;
  --border-strong: #333b47;

  --text: #e8ecf2;
  --text-dim: #98a2b3;
  --text-faint: #667085;

  --accent: #f5a524;
  --accent-soft: rgba(245, 165, 36, 0.14);
  --ok: #3ecf8e;
  --warn: #f5a524;
  --bad: #f4535f;
  --info: #5b9dff;

  --radius: 14px;
  --radius-sm: 9px;
  --gap: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-raised: #ffffff;
    --bg-sunken: #eceef2;
    --border: #e2e5ea;
    --border-strong: #cfd4dc;
    --text: #101828;
    --text-dim: #475467;
    --text-faint: #98a2b3;
    --accent: #b45309;
    --accent-soft: rgba(180, 83, 9, 0.1);
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px -12px rgba(16, 24, 40, 0.18);
  }
}

* { box-sizing: border-box; }

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

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

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

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand small { color: var(--text-faint); font-weight: 450; font-size: 12px; }

.nav { display: flex; gap: 2px; margin-left: auto; }
.nav button {
  background: none; border: 0; cursor: pointer;
  padding: 7px 13px; border-radius: 999px;
  color: var(--text-dim); font-weight: 500;
}
.nav button:hover { color: var(--text); background: var(--bg-raised); }
.nav button[aria-current="page"] { color: var(--text); background: var(--accent-soft); }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }

h1 { font-size: 26px; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 17px; letter-spacing: -0.01em; margin: 28px 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-dim); font-weight: 600; }
p.lead { color: var(--text-dim); margin: 0 0 20px; }

/* ---------- cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.tile {
  display: flex; flex-direction: column; gap: 10px;
  cursor: pointer; text-align: left; width: 100%;
  transition: border-color .15s, transform .12s;
}
.tile:hover { border-color: var(--border-strong); }
.tile:active { transform: scale(.985); }
.tile.on { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: linear-gradient(var(--accent-soft), transparent 60%), var(--bg-raised); }
.tile.problem { border-color: color-mix(in srgb, var(--bad) 50%, var(--border)); }
.tile.unavailable { opacity: .5; }

.tile-head { display: flex; align-items: flex-start; gap: 10px; }
.tile-name { font-weight: 570; line-height: 1.25; }
.tile-sub { font-size: 12px; color: var(--text-faint); }
.tile-value { font-size: 25px; font-weight: 600; letter-spacing: -0.02em; margin-top: auto; }
.tile-value span { font-size: 14px; color: var(--text-dim); font-weight: 500; margin-left: 2px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; margin-top: 6px; }
.dot.on { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }

/* ---------- controls ---------- */

.btn {
  border: 1px solid var(--border-strong); background: var(--bg-raised);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 8px 14px; cursor: pointer; font-weight: 520;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { border-color: var(--text-faint); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #17130a; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { border-color: color-mix(in srgb, var(--bad) 50%, var(--border)); color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }

input[type="text"], input[type="password"], input[type="number"], input[type="email"], select, textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; font-family: var(--mono); font-size: 13px; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
label.field small { display: block; color: var(--text-faint); font-size: 12px; margin-top: 4px; }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-sunken); color: var(--text-dim); border: 1px solid var(--border);
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.pill.cloud { color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, transparent); }

/* ---------- assistant ---------- */

.chat { display: flex; flex-direction: column; height: calc(100vh - 190px); min-height: 380px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 16px; }
.msg { max-width: 74%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #17130a; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--bg-raised); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.sys { align-self: center; font-size: 12.5px; color: var(--text-faint); background: none; }
.msg-actions { margin-top: 9px; display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; }
.msg-actions .line { display: flex; gap: 7px; align-items: center; color: var(--text-dim); }

.chat-input { display: flex; gap: 9px; padding-top: 12px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; }

.confirm-box {
  margin-top: 10px; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border));
  background: color-mix(in srgb, var(--warn) 8%, transparent);
}

/* ---------- tables & misc ---------- */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 12px; color: var(--text-faint); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

.center-page { max-width: 400px; margin: min(11vh, 90px) auto; }
.logo { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; margin-bottom: 4px; }

.error { color: var(--bad); font-size: 13.5px; margin: 10px 0; }
.hint { color: var(--text-faint); font-size: 12.5px; }
.empty { color: var(--text-faint); text-align: center; padding: 40px 20px; }

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 9px 18px; box-shadow: var(--shadow); font-size: 13.5px;
}
.toast.bad { border-color: var(--bad); color: var(--bad); }
.toast.ok { border-color: var(--ok); }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.sheet {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; width: min(520px, 100%);
  max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow);
}

.offline-banner {
  background: color-mix(in srgb, var(--bad) 14%, var(--bg-raised));
  border-bottom: 1px solid color-mix(in srgb, var(--bad) 40%, var(--border));
  padding: 7px 20px; font-size: 13px; text-align: center; color: var(--text);
}

/* ---------- utilities ----------
   The CSP forbids style attributes, so every one-off spacing tweak the JS
   needs has to exist as a class. Small price for `style-src 'self'`. */

/* !important on purpose: this has to beat element+class selectors such as
   `label.field { display: block }`, which are more specific than a bare
   utility class and otherwise leave "hidden" elements visible. */
.hidden { display: none !important; }
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-9 { margin-top: 9px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mt-18 { margin-top: 18px; }
.mb-10 { margin-bottom: 10px; }
.mb-12 { margin-bottom: 12px; }
.mb-14 { margin-bottom: 14px; }
.my-10 { margin: 10px 0; }
.sp-12 { height: 12px; }
.sp-16 { height: 16px; }
.p-9 { padding: 9px; }
.w-full { width: 100%; }
.grow { min-width: 220px; flex: 1; }
.bold { font-weight: 600; }
.semi { font-weight: 570; }
.pre { white-space: pre-wrap; }
.tall { min-height: 230px; }
.selectable { word-break: break-all; user-select: all; }
.scrollbox { max-height: 420px; overflow: auto; }
.rule { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.mark-ok { color: var(--ok); }
.mark-bad { color: var(--bad); }

/* ---------- joystick ----------
   Position of the knob comes from CSS custom properties set in JS - a
   `style` attribute would be blocked by the CSP, `style.setProperty` on a
   custom property is not. */
.stick-pad {
  width: 180px; height: 180px; border-radius: 50%; flex: none;
  background: radial-gradient(circle, var(--bg-sunken) 0 30%, transparent 31%), var(--bg-raised);
  border: 2px solid var(--border-strong); position: relative; touch-action: none;
  cursor: grab; user-select: none;
}
.stick-pad:active { cursor: grabbing; border-color: var(--accent); }
.stick-pad::before, .stick-pad::after {
  content: ""; position: absolute; background: var(--border); left: 50%; top: 8%;
  width: 1px; height: 84%; transform: translateX(-50%);
}
.stick-pad::after { left: 8%; top: 50%; width: 84%; height: 1px; transform: translateY(-50%); }
.stick-knob {
  --x: 0%; --y: 0%;
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.4);
  transform: translate(calc(-50% + var(--x) * 1.8), calc(-50% + var(--y) * 1.8));
  transition: transform .05s linear; pointer-events: none;
}
.chips { gap: 6px; flex-wrap: wrap; }

/* Inline inputs inside a row (banner, room list) must not stretch to 100%. */
input.inline { width: auto; min-width: 120px; flex: 1; max-width: 320px; }
.vault-banner { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.pill-x { border: 0; background: none; color: var(--text-faint); cursor: pointer; padding: 0 0 0 4px; font-size: 14px; line-height: 1; }
.pill-x:hover { color: var(--bad); }
details summary { cursor: pointer; margin: 8px 0; }

@media (max-width: 620px) {
  main { padding: 16px 12px 72px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .nav button { padding: 7px 10px; font-size: 13.5px; }
  .msg { max-width: 88%; }
}
