/* ============================================================
   Apple Design System — Shared Design Tokens & Base Styles
   Based on Apple HIG: typography, materials, motion, color
   ============================================================ */

/* ----- Design Tokens ----- */
:root {
  /* == Color: Accent (Apple Blue) == */
  --color-accent: #007AFF;
  --color-accent-hover: #0062CC;
  --color-accent-pressed: #004999;
  --color-accent-subtle: rgba(0, 122, 255, 0.12);

  /* == Color: System Backgrounds == */
  --color-bg-primary: #f2f2f7;
  --color-bg-secondary: #ffffff;
  --color-bg-tertiary: #f9f9f9;
  --color-bg-elevated: #ffffff;

  /* == Color: Materials (translucent) == */
  --material-header: rgba(255, 255, 255, 0.72);
  --material-input-bar: rgba(255, 255, 255, 0.88);
  --material-card: rgba(255, 255, 255, 0.76);
  --material-sidebar: rgba(248, 248, 252, 0.80);
  --material-scrim: rgba(0, 0, 0, 0.38);

  /* == Color: Labels (text) == */
  --color-label-primary: #1d1d1f;
  --color-label-secondary: #86868b;
  --color-label-tertiary: #aeaeb2;
  --color-label-quaternary: #c7c7cc;
  --color-label-on-accent: #ffffff;

  /* == Color: Chat Bubbles == */
  --bubble-self: #007AFF;
  --bubble-self-text: #ffffff;
  --bubble-other: #e9e9eb;
  --bubble-other-text: #1d1d1f;

  /* == Color: Semantic == */
  --color-success: #34C759;
  --color-warning: #FF9500;
  --color-danger: #FF3B30;
  --color-online: #34C759;
  --color-offline: #FF3B30;
  --color-unread: #FF3B30;

  /* == Color: Separators == */
  --color-separator: rgba(60, 60, 67, 0.12);
  --color-separator-opaque: #e5e5ea;

  /* == Depth: Shadows == */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.18);

  /* == Blur (materials) == */
  --blur-header: saturate(180%) blur(20px);
  --blur-card: saturate(160%) blur(16px);
  --blur-input: saturate(200%) blur(24px);

  /* == Radius == */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* == Spacing == */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* == Typography == */
  --font-system: -apple-system, BlinkMacSystemFont, 'SF Pro Text',
                 'Helvetica Neue', 'PingFang SC', 'Noto Sans SC',
                 'Microsoft YaHei', sans-serif;
  --font-system-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display',
                         'Helvetica Neue', 'PingFang SC', sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;

  /* Sizes */
  --text-caption2: 11px;
  --text-caption1: 12px;
  --text-footnote: 13px;
  --text-subheadline: 15px;
  --text-body: 17px;
  --text-title3: 20px;
  --text-title2: 22px;
  --text-title1: 28px;

  /* Weights */
  --weight-regular: 400;
  --weight-medium: 510;
  --weight-semibold: 590;
  --weight-bold: 700;

  /* Leading */
  --leading-tight: 1.15;
  --leading-normal: 1.4;
  --leading-relaxed: 1.6;

  /* == Duration == */
  --duration-instant: 0.1s;
  --duration-fast: 0.2s;
  --duration-normal: 0.3s;
  --duration-slow: 0.5s;

  /* == Easings (cubic-bezier fallbacks when no springs) == */
  --ease-default: cubic-bezier(0.25, 0.1, 0.25, 1.0);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0, 0, 0.58, 1);
  --ease-in: cubic-bezier(0.42, 0, 1, 1);
}

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

html {
  font-family: var(--font-system);
  font-size: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  color: var(--color-label-primary);
  background-color: var(--color-bg-primary);
  font-family: var(--font-system);
}

/* ----- Typography Presets ----- */
.title1 {
  font-size: var(--text-title1);
  font-weight: var(--weight-bold);
  letter-spacing: -0.024em;
  line-height: var(--leading-tight);
}

.title2 {
  font-size: var(--text-title2);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.022em;
  line-height: var(--leading-tight);
}

.title3 {
  font-size: var(--text-title3);
  font-weight: var(--weight-medium);
  letter-spacing: -0.018em;
  line-height: var(--leading-tight);
}

.body {
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  letter-spacing: -0.01em;
  line-height: var(--leading-normal);
}

.subheadline {
  font-size: var(--text-subheadline);
  font-weight: var(--weight-regular);
  letter-spacing: -0.008em;
  line-height: var(--leading-normal);
}

.footnote {
  font-size: var(--text-footnote);
  font-weight: var(--weight-regular);
  letter-spacing: 0;
  line-height: var(--leading-normal);
}

.caption1 {
  font-size: var(--text-caption1);
  font-weight: var(--weight-regular);
  letter-spacing: 0;
  line-height: var(--leading-normal);
}

.caption2 {
  font-size: var(--text-caption2);
  font-weight: var(--weight-regular);
  letter-spacing: 0.004em;
  line-height: 1.3;
}

/* ----- Press Feedback (instant pointer-down response) ----- */
.btn-press {
  transition: transform var(--duration-instant) var(--ease-default),
              opacity var(--duration-instant) var(--ease-default);
}
.btn-press:active {
  transform: scale(0.97);
}

/* ----- Focus Ring (Apple-style) ----- */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ----- Scrollbar (thin, Apple-style) ----- */
::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.28);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}

/* ----- Material Surface Mixins (applied as classes) ----- */
.material-header {
  background: var(--material-header);
  -webkit-backdrop-filter: var(--blur-header);
  backdrop-filter: var(--blur-header);
  border-bottom: 1px solid var(--color-separator);
}

.material-input-bar {
  background: var(--material-input-bar);
  -webkit-backdrop-filter: var(--blur-input);
  backdrop-filter: var(--blur-input);
  border-top: 1px solid var(--color-separator);
}

.material-card {
  background: var(--material-card);
  -webkit-backdrop-filter: var(--blur-card);
  backdrop-filter: var(--blur-card);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: var(--shadow-md);
}

.material-sidebar {
  background: var(--material-sidebar);
  -webkit-backdrop-filter: var(--blur-card);
  backdrop-filter: var(--blur-card);
}

/* ----- Accessibility: Reduced Motion ----- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.15s !important;
  }

  .btn-press:active {
    transform: none;
  }

  .copy-btn:active {
    transform: none;
  }
}

/* ----- Accessibility: Reduced Transparency ----- */
@media (prefers-reduced-transparency: reduce) {
  .material-header,
  .material-input-bar,
  .material-card,
  .material-sidebar {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .material-header {
    background: var(--color-bg-secondary);
  }

  .material-input-bar {
    background: var(--color-bg-secondary);
  }

  .material-card {
    background: var(--color-bg-secondary);
  }

  .material-sidebar {
    background: var(--color-bg-secondary);
  }
}

/* ----- Accessibility: Increased Contrast ----- */
@media (prefers-contrast: more) {
  :root {
    --material-header: rgba(255, 255, 255, 0.95);
    --material-input-bar: rgba(255, 255, 255, 0.98);
    --material-card: rgba(255, 255, 255, 0.92);
    --color-separator: rgba(60, 60, 67, 0.3);
  }
}

/* ----- Utility: sr-only ----- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
