/*
 * OBX Tools shared baseline.
 *
 * Injected into every PathRewriter-wrapped tool page (combined_server.py) as
 * the FIRST stylesheet in <head>, so each tool's own CSS loads after it and
 * wins. Every element rule is wrapped in :where() for zero specificity, which
 * means a tool only picks up a property here when it never set that property
 * itself. Inherited text properties (line-height, letter-spacing) are left
 * alone so a tool's own body/container settings keep flowing down. Branding colors come from the tool's own CSS variables when present
 * (--primary, --accent, --brand), with a neutral fallback.
 *
 * The bottom half styles the injected UI (coffee button, loading overlay,
 * demo login hint). Those use #obx-* ids so they never collide with tools.
 */

:where(:root) {
  --obx-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --obx-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --obx-ink: #1f2933;
  --obx-ink-soft: #52606d;
  --obx-line: #d9e2ec;
  --obx-surface: #ffffff;
  --obx-wash: #f5f7fa;
  --obx-brand: var(--primary, var(--brand, var(--accent, #1b4965)));
  --obx-focus: var(--obx-brand);
  --obx-radius: 10px;
  --obx-radius-sm: 8px;
  --obx-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
}

/* ---------- Base ---------- */

:where(html) {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

:where(body) {
  font-family: var(--obx-font);
  color: var(--obx-ink);
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
  overflow-x: hidden;
}

:where(h1, h2, h3, h4) { text-wrap: balance; }
:where(p, li) { text-wrap: pretty; }
:where(a) { text-underline-offset: 2px; }
:where(code, kbd, pre, samp) { font-family: var(--obx-mono); font-size: 0.92em; }
:where(img, video, iframe, svg, canvas) { max-width: 100%; }
:where(img, video) { height: auto; }
:where(hr) { border: 0; border-top: 1px solid var(--obx-line); }

::selection { background: var(--obx-brand); color: #fff; }

/* ---------- Forms ---------- */

:where(button, input, select, textarea) { font-family: inherit; box-sizing: border-box; }

:where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"], [type="submit"], [type="button"], [type="reset"], [type="image"]), select, textarea) {
  padding: 0.5em 0.65em;
  border: 1px solid var(--obx-line);
  border-radius: var(--obx-radius-sm);
  background-color: var(--obx-surface);
  line-height: 1.3;
  max-width: 100%;
}
:where(textarea) { resize: vertical; }
:where(input[type="checkbox"], input[type="radio"]) { accent-color: var(--obx-brand); }

/* iOS zooms the page when an input is under 16px. Keep this one forceful. */
@media (max-width: 640px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  select, textarea { font-size: 16px !important; }
}

:where(button, [type="submit"], [type="button"], [type="reset"], .btn) {
  cursor: pointer;
  border-radius: var(--obx-radius-sm);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
:where(button:disabled, [type="submit"]:disabled, .btn[disabled]) { cursor: not-allowed; opacity: 0.55; }
:where(button, [type="submit"], [type="button"], .btn):active:not(:disabled) { transform: translateY(1px); }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--obx-focus);
  outline-offset: 2px;
}

/* ---------- Tables ---------- */

:where(table) { border-collapse: collapse; width: 100%; }
:where(th, td) { padding: 0.55em 0.75em; text-align: left; vertical-align: top; }
:where(th) { font-weight: 600; }
:where(thead th) { border-bottom: 1px solid var(--obx-line); }
:where(tbody tr):hover { background-color: rgba(0, 0, 0, 0.02); }

/* ---------- Cards ---------- */

:where(.card, .box, .panel, .login-box, .login-card) { border-radius: var(--obx-radius); }
:where(.card, .panel, .stat-card, .queue-card) { transition: box-shadow 0.2s ease, transform 0.2s ease; }
:where(.login-box, .login-card, body > .box, body > div > .box) {
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* ---------- Motion + print ---------- */

@media (prefers-reduced-motion: reduce) {
  :where(*, *::before, *::after) { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media print {
  #obx-coffee, #obx-loading-overlay { display: none !important; }
}

/* =====================================================================
 * Injected UI
 * ===================================================================== */

/* Loading overlay: quiet, light, gone the moment the page is ready */
#obx-loading-overlay {
  position: fixed; inset: 0; z-index: 99999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--obx-wash);
  font-family: var(--obx-font);
  transition: opacity 0.25s ease;
}
#obx-loading-overlay.loaded { opacity: 0; pointer-events: none; }
#obx-loading-overlay .obx-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--obx-line);
  border-top-color: var(--obx-brand);
  animation: obx-spin 0.75s linear infinite;
}
#obx-loading-overlay .obx-loading-msg { font-size: 14px; color: var(--obx-ink-soft); letter-spacing: 0.01em; }
@keyframes obx-spin { to { transform: rotate(360deg); } }

/* Demo login hint under owner login forms */
#obx-demo-hint {
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-family: var(--obx-font); font-size: 13px; line-height: 1.6;
  color: var(--obx-ink-soft); text-align: center;
}
#obx-demo-hint .obx-demo-label {
  display: block; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.75;
}
#obx-demo-hint code {
  display: inline-block; margin: 6px 0 4px; padding: 3px 12px;
  font-family: var(--obx-mono); font-size: 14px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--obx-ink); background: rgba(0, 0, 0, 0.05); border-radius: 6px;
}
#obx-demo-hint .obx-demo-note { display: block; font-size: 12px; opacity: 0.8; }

/* Buy me a coffee: small pill, bottom right, dismissible, sits under modals */
#obx-coffee {
  position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: inline-flex; align-items: center;
  font-family: var(--obx-font); font-size: 13px; line-height: 1;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: saturate(1.4) blur(8px); backdrop-filter: saturate(1.4) blur(8px);
  color: #2d3748;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(16, 24, 40, 0.12);
  opacity: 0; transform: translateY(6px);
  transition: opacity 0.3s ease, transform 0.3s ease, bottom 0.2s ease;
}
#obx-coffee.obx-show { opacity: 1; transform: none; }
#obx-coffee.obx-show.obx-away { opacity: 0; transform: translateY(6px); pointer-events: none; }
#obx-coffee a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 4px 8px 13px;
  color: inherit; text-decoration: none; font-weight: 600; white-space: nowrap;
}
#obx-coffee a:hover { color: #000; }
#obx-coffee svg { width: 15px; height: 15px; flex: none; }
#obx-coffee button {
  appearance: none; border: 0; background: none; cursor: pointer;
  width: 28px; height: 28px; margin-right: 2px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: #8a94a6; font-size: 16px; line-height: 1; border-radius: 50%;
}
#obx-coffee button:hover { color: #2d3748; background: rgba(0, 0, 0, 0.05); }
#obx-coffee a:focus-visible, #obx-coffee button:focus-visible { outline: 2px solid #2d3748; outline-offset: 1px; }

@media (max-width: 640px) {
  #obx-coffee { right: 10px; font-size: 12px; }
  #obx-coffee a { padding: 7px 2px 7px 11px; }
}
