/* ============================================================
   HueGrid — design-system.css
   Single source of truth for all visual tokens.
   Import in every HTML file. No component-specific rules here.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600&family=DM+Sans:wght@300;400;500&display=swap');

/* ── Color Tokens ─────────────────────────────────────────── */
:root {
  --bg:              #0e0e0e;
  --surface:         #1a1a1a;
  --surface-raised:  #222222;
  --border:          #2a2a2a;
  --border-focus:    #c8a96e;
  --accent:          #c8a96e;
  --accent-dim:      rgba(200, 169, 110, 0.12);
  --text-primary:    #f0ede8;
  --text-secondary:  #8a8680;
  --text-inverse:    #0e0e0e;
  --success:         #4caf50;
  --danger:          #c0392b;
  --warning:         #e6a817;

  /* ── Border Radius ─────────────────────────────────────── */
  --radius-input:    6px;
  --radius-btn:      4px;
  --radius-card:     8px;
  --radius-modal:    10px;
  --radius-pill:     99px;

  /* ── Spacing Scale (multiples of 8px) ──────────────────── */
  --space-8:   8px;
  --space-16:  16px;
  --space-24:  24px;
  --space-32:  32px;
  --space-48:  48px;
  --space-64:  64px;
  --space-96:  96px;

  /* ── Typography ─────────────────────────────────────────── */
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-ui:      'DM Sans', system-ui, sans-serif;

  /* ── Transitions ─────────────────────────────────────────── */
  --transition: all 0.2s ease;

  /* ── Shadows ─────────────────────────────────────────────── */
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-focus: 0 0 0 2px rgba(200, 169, 110, 0.15);
}

/* ── Base Reset ───────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

button {
  cursor: pointer;
  font-family: var(--font-ui);
  border: none;
  background: none;
}

input, select, textarea {
  font-family: var(--font-ui);
  font-size: 16px; /* prevents iOS auto-zoom */
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: var(--space-8) var(--space-16);
  width: 100%;
  outline: none;
  transition: var(--transition);
  box-shadow: var(--shadow-card);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

/* Keyboard-only focus visible on buttons */
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.nav-item:focus-visible,
.mc-option:focus-visible,
.cb-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c8a96e' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

option {
  background: var(--surface);
  color: var(--text-primary);
}

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

a:hover {
  opacity: 0.8;
}

/* ── Button Variants ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 500;
  border-radius: var(--radius-btn);
  padding: 12px var(--space-24);
  min-height: 48px;
  transition: var(--transition);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
}

.btn:disabled,
.btn--loading {
  pointer-events: none;
  opacity: 0.6;
}

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

.btn--primary:hover:not(:disabled) {
  background: #d4b87e;
  border-color: #d4b87e;
}

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

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

.btn--destructive {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn--destructive:hover:not(:disabled) {
  background: rgba(192, 57, 43, 0.1);
}

.btn--sm {
  font-size: 13px;
  padding: 8px var(--space-16);
  min-height: 36px;
}

/* Loading state — spinner replaces text */
.btn--loading .btn-text {
  opacity: 0;
}

.btn--loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* ── Badge ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1;
  min-height: 20px;
}

.badge--success  { background: rgba(76,175,80,0.15);  color: var(--success); }
.badge--warning  { background: rgba(230,168,23,0.15); color: var(--warning); }
.badge--danger   { background: rgba(192,57,43,0.15);  color: var(--danger); }
.badge--muted    { background: rgba(138,134,128,0.15);color: var(--text-secondary); }
.badge--accent   { background: var(--accent-dim);     color: var(--accent); }

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  border: 2px solid rgba(200,169,110,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner--sm  { width: 16px; height: 16px; }
.spinner--md  { width: 32px; height: 32px; border-width: 3px; }
.spinner--lg  { width: 48px; height: 48px; border-width: 3px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  .slide,
  .toast,
  .btn,
  input, select, textarea {
    transition: none !important;
  }
  .slide-exit-left,
  .slide-exit-right,
  .slide-enter-left,
  .slide-enter-right {
    transform: none !important;
  }
  .spinner {
    animation-duration: 1.5s;
  }
}

/* ── Toast System ─────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-24);
  right: var(--space-24);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-8);
  padding: var(--space-16);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  max-width: 360px;
  min-width: 280px;
  pointer-events: all;
  animation: toast-in 0.25s ease forwards;
  border-left: 3px solid var(--border);
  font-size: 14px;
  line-height: 1.5;
}

.toast.dismissing {
  animation: toast-out 0.25s ease forwards;
}

.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }

.toast__message {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-primary);
}

.toast__actions {
  display: flex;
  gap: var(--space-8);
  margin-top: 8px;
}

.toast__btn {
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-ui);
  padding: 4px 10px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  transition: var(--transition);
}

.toast__btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.toast__close {
  font-size: 16px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  flex-shrink: 0;
  transition: var(--transition);
  font-family: var(--font-ui);
}

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

@keyframes toast-in {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateY(0);    opacity: 1; }
  to   { transform: translateY(16px); opacity: 0; }
}

/* ── Modal System ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-16);
  animation: modal-fade-in 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-modal);
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

.modal__header {
  padding: var(--space-24) var(--space-24) var(--space-16);
}

.modal__title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal__body {
  padding: 0 var(--space-24) var(--space-24);
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal__actions {
  padding: var(--space-16) var(--space-24) var(--space-24);
  display: flex;
  gap: var(--space-8);
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (max-width: 480px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-width: 100vw;
    width: 100vw;
    border-radius: var(--radius-modal) var(--radius-modal) 0 0;
  }
}

/* ── Form Field Helpers ───────────────────────────────────── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.field-error {
  font-size: 13px;
  color: var(--danger);
  font-family: var(--font-ui);
  display: none;
}

.field-error.visible {
  display: block;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-16);
}

@media (max-width: 480px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

/* ── Divider ──────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-24) 0;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.font-display { font-family: var(--font-display); }
.font-ui { font-family: var(--font-ui); }

/* Forced colors / Windows High Contrast mode */
@media (forced-colors: active) {
  .btn--primary {
    border: 2px solid ButtonText;
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
  .mc-option--selected, .cb-option--selected {
    border: 2px solid Highlight;
    forced-color-adjust: none;
  }
  .badge, .nav-badge {
    border: 1px solid ButtonText;
  }
}
