/* Shared look of the chat page and the admin page (SPEC.md Step 7g): design tokens for the light
   and dark themes, and the shared parts (header, buttons, fields, cards, chips, notices, the theme
   control). Each page links this file before its own stylesheet. No web fonts and no image files:
   the CSP allows styles and images from this origin only, and icons are inline SVG.

   Themes: light is the default below. Dark applies when the system prefers it and the user did not
   pick Light, or when the user picked Dark. theme.js sets data-theme="light" or "dark" on <html>;
   System means no attribute. The two dark blocks must hold the same values
   (tests/test_web_theme.py also checks the contrast of every token pair). */

:root {
  color-scheme: light dark;

  /* Placeholder brand color, until the Aquarobotics brand values exist (SPEC.md Open questions).
     Change --accent and --accent-text (and their dark values) together, then run
     tests/test_web_theme.py: button text on the accent needs 4.5:1. */
  --accent: #0b5cad;
  --accent-text: #ffffff;

  --bg: #f5f7fa;
  --surface: #ffffff;
  --raised: #eef2f6;
  --text: #18212d;
  --muted: #556170;
  --border: #dde3ea;
  --field-border: #7d8794;
  --focus: #0b5cad;
  --user: #e2edfa;
  --error-bg: #fdeceb;
  --error-text: #a3191c;
  --ok: #1d6b35;

  --radius-s: 6px;
  --radius: 10px;
  --radius-l: 16px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --shadow-1: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-2: 0 4px 12px rgb(16 24 40 / 8%), 0 2px 4px rgb(16 24 40 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #5ea3ec; /* placeholder brand color, dark theme */
    --accent-text: #0a1320;
    --bg: #0e1217;
    --surface: #171c23;
    --raised: #212833;
    --text: #e7eaef;
    --muted: #a0abb9;
    --border: #2a323e;
    --field-border: #6e7a8a;
    --focus: #7db7f3;
    --user: #1d3150;
    --error-bg: #3b1c1f;
    --error-text: #f6bcbc;
    --ok: #7fd49a;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-2: 0 4px 12px rgb(0 0 0 / 45%);
  }
}

:root[data-theme="dark"] {
  --accent: #5ea3ec; /* placeholder brand color, dark theme */
  --accent-text: #0a1320;
  --bg: #0e1217;
  --surface: #171c23;
  --raised: #212833;
  --text: #e7eaef;
  --muted: #a0abb9;
  --border: #2a323e;
  --field-border: #6e7a8a;
  --focus: #7db7f3;
  --user: #1d3150;
  --error-bg: #3b1c1f;
  --error-text: #f6bcbc;
  --ok: #7fd49a;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-2: 0 4px 12px rgb(0 0 0 / 45%);
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

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

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

h1,
h2,
h3 {
  line-height: 1.25;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Inline SVG icons take the text color and size of their button. */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentcolor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------ header */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top h1 {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 650;
}

.top h1 .logo {
  width: 1.6rem;
  height: 1.6rem;
  color: var(--accent);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.top-actions a {
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-s);
  font-weight: 500;
  text-decoration: none;
}

.top-actions a:hover {
  background: var(--raised);
}

/* ------------------------------------------------------------ buttons */

button {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    color 0.15s;
}

button:hover:not(:disabled) {
  background: var(--raised);
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.primary:hover:not(:disabled) {
  background: var(--accent);
  filter: brightness(1.08);
}

button.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

button.quiet:hover:not(:disabled) {
  background: var(--raised);
  color: var(--text);
}

button.danger {
  border-color: var(--error-text);
  color: var(--error-text);
}

button.icon-only {
  width: 2.25rem;
  padding: 0;
}

/* ------------------------------------------------------------ fields */

input,
textarea,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-s);
  padding: 0.4rem 0.6rem;
}

input[type="file"] {
  padding: 0.3rem;
}

textarea {
  resize: vertical;
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* ------------------------------------------------------------ cards, chips, notices */

.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

.chip {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  background: var(--raised);
  color: var(--muted);
  font-size: 0.85rem;
}

.notice {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-s);
  background: var(--error-bg);
  color: var(--error-text);
}

.notice[hidden] {
  display: none;
}

/* ------------------------------------------------------------ the theme control */

.theme-switch {
  position: relative; /* holds the buttons' visually hidden names */
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--raised);
}

.theme-switch button {
  width: 2rem;
  min-height: 2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.theme-switch button:hover:not([aria-pressed="true"]) {
  background: transparent;
  color: var(--text);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--surface);
  border-color: var(--field-border);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ------------------------------------------------------------ phone width */

/* The header stays one row: the title shows only its logo (its text stays the heading's
   accessible name) and the actions do not wrap. */
@media (max-width: 40rem) {
  .top,
  .top-actions {
    flex-wrap: nowrap;
  }

  .top h1 {
    position: relative; /* holds the hidden title text */
  }

  .top h1 .title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .top-actions {
    gap: var(--space-1);
  }

  /* Header items keep their size: a squeezed "Sign out" broke onto two lines at 320 px. */
  .top-actions > * {
    flex-shrink: 0;
  }
}

/* Very narrow phones (under 368 px): the actions move to their own row instead of squeezing. */
@media (max-width: 23rem) {
  .top {
    flex-wrap: wrap;
  }
}
