/**
 * Base Styles - Aurora Mint Design System
 *
 * Uses only CSS tokens from tokens.css. No hardcoded values.
 * Enforces 4px grid system for all spacing.
 */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--type-body-3-size);
  line-height: var(--type-body-3-line-height);
  font-weight: var(--type-body-3-weight);
  color: var(--text-primary);
  background-color: var(--surface-page);
  background-image: none;
  overflow: hidden;
}

#root {
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

/* ========== Typography ========== */
h1 {
  font-size: var(--type-heading-1-size);
  line-height: var(--type-heading-1-line-height);
  font-weight: var(--type-heading-1-weight);
  color: var(--text-primary);
}
h2 {
  font-size: var(--type-heading-2-size);
  line-height: var(--type-heading-2-line-height);
  font-weight: var(--type-heading-2-weight);
  color: var(--text-primary);
}
h3 {
  font-size: var(--type-heading-3-size);
  line-height: var(--type-heading-3-line-height);
  font-weight: var(--type-heading-3-weight);
  color: var(--text-primary);
}
h4 {
  font-size: var(--type-heading-4-size);
  line-height: var(--type-heading-4-line-height);
  font-weight: var(--type-heading-4-weight);
  color: var(--text-primary);
}
h5 {
  font-size: var(--type-heading-5-size);
  line-height: var(--type-heading-5-line-height);
  font-weight: var(--type-heading-5-weight);
  color: var(--text-primary);
}
h6 {
  font-size: var(--type-heading-6-size);
  line-height: var(--type-heading-6-line-height);
  font-weight: var(--type-heading-6-weight);
  color: var(--text-primary);
}

p {
  color: var(--text-secondary);
  line-height: var(--type-body-3-line-height);
}

.page-kicker,
.section-kicker,
.section-title {
  font-size: var(--type-body-6-size);
  line-height: var(--type-body-6-line-height);
  font-weight: var(--type-body-6-weight);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

.page-title {
  font-size: var(--type-heading-1-size);
  line-height: var(--type-heading-1-line-height);
  font-weight: var(--type-heading-1-weight);
  color: var(--text-primary);
}

.meta-text {
  font-size: var(--type-body-5-size);
  line-height: var(--type-body-5-line-height);
  font-weight: var(--type-body-5-weight);
  color: var(--text-secondary);
}

.hint-text {
  font-size: var(--type-body-5-size);
  line-height: var(--type-body-5-line-height);
  font-weight: var(--type-body-5-weight);
  color: var(--text-muted);
}

.mono-meta {
  color: var(--text-muted);
}

.mono-meta,
code,
pre,
kbd,
samp {
  font-family: var(--font-mono);
  font-size: var(--type-body-5-size);
  line-height: var(--type-body-5-line-height);
  font-weight: var(--type-body-5-weight);
}

code {
  background-color: var(--surface-hover);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
}

pre {
  background-color: var(--surface-panel);
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

/* ========== Links ========== */
a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--text-link-hover);
}

/* ========== Focus States ========== */
:focus {
  outline: none;
}

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

/* ========== Selection ========== */
::selection {
  background-color: var(--text-link);
  color: var(--text-inverse);
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
  width: var(--scrollbar-width);
  height: var(--scrollbar-width);
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-track-piece,
::-webkit-scrollbar-button,
::-webkit-scrollbar-corner {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-focus);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* ========== Buttons Base ========== */
button {
  font-family: var(--font-sans);
  font-size: var(--type-body-3-size);
  line-height: var(--type-body-3-line-height);
  font-weight: var(--type-body-3-weight);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== Input Base ========== */
input,
textarea,
select {
  font-family: var(--font-sans);
  font-size: var(--type-body-3-size);
  line-height: var(--type-body-3-line-height);
  font-weight: var(--type-body-3-weight);
  color: var(--text-primary);
  background-color: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  transition: border-color var(--duration-fast) var(--ease-out);
}

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

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

/* ========== Utility Classes ========== */

/* Flex utilities */
.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.flex-1 {
  flex: 1;
}
.items-center {
  align-items: center;
}
.items-start {
  align-items: flex-start;
}
.items-end {
  align-items: flex-end;
}
.justify-center {
  justify-content: center;
}
.justify-between {
  justify-content: space-between;
}
.justify-end {
  justify-content: flex-end;
}
.gap-1 {
  gap: var(--sp-1);
}
.gap-2 {
  gap: var(--sp-2);
}
.gap-3 {
  gap: var(--sp-3);
}
.gap-4 {
  gap: var(--sp-4);
}
.gap-6 {
  gap: var(--sp-6);
}

/* Text utilities */
.text-primary {
  color: var(--text-primary);
}
.text-secondary {
  color: var(--text-secondary);
}
.text-tertiary {
  color: var(--text-tertiary);
}
.text-success {
  color: var(--status-success-fg);
}
.text-warning {
  color: var(--status-warning-fg);
}
.text-error {
  color: var(--status-danger-fg);
}

/* Icon utilities */
.icon-tone-primary,
.themed-icon--tone-primary {
  color: var(--icon-primary);
}

.icon-tone-secondary,
.themed-icon--tone-secondary {
  color: var(--icon-secondary);
}

.icon-tone-muted,
.themed-icon--tone-muted {
  color: var(--icon-muted);
}

.icon-tone-accent,
.themed-icon--tone-accent {
  color: var(--icon-accent);
}

.icon-tone-success,
.themed-icon--tone-success {
  color: var(--icon-success);
}

.icon-tone-warning,
.themed-icon--tone-warning {
  color: var(--icon-warning);
}

.icon-tone-error,
.themed-icon--tone-error {
  color: var(--icon-error);
}

.icon-tone-info,
.themed-icon--tone-info {
  color: var(--icon-info);
}

.themed-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.themed-icon--tone-current {
  color: currentColor;
}

.themed-icon--tone-file-folder {
  color: var(--icon-file-folder);
}

.themed-icon--tone-file-code {
  color: var(--icon-file-code);
}

.themed-icon--tone-file-data {
  color: var(--icon-file-data);
}

.themed-icon--tone-file-doc {
  color: var(--icon-file-doc);
}

.themed-icon--tone-file-media {
  color: var(--icon-file-media);
}

.themed-icon--tone-file-default {
  color: var(--icon-file-default);
}

.themed-icon--tone-git-staged {
  color: var(--icon-git-staged);
}

.themed-icon--tone-git-modified {
  color: var(--icon-git-modified);
}

.themed-icon--tone-git-deleted {
  color: var(--icon-git-deleted);
}

.themed-icon--tone-git-untracked {
  color: var(--icon-git-untracked);
}

.icon-surface-subtle,
.themed-icon--surface-subtle {
  background: var(--icon-surface-subtle);
}

.icon-surface-accent,
.themed-icon--surface-accent {
  background: var(--icon-surface-accent);
}

.icon-surface-success,
.themed-icon--surface-success {
  background: var(--icon-surface-success);
}

.icon-surface-warning {
  background: var(--icon-surface-warning);
}

.themed-icon--surface-warning {
  background: var(--icon-surface-warning);
}

.icon-surface-error,
.themed-icon--surface-error {
  background: var(--icon-surface-error);
}

.icon-surface-info,
.themed-icon--surface-info {
  background: var(--icon-surface-info);
}

.themed-icon--surface-none {
  background: transparent;
}

.icon-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-control);
}

.themed-icon--surface-subtle,
.themed-icon--surface-accent,
.themed-icon--surface-success,
.themed-icon--surface-warning,
.themed-icon--surface-error,
.themed-icon--surface-info {
  border-radius: var(--radius-md);
}

.themed-icon--surface-info {
  background: var(--icon-surface-info);
  border-radius: var(--radius-md);
}

/* Spacing utilities (using 4px grid) */
.p-1 {
  padding: var(--sp-1);
}
.p-2 {
  padding: var(--sp-2);
}
.p-3 {
  padding: var(--sp-3);
}
.p-4 {
  padding: var(--sp-4);
}
.p-6 {
  padding: var(--sp-6);
}
.p-8 {
  padding: var(--sp-8);
}

.m-0 {
  margin: 0;
}
.m-1 {
  margin: var(--sp-1);
}
.m-2 {
  margin: var(--sp-2);
}
.m-3 {
  margin: var(--sp-3);
}
.m-4 {
  margin: var(--sp-4);
}

/* Size utilities */
.w-full {
  width: 100%;
}
.h-full {
  height: 100%;
}
.min-h-screen {
  min-height: 100vh;
}

/* Overflow */
.overflow-hidden {
  overflow: hidden;
}
.overflow-auto {
  overflow: auto;
}
.overflow-x-auto {
  overflow-x: auto;
}
.overflow-y-auto {
  overflow-y: auto;
}

/* Position */
.relative {
  position: relative;
}
.absolute {
  position: absolute;
}
.fixed {
  position: fixed;
}
.sticky {
  position: sticky;
}

/* Display */
.hidden {
  display: none;
}
.block {
  display: block;
}
.inline {
  display: inline;
}
.inline-block {
  display: inline-block;
}

/* Cursor */
.cursor-pointer {
  cursor: pointer;
}
.cursor-not-allowed {
  cursor: not-allowed;
}

/* Opacity */
.opacity-50 {
  opacity: 0.5;
}
.opacity-75 {
  opacity: 0.75;
}

/* Transitions */
.transition-all {
  transition: all var(--duration-normal) var(--ease-out);
}

.transition-colors {
  transition:
    color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

/* ========== Animation Keyframes ========== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(var(--sp-4));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(calc(-1 * var(--sp-4)));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Animation utilities */
.animate-fadeIn {
  animation: fadeIn var(--duration-normal) var(--ease-out);
}
.animate-slideInUp {
  animation: slideInUp var(--duration-slow) var(--ease-out);
}
.animate-spin {
  animation: spin 1s linear infinite;
}
.animate-pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* ========== App Shell ========== */
.app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface-page);
  color: var(--text-primary);
  overflow: hidden;
  isolation: isolate;
}

.app::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image: var(--app-bg-image, none);
  background-position: center;
  background-repeat: no-repeat;
  background-size: var(--app-bg-fit, cover);
  filter: blur(var(--app-bg-blur, 0px));
  transform: scale(1.04);
  pointer-events: none;
}

.app::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--surface-page);
  opacity: var(--app-bg-dim, 0);
  pointer-events: none;
}

.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  background: var(--status-warning-fg);
  color: var(--text-inverse);
  font-size: var(--type-body-6-size);
  line-height: var(--type-body-6-line-height);
  font-weight: var(--type-body-6-weight);
  z-index: var(--z-toast);
}

.connection-banner__primary,
.connection-banner__hint {
  min-width: 0;
}

.connection-banner__hint {
  opacity: 0.88;
}

.connection-banner--mobile {
  min-height: calc(var(--sp-6) + var(--mobile-safe-top));
  padding-top: var(--mobile-safe-top);
  padding-right: calc(var(--mobile-safe-right) + var(--sp-3));
  padding-left: calc(var(--mobile-safe-left) + var(--sp-3));
}

.connection-banner--stacked {
  height: auto;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--gap-control);
  padding-top: calc(var(--mobile-safe-top) + var(--sp-1));
  padding-right: calc(var(--mobile-safe-right) + var(--sp-3));
  padding-bottom: var(--sp-1);
  padding-left: calc(var(--mobile-safe-left) + var(--sp-3));
}

.connection-banner--stacked .connection-banner__primary,
.connection-banner--stacked .connection-banner__hint {
  width: 100%;
  text-align: left;
  overflow-wrap: anywhere;
}

.connection-banner--error {
  background: var(--status-danger-fg);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-loading-shell {
  flex: 1;
  display: grid;
  place-items: center;
  padding: var(--sp-8);
  background: var(--material-shell-page);
  backdrop-filter: var(--material-backdrop-filter);
}

.app-loading-card {
  width: min(520px, 100%);
  padding: var(--sp-8);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-overlay);
  background: var(--material-overlay);
  backdrop-filter: var(--material-backdrop-filter);
  box-shadow: var(--surface-overlay-shadow);
}

.app-loading-kicker {
  margin-bottom: var(--sp-3);
  color: var(--text-tertiary);
  font-size: var(--type-body-6-size);
  line-height: var(--type-body-6-line-height);
  font-weight: var(--type-body-6-weight);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-loading-title {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--type-heading-1-size);
  line-height: var(--type-heading-1-line-height);
  font-weight: var(--type-heading-1-weight);
  letter-spacing: -0.03em;
}

.app-loading-desc {
  margin-top: var(--sp-3);
  color: var(--text-secondary);
  font-size: var(--type-body-3-size);
  line-height: var(--type-body-3-line-height);
  font-weight: var(--type-body-3-weight);
  max-width: 42ch;
}
