/*
 * xsuite.css -- the one design system for xDocs, xDrive and xMS.
 *
 * The palette is lifted from xMS, which already looks the way Frank wants the
 * suite to look: near-black surfaces, amber accent, Segoe UI. What changes is
 * how it is expressed. xMS today has exactly one custom property
 * (--accent-color) and roughly forty hard-coded hexes, and its theme files
 * override raw colours on a hand-maintained list of selectors -- so any element
 * that isn't on the list keeps its dark colours and punches a hole in the light
 * themes.
 *
 * Here every colour is a token. A theme redefines tokens and nothing else,
 * which means a new theme cannot miss an element: if a component is built from
 * tokens it themes correctly for free.
 */

/* ------------------------------------------------------------------ tokens */

:root {
  /* Surfaces, darkest to lightest. "sunken" is for wells and side panes,
     "raised" for cards and controls that sit above the page. */
  --bg: #1a1a1a;
  --bg-sunken: #151515;
  --bg-raised: #2a2a2a;
  --bg-header: #1f1f1f;
  --bg-hover: #333333;

  --border: #333333;
  --border-strong: #444444;
  --border-hover: #555555;

  --text: #ffffff;
  --text-muted: #aaaaaa;
  --text-faint: #888888;

  /* One accent, plus the two derived shades xMS previously hard-coded as
     #ffd666 / #ffb030 / #ffb300. Deriving them means a custom accent stays
     consistent through hover and focus instead of snapping back to orange. */
  --accent: #ffc040;
  --accent-hover: color-mix(in srgb, var(--accent) 82%, white);
  --accent-active: color-mix(in srgb, var(--accent) 88%, black);
  --accent-glow: color-mix(in srgb, var(--accent) 35%, transparent);
  --on-accent: #1a1a1a;

  --danger: #ff6b6b;
  --success: #4ade80;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --font: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "Courier New", monospace;

  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

/* Light theme. Only tokens are redefined -- no component selectors appear
   below this line, which is the entire point of the exercise. */
:root.qs-light {
  --bg: #f4f2ee;
  --bg-sunken: #e9e6e0;
  --bg-raised: #ffffff;
  --bg-header: #ffffff;
  --bg-hover: #e4e0d8;

  --border: #d6d1c7;
  --border-strong: #c2bcae;
  --border-hover: #a8a294;

  --text: #1a1a1a;
  --text-muted: #5b564d;
  --text-faint: #837d72;

  --accent: #b8791a;
  --on-accent: #ffffff;

  --shadow: 0 8px 32px rgba(0, 0, 0, 0.15);

  color-scheme: light;
}

/* Fallback for browsers without color-mix(): without this the derived accents
   resolve to nothing and hovers lose their colour entirely. */
@supports not (color: color-mix(in srgb, red 50%, white)) {
  :root {
    --accent-hover: #ffd666;
    --accent-active: #e0a838;
    --accent-glow: rgba(255, 192, 64, 0.35);
  }
}

/* --------------------------------------------------------------- base ---- */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* [hidden] is only `display: none` in the UA stylesheet, so ANY author rule
   that sets display -- .qs-main{display:flex} below, for one -- silently wins
   and the element stays on screen. This has to be !important to outrank those
   class rules. Without it, hiding a flex/grid container does nothing at all. */
[hidden] {
  display: none !important;
}

/* One focus style for the whole suite. xMS currently removes the outline in
   several places and replaces it with nothing, which makes the app unusable by
   keyboard; :focus-visible keeps it invisible for mouse users. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

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

.qs-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.2;
  color: var(--text);
  background-color: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.05s;
}

.qs-btn:hover:not(:disabled) {
  background-color: var(--bg-hover);
  border-color: var(--border-hover);
}

.qs-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.qs-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.qs-btn-primary {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.qs-btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.qs-btn-danger:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

/* Square icon button, for toolbars. */
.qs-icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  flex: 0 0 auto;
}

.qs-input,
.qs-textarea,
.qs-select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  /* 16px minimum: anything smaller makes iOS Safari zoom the page on focus. */
  font-size: max(1rem, 16px);
  color: var(--text);
  background-color: var(--bg-sunken);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

.qs-input:focus,
.qs-textarea:focus,
.qs-select:focus {
  outline: none;
  border-color: var(--accent);
}

.qs-input::placeholder,
.qs-textarea::placeholder {
  color: var(--text-faint);
}

/* ---------------------------------------------------------- structure ---- */

.qs-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.qs-topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.qs-topbar h1 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.qs-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0; /* lets children scroll instead of the page growing */
}

.qs-sidebar {
  width: 260px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background-color: var(--bg-sunken);
  border-right: 1px solid var(--border);
}

.qs-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.qs-scroll {
  overflow-y: auto;
  min-height: 0;
}

.qs-spacer {
  flex: 1 1 auto;
}

/* --------------------------------------------------------------- misc ---- */

.qs-muted {
  color: var(--text-muted);
}

.qs-faint {
  color: var(--text-faint);
  font-size: 0.85rem;
}

.qs-empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-faint);
}

.qs-card {
  background-color: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.qs-badge {
  display: inline-block;
  padding: 2px var(--space-2);
  font-size: 0.75rem;
  border-radius: 999px;
  background-color: var(--bg-hover);
  color: var(--text-muted);
}

mark {
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 2px;
}

/* Modal, replacing the alert()/prompt() pattern used across the suite today. */
.qs-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 1000;
}

.qs-modal[hidden] {
  display: none;
}

.qs-modal-card {
  width: min(460px, 100%);
  max-height: 85dvh;
  overflow-y: auto;
  background-color: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-5);
}

.qs-modal-card h2 {
  font-size: 1.15rem;
  margin-bottom: var(--space-3);
  color: var(--accent);
}

.qs-modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-4);
}

/* Toast, for save confirmations and errors that don't deserve a modal. */
.qs-toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translateX(-50%);
  padding: var(--space-2) var(--space-4);
  background-color: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 1100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.qs-toast.qs-show {
  opacity: 1;
}

.qs-toast.qs-error {
  border-color: var(--danger);
  color: var(--danger);
}

/* -------------------------------------------------------- scrollbars ----- */

.qs-scroll::-webkit-scrollbar,
.qs-textarea::-webkit-scrollbar {
  width: 10px;
}

.qs-scroll::-webkit-scrollbar-track,
.qs-textarea::-webkit-scrollbar-track {
  background: var(--bg-sunken);
}

.qs-scroll::-webkit-scrollbar-thumb,
.qs-textarea::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
}

.qs-scroll::-webkit-scrollbar-thumb:hover,
.qs-textarea::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ------------------------------------------------------------- mobile ---- */

@media (max-width: 860px) {
  .qs-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 85vw);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .qs-sidebar.qs-open {
    transform: translateX(0);
  }

  .qs-sidebar-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
  }

  .qs-sidebar-scrim[hidden] {
    display: none;
  }
}

@media (min-width: 861px) {
  .qs-only-mobile {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
