/*
 * Crisp design system v1 (BookerDog, Cycle 1).
 * Tokens: session 1a brief, Tables T and T2. This file and assets/ are the only places colour literals may appear.
 */

/* Day (default) */
:root {
  --bg-canvas: #FAFAF9;
  --bg-surface: #FFFFFF;
  --bg-sunken: #F3F3F1;
  --bg-raised: #FFFFFF;
  --bg-hover: #EDEDEA;
  --bg-selected: #E9E9F8;
  --border-subtle: #E4E4E0;
  --border-strong: #82838A;
  --text-primary: #1C1C21;
  --text-secondary: #53545C;
  --text-tertiary: #6B6C74;
  --accent: #4B4BC8;
  --accent-hover: #3D3DB0;
  --on-accent: #FFFFFF;
  --success: #1D7444;
  --warning: #875700;
  --warning-bg: #FFF4DE;
  --danger: #BE2F28;
  --info: #2360A3;
  --focus-ring: #4B4BC8;
  --info-bg: #E8F0FA;
  --success-bg: #E6F4EC;
  --danger-bg: #FCEAE9;
  --toast-bg: #1C1C21;
  --toast-fg: #FAFAF9;
  --skeleton: #EDEDEA;
  --shadow-e1: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.06);
  --shadow-e2: 0 8px 32px rgba(0,0,0,.16);

  --fs-display: 28px;
  --lh-display: 34px;
  --fs-h1: 22px;
  --lh-h1: 28px;
  --fs-h2: 17px;
  --lh-h2: 24px;
  --fs-body-lg: 16px;
  --lh-body-lg: 24px;
  --fs-body: 14px;
  --lh-body: 20px;
  --fs-label: 13px;
  --lh-label: 18px;
  --fs-caption: 12px;
  --lh-caption: 16px;

  --space-1: 2px;
  --space-2: 4px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 16px;
  --space-6: 20px;
  --space-7: 24px;
  --space-8: 32px;
  --space-9: 40px;
  --space-10: 56px;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-full: 9999px;

  --motion-fast: 120ms;
  --motion-base: 180ms;
  --motion-slow: 240ms;
  --ease-standard: cubic-bezier(.2,.8,.2,1);

  color-scheme: light;
}

/* Night, explicit choice */
[data-theme="night"] {
  --bg-canvas: #111114;
  --bg-surface: #18181C;
  --bg-sunken: #141417;
  --bg-raised: #212126;
  --bg-hover: #26262C;
  --bg-selected: #25254A;
  --border-subtle: #2B2B31;
  --border-strong: #72737C;
  --text-primary: #EDEDF0;
  --text-secondary: #A8A9B2;
  --text-tertiary: #8E8F98;
  --accent: #9494FF;
  --accent-hover: #A8A8FF;
  --on-accent: #111114;
  --success: #4FC48C;
  --warning: #E6B04C;
  --warning-bg: #2E2412;
  --danger: #FF7D72;
  --info: #6FA9FF;
  --focus-ring: #9494FF;
  --info-bg: #14233A;
  --success-bg: #12291D;
  --danger-bg: #3A1715;
  --toast-bg: #EDEDF0;
  --toast-fg: #111114;
  --skeleton: #26262C;
  --shadow-e1: none;
  --shadow-e2: 0 8px 32px rgba(0,0,0,.5);
  color-scheme: dark;
}

/* Night, following the device when no explicit choice has been made */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="day"]) {
    --bg-canvas: #111114;
    --bg-surface: #18181C;
    --bg-sunken: #141417;
    --bg-raised: #212126;
    --bg-hover: #26262C;
    --bg-selected: #25254A;
    --border-subtle: #2B2B31;
    --border-strong: #72737C;
    --text-primary: #EDEDF0;
    --text-secondary: #A8A9B2;
    --text-tertiary: #8E8F98;
    --accent: #9494FF;
    --accent-hover: #A8A8FF;
    --on-accent: #111114;
    --success: #4FC48C;
    --warning: #E6B04C;
    --warning-bg: #2E2412;
    --danger: #FF7D72;
    --info: #6FA9FF;
    --focus-ring: #9494FF;
    --info-bg: #14233A;
    --success-bg: #12291D;
    --danger-bg: #3A1715;
    --toast-bg: #EDEDF0;
    --toast-fg: #111114;
    --skeleton: #26262C;
    --shadow-e1: none;
    --shadow-e2: 0 8px 32px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  font-size: var(--fs-body-lg);
  line-height: var(--lh-body-lg);
  font-weight: 400;
  background: var(--bg-canvas);
  color: var(--text-primary);
}
h1, h2, h3 { font-family: "Inter", system-ui, sans-serif; margin: 0; font-weight: 600; }
.t-display { font-size: var(--fs-display); line-height: var(--lh-display); font-weight: 600; }
.t-h1 { font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: 600; }
.t-h2 { font-size: var(--fs-h2); line-height: var(--lh-h2); font-weight: 600; }
.t-body-lg { font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); }
.t-meta { font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text-secondary); }
.t-label { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500; }
.t-caption { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--text-secondary); }

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

.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.icon-20 { width: 20px; height: 20px; }

/* Button: contributor screens use the 40 px height */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-3);
  min-height: 40px; padding: 0 var(--space-5);
  font: inherit; font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500;
  border-radius: var(--radius-md); border: 1px solid transparent; cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease-standard), border-color var(--motion-fast) var(--ease-standard);
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-quiet { background: transparent; color: var(--text-primary); }
.btn-quiet:hover { background: var(--bg-hover); }
.btn[disabled] { cursor: default; opacity: .6; }
.btn-block { width: 100%; }

/* Text-styled link button: 40 px tall so it meets the contributor target size */
.link {
  display: inline-flex; align-items: center; min-height: 40px; min-width: 24px; padding: 0 var(--space-2);
  background: transparent; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); font-weight: 500;
  color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
}
.link:hover { color: var(--accent-hover); }
.link[disabled] { color: var(--text-secondary); text-decoration: none; cursor: default; }

/* Inputs */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field-label { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500; color: var(--text-primary); }
.field-help { font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text-secondary); }
.input, .select, .textarea {
  font: inherit; font-size: var(--fs-body-lg); line-height: var(--lh-body-lg);
  min-height: 40px; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-primary); width: 100%;
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); opacity: 1; }
.input[readonly], .textarea[readonly], .select[disabled] { background: var(--bg-sunken); }
.textarea { resize: vertical; }
.field-error { font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); color: var(--danger); margin: 0; }

/* Status label: icon + word + colour */
.status {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm);
  font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500; white-space: nowrap;
}
.status-neutral { color: var(--text-secondary); background: var(--bg-sunken); }
.status-warning { color: var(--warning); background: transparent; }
.status-info { color: var(--info); background: transparent; }
.status-success { color: var(--success); background: transparent; }
.status-danger { color: var(--danger); background: transparent; }

/* Inline notice */
.notice {
  display: flex; gap: var(--space-4); align-items: flex-start; flex-wrap: wrap;
  padding: var(--space-4) var(--space-5); border-radius: var(--radius-lg);
  color: var(--text-primary); font-size: var(--fs-body-lg); line-height: var(--lh-body-lg);
}
.notice p { margin: 0; flex: 1 1 200px; }
.notice-warning { background: var(--warning-bg); }
.notice-info { background: var(--info-bg); }
.notice-danger { background: var(--danger-bg); }
.notice-success { background: var(--success-bg); }
.notice-neutral { background: var(--bg-sunken); }

/* Banner (offline, system-wide) */
.banner {
  background: var(--bg-sunken); color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  padding: var(--space-3) var(--space-7); font-size: var(--fs-body-lg); line-height: var(--lh-body-lg);
}

/* Toast */
.toast-region { position: fixed; left: var(--space-7); bottom: var(--space-7); z-index: 50; display: flex; flex-direction: column; gap: var(--space-3); max-width: min(440px, calc(100vw - 2 * var(--space-5))); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-4);
  background: var(--toast-bg); color: var(--toast-fg); box-shadow: var(--shadow-e2);
  border-radius: var(--radius-lg); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
  font-size: var(--fs-body-lg); line-height: var(--lh-body-lg);
  animation: toast-in var(--motion-base) var(--ease-standard);
}
.toast p { margin: 0; flex: 1 1 180px; }
.toast .toast-action {
  min-height: 40px; padding: 0 var(--space-4); border: 0; border-radius: var(--radius-md); cursor: pointer;
  background: transparent; color: var(--toast-fg); font: inherit; font-weight: 600; text-decoration: underline;
}
.toast .toast-action:focus-visible { outline-color: var(--focus-ring); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Empty state */
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-5); padding: var(--space-8) 0; }
.empty p { margin: 0; }

/* Skeleton */
.skeleton { background: var(--skeleton); border-radius: var(--radius-sm); }
.skeleton-line { height: 12px; }

/* Avatar */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: var(--radius-full);
  background: var(--bg-selected); color: var(--text-primary);
  font-size: var(--fs-label); line-height: 1; font-weight: 600;
}

/* Spinner (inline) */
.spinner { width: 14px; height: 14px; border-radius: var(--radius-full); border: 2px solid currentColor; border-right-color: transparent; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Reduced motion: transitions collapse to short fades, animations stop */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
  .toast { animation: none !important; }
  .spinner { animation: none !important; border-right-color: currentColor; opacity: .6; }
}
