@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
  --bg-main: #f4f3ef;
  --bg-surface: #ffffff;
  --bg-elevated: #eae8e1;
  --bg-inset: #e2dfd7;
  --text-primary: #141518;
  --text-muted: #555a64;
  --border-subtle: #d6d3ca;
  --border-strong: #b4b0a4;
  --accent-color: #d9381e;
  --accent-hover: #b82b14;
  --accent-soft: rgba(217, 56, 30, 0.1);
  --status-ok: #15803d;
  --status-ok-soft: rgba(21, 128, 61, 0.12);
  --status-warn: #b45309;
  --status-warn-soft: rgba(180, 83, 9, 0.12);
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
  --radius-sm: 4px;
  --radius-md: 8px;
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --topbar-h: 56px;
  --bottombar-h: 64px;
}

[data-theme="dark"] {
  --bg-main: #0d0f12;
  --bg-surface: #15181e;
  --bg-elevated: #1c2028;
  --bg-inset: #232833;
  --text-primary: #f1f3f6;
  --text-muted: #98a0ac;
  --border-subtle: #282e39;
  --border-strong: #3d4656;
  --accent-color: #ef442a;
  --accent-hover: #ff5b42;
  --accent-soft: rgba(239, 68, 42, 0.15);
  --status-ok: #22c55e;
  --status-ok-soft: rgba(34, 197, 94, 0.15);
  --status-warn: #f59e0b;
  --status-warn-soft: rgba(245, 158, 11, 0.15);
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 200ms var(--ease-spring), color 200ms var(--ease-spring);
}

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

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

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

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

#section-stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  position: relative;
}

#section-stage.stage-locked {
  overflow: hidden;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: 0 var(--sp-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms var(--ease-spring), background-color 160ms var(--ease-spring), border-color 160ms var(--ease-spring);
}

.btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.975);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

.btn-sm {
  min-height: 32px;
  padding: 0 var(--sp-3);
  font-size: 12px;
}

.segmented {
  display: inline-flex;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--sp-1);
  gap: var(--sp-1);
}

.segmented-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  min-height: 32px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 140ms var(--ease-spring), background-color 140ms var(--ease-spring), color 140ms var(--ease-spring);
}

.segmented-btn:active {
  transform: scale(0.97);
}

.segmented-btn.is-active {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-primary);
  font-weight: 600;
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  min-height: 40px;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  color: var(--text-primary);
  transition: border-color 150ms var(--ease-spring);
}

.field-textarea {
  min-height: 96px;
}

.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  border-color: var(--accent-color);
  outline: none;
}

h1, h2, h3 {
  font-family: var(--font-display);
  margin: 0;
  letter-spacing: -0.02em;
}

h1 { font-size: 22px; font-weight: 700; line-height: 1.2; }
h2 { font-size: 16px; font-weight: 600; line-height: 1.3; }
h3 { font-size: 14px; font-weight: 600; line-height: 1.35; }

/* 4-State UI Helpers (Skeleton, Empty, Error, Stagger Entrance) */
.skeleton-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.skeleton-line {
  height: 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  position: relative;
  overflow: hidden;
}

.skeleton-line::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translate3d(-100%, 0, 0);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  100% { transform: translate3d(100%, 0, 0); }
}

.state-box {
  padding: var(--sp-6);
  background: var(--bg-main);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-3);
}

.state-box.is-error {
  border-color: var(--accent-color);
  background: var(--accent-soft);
}

.stagger-in {
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  animation: enterUp 320ms var(--ease-spring) forwards;
}

@keyframes enterUp {
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

/* Toast Notifications with Swipe Dismiss */
.toast-stack {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 90;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  min-width: 240px;
  max-width: 340px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent-color);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  transform: translate3d(0, 12px, 0);
  opacity: 0;
  transition: transform 240ms var(--ease-spring), opacity 200ms ease;
  touch-action: pan-x;
}

.toast-item.is-visible {
  transform: translate3d(0, 0, 0);
  opacity: 1;
}

.toast-item.is-ok {
  border-left-color: var(--status-ok);
}

@media (max-width: 768px) {
  .btn,
  .icon-btn,
  .segmented-btn,
  .field-input,
  .field-select {
    min-height: 44px;
  }

  #section-stage.stage-locked {
    overflow-y: auto;
  }

  .toast-stack {
    bottom: calc(var(--bottombar-h) + var(--sp-3));
    right: var(--sp-3);
    left: var(--sp-3);
  }

  .toast-item {
    max-width: none;
  }
}
