@import 'tailwindcss';

@theme {
  --color-bg: #ffffff;
  --color-surface: #fafafa;
  --color-elevated: #ffffff;
  --color-border: rgba(10, 10, 10, 0.08);
  --color-border-strong: rgba(10, 10, 10, 0.14);
  --color-ink: #0a0a0a;
  --color-muted: #6b7280;
  --color-subtle: #9ca3af;
  --color-accent: #2563eb;
  --color-accent-soft: #eff6ff;
  --color-success: #16a34a;
  --color-success-soft: #f0fdf4;
  --color-danger: #dc2626;
  --color-danger-soft: #fef2f2;

  --color-on-ink: #ffffff;
  --color-ink-hover: #1f1f1f;
  --color-accent-hover: #1d4ed8;

  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif;
}

:root {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --color-bg: #0a0a0a;
    --color-surface: #141414;
    --color-elevated: #1a1a1a;
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-strong: rgba(255, 255, 255, 0.14);
    --color-ink: #ededed;
    --color-muted: #a1a1aa;
    --color-subtle: #71717a;
    --color-accent: #3b82f6;
    --color-accent-soft: rgba(59, 130, 246, 0.12);
    --color-success: #22c55e;
    --color-success-soft: rgba(34, 197, 94, 0.12);
    --color-danger: #ef4444;
    --color-danger-soft: rgba(239, 68, 68, 0.12);
    --color-on-ink: #0a0a0a;
    --color-ink-hover: #d4d4d4;
    --color-accent-hover: #60a5fa;
    --color-log-bg: #111111;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-sans);
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.modal-open {
  overflow: hidden;
}

::selection {
  background-color: color-mix(in srgb, var(--color-accent) 22%, transparent);
}

/* ----- form primitives ----- */

.field-input {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-ink);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.field-input::placeholder {
  color: var(--color-subtle);
}

.field-input:hover:not(:focus):not(:disabled) {
  border-color: var(--color-border-strong);
}

.field-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 18%, transparent);
}

.field-input:disabled {
  background: var(--color-surface);
  color: var(--color-muted);
  cursor: not-allowed;
}

.field-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ----- buttons ----- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease,
    transform 0.05s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--color-ink-hover);
}

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

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

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

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

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 8px;
}

/* ----- segmented nav ----- */

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.seg-btn {
  height: 32px;
  padding: 0 14px;
  border-radius: 7px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.seg-btn:hover {
  color: var(--color-ink);
}

.seg-btn[data-active='true'] {
  background: var(--color-elevated);
  color: var(--color-ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ----- card ----- */

.card {
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-elevated);
}

.card-pad {
  padding: 22px;
}

@media (min-width: 640px) {
  .card-pad {
    padding: 26px;
  }
}

/* ----- stepper (Cookey-style horizontal) ----- */

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.stepper-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 72px;
}

.stepper-marker {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  min-width: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.stepper-step[data-state='active'] .stepper-marker {
  background: var(--color-ink);
  color: var(--color-on-ink);
  border-color: var(--color-ink);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-ink) 6%, transparent);
}

.stepper-step[data-state='active'] .stepper-marker::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--color-ink) 18%, transparent);
  animation: pulse-ring 1.8s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  pointer-events: none;
}

.stepper-step[data-state='done'] .stepper-marker {
  background: var(--color-success-soft);
  color: var(--color-success);
  border-color: color-mix(in srgb, var(--color-success) 28%, transparent);
}

.stepper-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-muted);
  letter-spacing: 0.01em;
}

.stepper-step[data-state='active'] .stepper-label {
  color: var(--color-ink);
}

.stepper-step[data-state='done'] .stepper-label {
  color: var(--color-success);
}

.stepper-bar {
  flex: 0 0 36px;
  height: 1px;
  background: var(--color-border);
  margin: 0 4px;
  margin-bottom: 26px;
  transition: background-color 0.3s ease;
}

@media (min-width: 480px) {
  .stepper-bar {
    flex-basis: 56px;
  }
}

.stepper-bar[data-done='true'] {
  background: rgba(22, 163, 74, 0.4);
}

@keyframes pulse-ring {
  0%,
  100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 0;
    transform: scale(1.18);
  }
}

/* ----- drop zone ----- */

.drop-zone {
  display: block;
  cursor: pointer;
  padding: 26px 18px;
  text-align: center;
  border: 1.5px dashed var(--color-border-strong);
  border-radius: 12px;
  background: var(--color-surface);
  transition: border-color 0.18s ease, background-color 0.18s ease, transform 0.18s ease;
}

.drop-zone:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.drop-zone.dragover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
  transform: scale(1.01);
}

/* ----- progress bar ----- */

.progress-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--color-surface);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.progress-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: var(--color-ink);
  border-radius: 999px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-fill[data-busy='true']::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* ----- log ----- */

pre.log {
  margin: 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--color-log-bg, #0a0a0a);
  color: #e5e7eb;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

pre.log::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

pre.log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

pre.log::-webkit-scrollbar-track {
  background: transparent;
}

/* ----- modal ----- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 10, 10, 0.32);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.modal.open {
  display: flex;
  opacity: 1;
}

.modal-panel {
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-elevated);
  padding: 22px;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.2);
  transform: translateY(8px) scale(0.98);
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease;
}

.modal.open .modal-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ----- pill / chip ----- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--color-muted);
  letter-spacing: 0.01em;
}

.chip[data-tone='success'] {
  background: var(--color-success-soft);
  border-color: color-mix(in srgb, var(--color-success) 22%, transparent);
  color: var(--color-success);
}

.chip[data-tone='accent'] {
  background: var(--color-accent-soft);
  border-color: color-mix(in srgb, var(--color-accent) 22%, transparent);
  color: var(--color-accent);
}

/* ----- account row ----- */

.acct-row {
  position: relative;
  padding: 12px 14px 12px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: background-color 0.15s ease;
}

.acct-row:hover {
  background: var(--color-surface);
}

.acct-row[data-active='true'] {
  background: var(--color-surface);
}

.acct-row[data-active='true']::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  border-radius: 2px;
  background: var(--color-ink);
}

/* ----- spinner ----- */

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* ----- entrance animations ----- */

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.anim-in {
  animation: fade-in-up 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ----- dark mode component overrides ----- */

@media (prefers-color-scheme: dark) {
  .field-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23a1a1aa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  }

  .modal {
    background: rgba(0, 0, 0, 0.55);
  }
}
