/* Scout Tools base styles (reset + semantic defaults) */
:root {
  color-scheme: light dark;

  /* Core palette */
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-muted: #e5e7eb;
  --text: #111827;
  --muted: #4b5563;
  --placeholder: #5f6670;
  --border: #e5e7eb;
  --accent: #2c5f4d;
  --accent-contrast: #ffffff;
  --accent-secondary: #ce1126;
  --accent-tertiary: #996633;
  --button-bg: var(--accent);
  --button-text: var(--accent-contrast);

  /* Theme accents (overridable) */
  --hero-from: #ffffff;
  --hero-to: #f3f4f6;
  --hero-text: var(--text);
  --header-bg: #ffffff;
  --header-border: #e5e7eb;
  --header-text: var(--text);

  /* Layout & motion */
  --radius-sm: 8px;
  --radius: 14px;
  --shadow-sm: 0 2px 10px rgba(27, 27, 27, 0.08);
  --shadow: 0 8px 28px rgba(27, 27, 27, 0.12);
  --focus: 2px solid color-mix(in srgb, var(--accent) 75%, transparent);
  --select-caret: url("data:image/svg+xml,%3Csvg viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5 7l5 6 5-6' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --bg: #111316;
  --surface: #1b1f24;
  --surface-2: #242a30;
  --surface-muted: #2b3239;
  --text: #e5e7eb;
  --muted: #a8b0bb;
  --placeholder: #b2bcc8;
  --border: #2f353c;
  --accent: #6db39b;
  --accent-contrast: #0b1a14;
  --accent-secondary: #e05a6b;
  --accent-tertiary: #b2855a;

  --hero-from: #24292e;
  --hero-to: #1f252b;
  --hero-text: #e1e4e8;
  --header-bg: #24292e;
  --header-border: #3d454b;
  --header-text: #e1e4e8;

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --select-caret: url("data:image/svg+xml,%3Csvg viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5 7l5 6 5-6' fill='none' stroke='%23cbd5e1' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111316;
    --surface: #1b1f24;
    --surface-2: #242a30;
    --surface-muted: #2b3239;
    --text: #e5e7eb;
    --muted: #a8b0bb;
    --placeholder: #b2bcc8;
    --border: #2f353c;
    --accent: #6db39b;
    --accent-contrast: #0b1a14;
    --accent-secondary: #e05a6b;
    --accent-tertiary: #b2855a;

    --hero-from: #24292e;
    --hero-to: #1f252b;
    --hero-text: #e1e4e8;
    --header-bg: #24292e;
    --header-border: #3d454b;
    --header-text: #e1e4e8;

    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    --select-caret: url("data:image/svg+xml,%3Csvg viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5 7l5 6 5-6' fill='none' stroke='%23cbd5e1' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

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

* {
  margin: 0;
}

html {
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

a:not(.button):not(.tile):hover,
a:not(.button):not(.tile):focus-visible {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

::placeholder {
  color: var(--placeholder);
}

.header .muted {
  color: color-mix(in srgb, var(--header-text) 70%, transparent);
}

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

/* Typography */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
  font-weight: 700;
}

h1 { font-size: clamp(28px, 4vw, 40px); }

h2 { font-size: clamp(20px, 2.6vw, 28px); }

p {
  max-width: 70ch;
}

.muted {
  color: var(--muted);
  font-size: 0.95rem;
}

label {
  font-size: 0.85rem;
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Form controls */
input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--surface);
}

select {
  background-color: var(--surface);
  padding-right: 36px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: var(--select-caret);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
}

button,
.button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.05s ease, background 0.2s ease, border-color 0.2s ease;
}

button:hover,
.button:hover {
  background: color-mix(in srgb, var(--surface-2) 85%, white);
}

button.primary,
.button.primary {
  background: var(--button-bg);
  color: var(--button-text);
  border-color: color-mix(in srgb, var(--button-bg) 65%, var(--border));
}

button.primary:hover,
.button.primary:hover {
  background: color-mix(in srgb, var(--button-bg) 92%, white);
}

button:active,
.button:active {
  transform: translateY(1px);
}

/* Layout utilities */
.container {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 0 16px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.cols-2 {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* Header + hero */
.header {
  position: relative;
}

.header-inner {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  color: var(--header-text);
  backdrop-filter: saturate(120%) blur(6px);
}

.header-brand {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.header-brand strong {
  font-size: 1.05rem;
}

.header-title-subtitle {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-toggle {
  display: none;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--header-border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
}

.header-toggle-icon {
  width: 20px;
  height: 2px;
  background: currentColor;
  position: relative;
}

.header-toggle-icon::before,
.header-toggle-icon::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 2px;
  left: 0;
  background: currentColor;
}

.header-toggle-icon::before {
  top: -6px;
}

.header-toggle-icon::after {
  top: 6px;
}

.header-panel {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.header-panel.is-collapsed {
  display: none;
}

.breadcrumbs {
  border-top: none;
  padding: 10px 8px 12px;
  background: var(--bg);
}

.breadcrumb-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
  color: color-mix(in srgb, var(--muted) 82%, var(--header-text));
}

.breadcrumb-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.breadcrumb-item + .breadcrumb-item::before {
  content: "/";
  color: color-mix(in srgb, var(--muted) 72%, transparent);
  margin-right: 2px;
}

.breadcrumb-item a {
  color: color-mix(in srgb, var(--muted) 86%, var(--header-text));
}

.breadcrumb-item [aria-current="page"] {
  color: color-mix(in srgb, var(--muted) 92%, var(--header-text));
}

.hero {
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  border: 1px solid var(--header-border);
  border-radius: calc(var(--radius) + 6px);
  padding: 24px;
  box-shadow: var(--shadow);
  color: var(--hero-text);
}

/* Theme controls */
.theme-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.theme-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 150px;
}

.theme-control label {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0;
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 999px;
  font-weight: 400;
  line-height: 1;
}

.theme-toggle [data-theme-toggle-label] {
  font-size: 16px;
  line-height: 1;
}

.theme-toggle[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

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

/* Cards + tiles */
.card {
  background: var(--surface);
  border: 1px solid var(--header-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--header-border);
  background: var(--surface);
  min-height: 120px;
  transition: background 0.2s ease, transform 0.05s ease;
}

.tile:hover {
  background: color-mix(in srgb, var(--surface-2) 85%, white);
  border-color: color-mix(in srgb, var(--accent) 30%, var(--header-border));
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  background: color-mix(in srgb, var(--accent-secondary) 18%, var(--surface));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent-secondary) 36%, var(--border));
}

[data-theme="dark"] .badge {
  background: color-mix(in srgb, var(--accent-secondary) 24%, var(--surface));
  border-color: color-mix(in srgb, var(--accent-secondary) 42%, var(--border));
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

caption {
  text-align: left;
  font-weight: 600;
  margin-bottom: 8px;
}

th,
td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  vertical-align: middle;
}

th {
  background: var(--surface-muted);
  font-size: 0.78rem;
  text-align: left;
  font-weight: 700;
}

td {
  font-size: 0.85rem;
}

tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface) 94%, var(--surface-muted));
}

td:first-child,
th[scope="row"] {
  font-weight: 600;
}

table input,
table select {
  width: 100%;
  padding: 6px 8px;
  font-size: 0.85rem;
}

@media print {
  .no-print {
    display: none !important;
  }
}

@media (max-width: 860px) {
  .header-inner {
    align-items: center;
    flex-wrap: wrap;
    min-height: 44px;
    padding-top: 0;
    padding-bottom: 0;
  }

  .header-title-subtitle {
    display: none;
  }

  .header-brand strong {
    font-size: 0.98rem;
    line-height: 1.1;
  }

  .header-actions {
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
    position: relative;
    gap: 8px;
  }

  .header-toggle {
    display: inline-flex;
  }

  .header-panel {
    width: min(320px, calc(100vw - 32px));
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--header-border);
    border-radius: var(--radius-sm);
    background: var(--header-bg);
    box-shadow: var(--shadow-sm);
    z-index: 20;
  }

  .theme-controls {
    width: 100%;
  }

  .theme-control {
    min-width: 0;
  }

  .breadcrumbs {
    padding: 6px 8px 8px;
  }
}

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