/* ============================================================================
   Q0RO.NET — base primitives
   Reset, ambient background, typography, glass surfaces, buttons, forms,
   badges, tables, overlays and the shared feedback components. Every value
   comes from tokens.css; page layout lives in app.css.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
h1, h2, h3, h4, p, figure { margin: 0; }
h1, h2, h3, h4 {
  letter-spacing: var(--tracking-tight);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}
a { color: var(--primary); text-decoration: none; }
img, video { display: block; max-width: 100%; }
svg { display: block; }
ul, ol { margin: 0; padding: 0; list-style: none; }
small { font-size: var(--text-xs); }
hr { border: 0; height: 1px; background: var(--divider); margin: var(--space-5) 0; }
::selection { background: var(--accent-line); color: var(--text-primary); }
:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ─────────────────────────────────────────────────────────────── icons & text */

.ti {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
}
.icon .ti, .ic .ti { width: 18px; height: 18px; }
.ic.sm .ti { width: 14px; height: 14px; }
.nav .ti, .sfoot .ti { width: 19px; height: 19px; }
.logo .ti { width: 18px; height: 18px; }
button .ti { width: 16px; height: 16px; }
.pill .ti, .badge .ti { width: 12px; height: 12px; }

.mu, small { color: var(--text-muted); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eyebrow {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgb(var(--text-rgb) / 0.14);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgb(var(--text-rgb) / 0.24); background-clip: content-box; }

/* ─────────────────────────────────────────────────────────────── background */

.app-background {
  position: fixed;
  inset: 0;
  z-index: var(--z-background, 0);
  overflow: hidden;
  pointer-events: none;
  background: var(--bg-base, var(--background));
}
.app-background > div { position: absolute; inset: 0; }
.bg-base {
  background:
    radial-gradient(110% 80% at 78% -8%, rgb(var(--surface-rgb) / 0.5), transparent 58%),
    radial-gradient(90% 70% at 0% 100%, rgb(var(--surface-rgb) / 0.28), transparent 55%),
    var(--bg-base, var(--background));
}
.bg-image {
  inset: -3%;
  background-image: url("../aurora.jpg");
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  filter: blur(2px) brightness(0.92) saturate(1.08) hue-rotate(var(--bg-hue, 0deg));
  transform: scale(1.03);
  opacity: var(--scene-image-alpha, 0.9);
  transition: opacity var(--duration-slow) var(--ease);
}
.bg-aurora i {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.5;
  will-change: transform;
}
.bg-aurora i:nth-child(1) {
  width: 58vw; height: 58vw; left: -12vw; top: -18vw;
  background: radial-gradient(circle, rgb(var(--surface-rgb) / 0.95), transparent 66%);
  animation: aurora-a 28s var(--ease-in-out) infinite alternate;
}
.bg-aurora i:nth-child(2) {
  width: 48vw; height: 48vw; right: -8vw; top: 8vh;
  background: radial-gradient(circle, var(--accent-glow), transparent 68%);
  animation: aurora-b 34s var(--ease-in-out) infinite alternate;
}
.bg-aurora i:nth-child(3) {
  width: 42vw; height: 42vw; left: 28vw; bottom: -16vw;
  background: radial-gradient(circle, rgb(var(--surface-elevated-rgb) / 0.8), transparent 70%);
  animation: aurora-c 30s var(--ease-in-out) infinite alternate;
}
.bg-aurora { opacity: 0.6; }
.bg-grain {
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}
.bg-overlay {
  background:
    linear-gradient(180deg,
      rgb(var(--bg-overlay-rgb, var(--background-rgb)) / 0.78) 0%,
      rgb(var(--bg-overlay-rgb, var(--background-rgb)) / 0.56) 18%,
      rgb(var(--bg-overlay-rgb, var(--background-rgb)) / 0.48) 38%,
      rgb(var(--bg-overlay-rgb, var(--background-rgb)) / 0.6) 66%,
      rgb(var(--bg-overlay-rgb, var(--background-rgb)) / 0.86) 100%),
    radial-gradient(90% 55% at 50% 42%, var(--bg-glow), transparent 78%);
}
@keyframes aurora-a { from { transform: translate3d(0, 0, 0) scale(1); } to { transform: translate3d(8vw, 6vh, 0) scale(1.12); } }
@keyframes aurora-b { from { transform: translate3d(0, 0, 0) scale(1.05); } to { transform: translate3d(-7vw, 10vh, 0) scale(0.94); } }
@keyframes aurora-c { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(-10vw, -6vh, 0); } }

/* ─────────────────────────────────────────────────────────────── surfaces */

.glass,
.card,
.stat,
.topo,
.info,
.ev,
.fp,
.dc,
#bellp,
#drawer,
#auth .card,
dialog,
.command-palette {
  background: var(--panel-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-highlight),
    inset 0 0 0 1px var(--glass-inner-line, transparent),
    inset 0 -28px 44px -34px var(--glass-inner-glow, transparent);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
}
/* nested surfaces must not blur again: the page already sits on glass */
.card .card,
.card .info,
.card .ev,
.card .fp,
.card .dc,
.pop .card {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.glass { position: relative; }
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--glass-sheen);
  pointer-events: none;
}
.card { padding: var(--space-5); }
.card > h2 { margin: 0 0 4px; font-size: var(--text-md); }
.card > h2 small { font-size: var(--text-sm); font-weight: var(--weight-regular); color: var(--text-muted); margin-left: 6px; }
.card > small {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.6;
  margin-bottom: var(--space-3);
}
.card > small:last-child { margin-bottom: 0; }
.card > small b, .card > small i { color: var(--text-secondary); font-style: normal; }
.sunken {
  background: var(--sunken-bg);
  border: 1px solid var(--divider);
  border-radius: var(--radius-md);
}
.divider-h { height: 1px; background: var(--divider); margin: var(--space-4) 0; }

/* ─────────────────────────────────────────────────────────────── buttons */

button {
  font: inherit;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease),
    color var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease),
    box-shadow var(--duration-fast) var(--ease);
}
@media (hover: hover) {
  button:hover { background: var(--control-bg-hover); border-color: var(--border-strong); color: var(--text-primary); }
}
button:active { transform: scale(0.97); background: var(--active-bg); }
button:disabled, button:disabled:hover { opacity: var(--disabled-opacity); cursor: not-allowed; transform: none; }
button.pri {
  background: var(--btn-primary-bg);
  border-color: transparent;
  color: var(--btn-primary-contrast);
  font-weight: 650;
  box-shadow: var(--btn-primary-shadow);
}
@media (hover: hover) {
  button.pri:hover { background: var(--btn-primary-bg-hover); border-color: transparent; color: var(--btn-primary-contrast); filter: brightness(1.02); }
}
button.pri:active { background: var(--btn-primary-bg); filter: brightness(0.96); }
button.sm { min-height: 30px; padding: 0 10px; font-size: var(--text-xs); border-radius: var(--radius-xs); }

/* icon-only controls: the topology toolbar, the bell, panel close */
#bell, #zo, #zi, #plZo, #plZi, #plFit, #dclose, #plDel, .icon-btn {
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
}
@media (hover: hover) {
  #bell:hover, #zo:hover, #zi:hover, #zr:hover, #zf:hover, #plZo:hover, #plZi:hover,
  #plFit:hover, #dclose:hover, #plDel:hover, .icon-btn:hover {
    background: var(--control-bg-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
  }
}
#bell { position: relative; }
#bell.on { color: var(--primary); border-color: var(--accent-line); background: var(--accent-soft); }

/* ─────────────────────────────────────────────────────────────── forms */

label {
  display: block;
  margin: 0 0 7px 2px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
  color: var(--text-secondary);
}
input, select, textarea {
  width: 100%;
  min-height: 42px;
  margin: 4px 0 12px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), background var(--duration-fast);
}
textarea { min-height: 112px; padding: 11px 13px; line-height: 1.5; resize: vertical; font-family: var(--font-mono); font-size: 12px; }
select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238DA398' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 15px;
  cursor: pointer;
}
select option { background-color: var(--surface-elevated); color: var(--text-primary); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-faint);
  background: var(--input-bg-focus);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
  opacity: 1;
}
/* Boolean controls are switches, matching the Q0RO appearance settings. The
   markup still writes style="width:auto", so min-width carries the real size. */
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  min-width: 44px;
  height: 24px;
  min-height: 24px;
  flex: none;
  margin: 0;
  padding: 0;
  position: relative;
  border-radius: var(--radius-pill);
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  cursor: pointer;
  transition: background var(--duration-base) var(--ease), border-color var(--duration-base) var(--ease), box-shadow var(--duration-fast);
}
input[type="checkbox"]::after, input[type="radio"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform var(--duration-base) var(--ease), background var(--duration-base) var(--ease);
}
input[type="checkbox"]:checked, input[type="radio"]:checked {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
input[type="checkbox"]:checked::after, input[type="radio"]:checked::after {
  transform: translateX(20px);
  background: var(--primary);
}
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-faint);
}
input[type="radio"] { border-radius: 50%; }
input[type="radio"]::after { border-radius: 50%; }
input[type="file"] { padding: 8px 10px; }
label:has(> input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  margin: 8px 0;
}

/* ─────────────────────────────────────────────────────────────── chips, pills, badges */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0.01em;
  color: var(--c, var(--text-secondary));
  background: color-mix(in srgb, var(--c, var(--text-muted)) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c, var(--text-muted)) 26%, transparent);
  white-space: nowrap;
}
.pill .dot { width: 5px; height: 5px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--accent-faint);
  font-size: 10px;
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge.ok { color: var(--success); border-color: var(--success-line); background: var(--success-soft); }
.badge.warn { color: var(--warning); border-color: var(--warning-line); background: var(--warning-soft); }
.badge.bad { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); }
.badge.ac { color: var(--primary); border-color: var(--accent-line); background: var(--accent-soft); }

.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c, var(--text-muted));
  flex: none;
}
.ok { --c: var(--success); }
.warn { --c: var(--warning); }
.off { --c: var(--danger); }
.na { --c: var(--text-muted); }
.dot.pulse { animation: dot-pulse 2.4s ease-out infinite; }
@keyframes dot-pulse {
  0% { box-shadow: 0 0 0 0 var(--success-line); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.av {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: var(--avatar-text);
  font-size: 11px;
  font-weight: var(--weight-bold);
  letter-spacing: 0;
}

.ic {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  background: var(--accent-faint);
  color: var(--primary);
  font-style: normal;
}
.ic.sm { width: 26px; height: 26px; }
.ic.big { width: 40px; height: 40px; border-radius: 12px; }
.ic.big .ti { width: 21px; height: 21px; }
.ic.ok { background: var(--success-soft); color: var(--success); }
.ic.warn { background: var(--warning-soft); color: var(--warning); }
.ic.off { background: var(--danger-soft); color: var(--danger); }
.ic.na { background: var(--neutral-soft); color: var(--text-muted); }

/* ─────────────────────────────────────────────────────────────── tables */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--divider);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
  font-size: var(--text-sm);
  vertical-align: middle;
}
tbody tr { transition: background var(--duration-fast); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--accent-faint); }

/* ─────────────────────────────────────────────────────────────── states */

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent-line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────────────────────── toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 22px);
  z-index: var(--z-toast, 100);
  transform: translateX(-50%);
  max-width: min(92vw, 560px);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--accent-line);
  background: rgb(var(--surface-rgb) / 0.96);
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: 1.45;
  text-align: center;
  box-shadow: var(--shadow-lg), inset 0 1px 0 var(--glass-highlight);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  animation: toast-in 240ms var(--ease) both;
}
#toast[hidden] { display: none; }
@keyframes toast-in { from { transform: translate(-50%, 10px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ─────────────────────────────────────────────────────────────── dialogs */

dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--text-primary);
  background: var(--glass-gradient);
  border: 1px solid var(--glass-border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-highlight),
    inset 0 0 0 1px var(--glass-inner-line, transparent),
    inset 0 -28px 44px -34px var(--glass-inner-glow, transparent);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(150%);
  backdrop-filter: blur(var(--glass-blur)) saturate(150%);
}
dialog[open] { animation: sheet-in 220ms var(--ease); }
dialog::backdrop {
  background: var(--modal-backdrop);
  -webkit-backdrop-filter: blur(7px) saturate(120%);
  backdrop-filter: blur(7px) saturate(120%);
}
dialog h2 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-4);
  letter-spacing: -0.02em;
}
dialog label { margin-top: var(--space-3); }
dialog .row { margin-top: var(--space-4); }
dialog .row button { min-width: 96px; }
dialog input, dialog select, dialog textarea { margin-bottom: var(--space-2); }
dialog > .row:last-child { justify-content: flex-end; gap: 8px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px) scale(0.985); } }

/* dialog forms generated by the app: keep the rhythm of the Q0RO sheets */
#acct h2, #gmCfg h2, #camCfg h2 { font-size: var(--text-lg); }

/* ─────────────────────────────────────────────────────────────── theme swap
   The theme picker uses the View Transitions API when the browser supports it,
   so a palette change crossfades instead of flashing. Browsers without it and
   reduced-motion users get the same instant, correct swap. */

::view-transition-old(root) { animation: theme-swap-out 180ms var(--ease) both; }
::view-transition-new(root) { animation: theme-swap-in 260ms var(--ease) both; }
@keyframes theme-swap-out { to { opacity: 0; } }
@keyframes theme-swap-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
}

/* OLED: one cool reflection over real black. The scene is desaturated so the
   glass, the video and the status colours are the only colour in the room. */
[data-theme="dark-oled"] .bg-image {
  filter: blur(2px) grayscale(1) brightness(0.72) contrast(1.05);
  opacity: 0.04;
}
[data-theme="dark-oled"] .bg-aurora { opacity: 0.38; }
[data-theme="dark-oled"] .bg-grain { opacity: 0.02; }

/* ---- Q0RO performance guard -------------------------------------------- */
/* Decorative animation runs only while the page is visible and focused. */
html.q0ro-idle .bg-aurora i,
html.q0ro-idle .dot.pulse,
html.q0ro-idle #wires path.hl { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
  .bg-aurora i, .dot.pulse, #wires path.hl { animation: none !important; }
}
