/* ==========================================================================
   AutoPload — base styles: tokens + components (production)
   Synced from design/assets/design-system.css — the design source of truth.
   Keep both in sync until the design/ mockups are retired.
   Spec: design/tokens.md · Board: design/assets/UI_Design_System.png
   Rules: pure CSS · no JS · no external fonts or frameworks.
   ========================================================================== */

/* ----- Tokens ------------------------------------------------------------ */
:root {
  /* native controls (date/time picker icons, dropdowns, checkboxes, scrollbars) in dark */
  color-scheme: dark;

  /* brand */
  --lime: #9bea00;
  --lime-hover: #aef92b;
  --lime-tint: rgba(155, 234, 0, 0.12);
  --lime-tint-strong: rgba(155, 234, 0, 0.2);

  /* neutrals */
  --ink: #0a0a0a;
  --surface: #111317;
  --elevated: #1a1f23;
  --elevated-2: #23292e;         /* hover layer above elevated */
  --border: #2a2f33;
  --border-strong: #3a4147;
  --text: #ffffff;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  /* semantic */
  --success: var(--lime);
  --success-tint: var(--lime-tint);
  --warning: #fbbf24;
  --warning-tint: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-tint: rgba(248, 113, 113, 0.12);
  --info: #93c5fd;
  --info-tint: rgba(147, 197, 253, 0.12);

  /* type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-ui: 14px;
  --text-base: 15px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 26px;
  --text-display: 44px;
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* radius */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-2xl: 32px;
  --radius-pill: 999px;

  /* elevation */
  --shadow-low: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-high: 0 12px 32px rgba(0, 0, 0, 0.55);

  /* motion */
  --speed: 140ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  /* layout */
  --sidebar-w: 248px;
  --content-max: 1200px;
}

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

body,
h1, h2, h3, h4, p,
figure, blockquote, dl, dd {
  margin: 0;
}

img {
  display: block;
  max-width: 100%;
}

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

/* ----- Base -------------------------------------------------------------- */
body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

a {
  color: var(--lime);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

::selection {
  background: var(--lime);
  color: var(--ink);
}

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

/* ----- Utilities (small, deliberate set) --------------------------------- */
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.tabular { font-variant-numeric: tabular-nums; }

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

.grow {
  flex: 1;
  min-width: 0;
}

.eyebrow {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
}

.icon--sm {
  width: 14px;
  height: 14px;
}

/* Code samples (CSV example, keys) scroll inside their card instead of
   widening the page on a phone — a bare <pre> never wraps. */
pre {
  max-width: 100%;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* ----- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 38px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-ui);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--speed) var(--ease),
    border-color var(--speed) var(--ease), color var(--speed) var(--ease);
}

a.btn:hover { text-decoration: none; }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--lime);
  color: var(--ink);
}

.btn--primary:hover:not(:disabled) { background: var(--lime-hover); }
.btn--primary:active:not(:disabled) { transform: translateY(1px); }

.btn--secondary {
  background: var(--elevated);
  border-color: var(--border);
  color: var(--text);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--elevated-2);
  border-color: var(--border-strong);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.btn--danger-ghost {
  background: var(--danger);
  color: var(--ink);
}

.btn--danger-ghost:hover:not(:disabled) {
  background: #fb9c9c;
  color: var(--ink);
}

.btn--danger {
  background: var(--danger);
  color: var(--ink);
}

.btn--danger:hover:not(:disabled) { background: #fb9c9c; }

.btn--sm {
  height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

.btn--icon {
  width: 38px;
  padding: 0;
}

.btn--icon.btn--sm { width: 32px; }

.btn--block {
  width: 100%;
}

/* ----- Forms ------------------------------------------------------------- */
.label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.label__hint {
  font-weight: var(--weight-normal);
  color: var(--text-dim);
}

.input,
.select,
textarea.input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 var(--space-3);
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--text-ui);
  transition: border-color var(--speed) var(--ease);
}

textarea.input {
  height: auto;
  min-height: 120px;
  padding: 10px var(--space-3);
  line-height: 1.6;
  resize: vertical;
}

.input::placeholder { color: var(--text-dim); }

.input:hover,
.select:hover,
textarea.input:hover { border-color: var(--border-strong); }

.input:focus,
.select:focus,
textarea.input:focus {
  outline: none;
  border-color: var(--lime);
  box-shadow: 0 0 0 3px var(--lime-tint);
}

.input:disabled,
.select:disabled,
textarea.input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* native date/time picker icons — visible on dark */
.input::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.7;
}

.input::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

.select {
  appearance: none;
  height: 40px;
  border-radius: var(--radius-md);
  padding-right: 34px;
  font-variant-numeric: tabular-nums;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.2' 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 11px center;
  cursor: pointer;
}

/* Opening the native list should not flash a white system menu */
option {
  background: var(--elevated);
  color: var(--text);
}

/* Hour:minute read as one control instead of two stray boxes */
/* One field, two drop zones — not two stray boxes next to each other */
.TimePair {
  display: flex;
  align-items: center;
  width: 100%;
  height: 38px;
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}

.TimePair:hover { border-color: var(--border-strong); }

.TimePair:focus-within {
  border-color: var(--lime);
  box-shadow: 0 0 0 3px var(--lime-tint);
}

.TimePair .select {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding-left: 0;
  padding-right: 24px;
  text-align: center;
  background-color: transparent;
  border: 0;
  border-radius: 0;
  background-position: right 8px center;
}

.TimePair .select:focus {
  outline: none;
  box-shadow: none; /* the field itself shows focus */
}

.TimePairSep {
  color: var(--text-dim);
  font-weight: var(--weight-semibold);
  line-height: 1;
}

.checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--lime);
  cursor: pointer;
}

.radio {
  appearance: none;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  flex: none;
}

.radio::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lime);
  transform: scale(0);
  transition: transform var(--speed) var(--ease);
}

.radio:checked { border-color: var(--lime); }
.radio:checked::after { transform: scale(1); }

.field-hint {
  margin-top: 6px;
  font-size: var(--text-xs);
  color: var(--text-dim);
}

/* file inputs — theme the native control (no JS needed) */
input[type="file"] {
  height: auto;
  padding: 8px var(--space-3);
  line-height: 1.4;
}

input[type="file"]::file-selector-button {
  margin-right: var(--space-3);
  padding: 6px var(--space-3);
  background: var(--elevated-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--border-strong);
}

.field-stack { display: flex; flex-direction: column; gap: var(--space-4); }

/* ----- Badge ------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--neutral {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
  color: var(--text-muted);
}

.badge--success {
  background: var(--success-tint);
  border-color: rgba(155, 234, 0, 0.3);
  color: var(--lime);
}

.badge--warning {
  background: var(--warning-tint);
  border-color: rgba(251, 191, 36, 0.3);
  color: var(--warning);
}

.badge--danger {
  background: var(--danger-tint);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}

.badge--info {
  background: var(--info-tint);
  border-color: rgba(147, 197, 253, 0.3);
  color: var(--info);
}

/* ----- Alert ------------------------------------------------------------- */
.alert {
  display: flex;
  gap: var(--space-3);
  padding: 14px var(--space-4);
  border: 1px solid;
  border-radius: var(--radius-md);
  font-size: var(--text-ui);
}

.alert__icon { margin-top: 1px; }

.alert__title {
  font-weight: var(--weight-semibold);
  color: var(--text);
}

.alert__body {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.alert--warning {
  background: var(--warning-tint);
  border-color: rgba(251, 191, 36, 0.3);
}
.alert--warning .alert__icon { color: var(--warning); }

.alert--danger {
  background: var(--danger-tint);
  border-color: rgba(248, 113, 113, 0.35);
}
.alert--danger .alert__icon { color: var(--danger); }

.alert--success {
  background: var(--success-tint);
  border-color: rgba(155, 234, 0, 0.3);
}
.alert--success .alert__icon { color: var(--lime); }

.alert--info {
  background: var(--info-tint);
  border-color: rgba(147, 197, 253, 0.3);
}
.alert--info .alert__icon { color: var(--info); }

/* ----- Card / Panel ------------------------------------------------------ */
.card {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}

.card--pad { padding: 20px; }
.panel--pad { padding: var(--space-5); }

/* ----- Tabs -------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
}

.tab {
  margin-bottom: -1px;
  padding: 10px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: var(--text-ui);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  color: var(--lime);
  border-bottom-color: var(--lime);
}

/* ----- Segmented control ------------------------------------------------- */
.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.seg__item {
  padding: 5px 12px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.seg__item.is-active {
  background: #2e353b;
  color: var(--text);
}

/* ----- Avatar ------------------------------------------------------------ */
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--elevated-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

/* ----- Table ------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-ui);
}

.table th {
  padding: 10px 12px;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.table__num {
  width: 40px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.table__when {
  white-space: nowrap;
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.table__text {
  margin: 0;
  max-width: 380px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
}

.table__note {
  margin-top: 4px;
  font-size: var(--text-xs);
  color: var(--text-dim);
}

.table__note--warn { color: var(--warning); }

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