/* ════════════════════════════════════════════════════
   uTrain — Global Styles
   Precision Dark design system
   ════════════════════════════════════════════════════ */

@import url('./tokens.css');

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

/* ── Base ── */
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.5;
  padding-bottom: calc(var(--nav-height) + 20px);
  font-size: var(--text-base);
}

/* Subtle atmospheric gradient */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(200, 255, 0, 0.015), transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(255, 255, 255, 0.008), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ── Header ── */
header {
  position: relative;
  z-index: 1;
  padding: var(--space-5) var(--space-5) var(--space-4);
  width: 100%;
  max-width: var(--max-width);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

header h1 span {
  color: var(--accent);
}

/* ── Auth UI ── */
.auth-section {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.auth-section.hidden {
  display: none;
}

.auth-user {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-short) var(--ease-snappy);
  font-family: var(--font-body);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  transition: all var(--duration-short) var(--ease-snappy);
  font-family: var(--font-body);
  min-height: var(--touch-target);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-btn-hover);
  filter: brightness(1.05);
}

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

.btn-secondary {
  background: var(--bg-surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-short) var(--ease-snappy);
  font-family: var(--font-body);
}

.btn-secondary:hover {
  background: var(--bg-surface-3);
  border-color: var(--border-active);
  box-shadow: var(--shadow-btn-hover);
  filter: brightness(1.05);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-tertiary);
  border: none;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: color var(--duration-short);
  font-family: var(--font-body);
}

.btn-ghost:hover {
  color: var(--text-secondary);
}

.auth-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--bg-surface-1);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-short) var(--ease-snappy);
  font-family: var(--font-body);
}

.auth-btn:hover {
  background: var(--bg-surface-3);
}

.auth-btn.primary {
  background: var(--accent);
  color: var(--text-inverse);
  border: none;
  font-weight: 700;
}

.auth-btn.primary:hover {
  background: var(--accent-hover);
}

.auth-btn:active, .auth-btn.primary:active {
  transform: scale(0.97);
}

/* ── Auth Modal ── */
.auth-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.auth-modal-backdrop.visible {
  display: flex;
}

.auth-modal {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: var(--space-8) 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}

.auth-modal h2 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  margin-bottom: var(--space-5);
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.auth-modal input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-inner);
  font-size: var(--text-sm);
  margin-bottom: 10px;
  outline: none;
  background: var(--bg-surface-1);
  color: var(--text-primary);
  font-family: var(--font-body);
  transition: border-color var(--duration-short);
}

.auth-modal input::placeholder {
  color: var(--text-tertiary);
}

.auth-modal input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.auth-modal-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.auth-modal-actions .auth-btn {
  flex: 1;
  padding: 12px;
  font-size: var(--text-sm);
}

.auth-error {
  color: var(--status-red);
  font-size: var(--text-xs);
  margin-top: 10px;
  min-height: 1.2em;
}

.auth-toggle {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 14px;
  text-align: center;
}

.auth-toggle a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
}

.auth-toggle a:hover {
  text-decoration: underline;
}

/* ════════════════════════════════════════════════════
   Bottom Tab Navigation
   ════════════════════════════════════════════════════ */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  width: 100%;
  max-width: var(--max-width);
  height: var(--nav-height);
  background: var(--bg-base);
  border-top: 1px solid var(--border-active);
  z-index: 50;
  padding: 0 var(--space-4);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-2) var(--space-1);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color var(--duration-medium) var(--ease-snappy);
  position: relative;
}

.tab-link:hover {
  color: var(--text-secondary);
}

.tab-link.active {
  color: var(--accent);
}

/* Sliding pill indicator */
.tab-indicator {
  position: absolute;
  top: -1px;
  height: 2px;
  width: calc(100% / 3);
  transition: transform var(--duration-medium) var(--ease-snappy);
  pointer-events: none;
}

.tab-indicator::after {
  content: '';
  display: block;
  width: 32px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
  margin: 0 auto;
}

/* Indicator positions */
.tab-indicator[data-active="0"] { transform: translateX(0); }
.tab-indicator[data-active="1"] { transform: translateX(100%); }
.tab-indicator[data-active="2"] { transform: translateX(200%); }

.tab-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab-label {
  transition: transform var(--duration-medium) var(--ease-snappy),
              opacity var(--duration-medium) var(--ease-snappy);
}

.tab-link.active .tab-label {
  transform: translateY(-1px);
}

/* BETA badge */
.tab-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 28px);
  font-family: var(--font-mono);
  font-size: 7px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1;
}

/* ── Cards ── */
.card {
  position: relative;
  z-index: 1;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: var(--space-5);
  transition: border-color var(--duration-medium) var(--ease-snappy);
}

.card:hover {
  border-color: var(--border-active);
}

.card-title {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
}

/* ── Layout ── */
.dashboard {
  display: none;
  width: 100%;
  max-width: var(--max-width);
  padding: 0 var(--space-4) var(--space-6);
  gap: 14px;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.dashboard.visible {
  display: flex;
}

/* ── Empty State ── */
.empty-state {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 80px var(--space-6);
  width: 100%;
  max-width: var(--max-width);
}

.empty-state p {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-bottom: var(--space-5);
  line-height: 1.6;
}

/* ════════════════════════════════════════════════════
   Loading Screen
   ════════════════════════════════════════════════════ */

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  transition: opacity var(--duration-long) var(--ease-snappy),
              transform var(--duration-long) var(--ease-snappy);
}

.loading-screen.dismissed {
  opacity: 0;
  transform: scale(0.98);
  pointer-events: none;
}

.loading-wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-4xl);
  color: var(--text-primary);
  letter-spacing: 0.05em;
  user-select: none;
}

.loading-wordmark span {
  color: var(--accent);
}

.scan-line-container {
  width: 120px;
  height: 1px;
  background: var(--bg-surface-2);
  position: relative;
  overflow: hidden;
  border-radius: 1px;
}

.scan-line {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 1px;
  animation: scanExpand 1.5s var(--ease-snappy) infinite;
}

@keyframes scanExpand {
  0% {
    width: 0%;
    left: 0;
    opacity: 1;
  }
  60% {
    width: 100%;
    left: 0;
    opacity: 1;
  }
  80% {
    width: 100%;
    left: 0;
    opacity: 0.4;
  }
  100% {
    width: 100%;
    left: 0;
    opacity: 0;
  }
}

.loading-phrase {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  min-height: 1.4em;
  animation: phrasePulse 1.5s ease-in-out infinite;
}

@keyframes phrasePulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ════════════════════════════════════════════════════
   Skeleton Loading States
   ════════════════════════════════════════════════════ */

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg,
    #1A1A1A 25%,
    #2A2A2A 50%,
    #1A1A1A 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-inner);
}

.skeleton-text {
  height: 12px;
  border-radius: 4px;
}

.skeleton-text.sm { width: 60px; }
.skeleton-text.md { width: 120px; }
.skeleton-text.lg { width: 200px; }
.skeleton-text.full { width: 100%; }

.skeleton-card {
  height: 120px;
  width: 100%;
}

.skeleton-circle {
  border-radius: 50%;
}

.skeleton-circle.sm { width: 32px; height: 32px; }
.skeleton-circle.md { width: 48px; height: 48px; }
.skeleton-circle.lg { width: 64px; height: 64px; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-green {
  background: var(--status-green-tint);
  color: var(--status-green);
}

.badge-yellow {
  background: var(--status-yellow-tint);
  color: var(--status-yellow);
}

.badge-red {
  background: var(--status-red-tint);
  color: var(--status-red);
}

.badge-blue {
  background: var(--status-blue-tint);
  color: var(--status-blue);
}

.badge-purple {
  background: var(--purple-soft);
  color: var(--purple);
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

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

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

.animate-in {
  animation: fadeIn var(--duration-long) var(--ease-snappy) forwards;
}

/* ── Loading Spinner ── */
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .dashboard {
    padding: 0 10px var(--space-6);
  }
}

/* ════════════════════════════════════════════════════
   Page Transitions
   ════════════════════════════════════════════════════ */

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

body {
  animation: pageIn var(--duration-medium) var(--ease-snappy) both;
}

/* ════════════════════════════════════════════════════
   Typography: Tabular Nums for Data
   ════════════════════════════════════════════════════ */

.font-display,
.dial-value,
.rep-count,
.hero-duration,
.metric-value,
.sleep-hero-duration,
.sleep-score-val,
.stress-center-val,
.plan-stat-val,
.readiness-chip-val {
  font-variant-numeric: tabular-nums;
}

/* Card title: mono label style */
.card-title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

/* ════════════════════════════════════════════════════
   Interactive States (global)
   ════════════════════════════════════════════════════ */

/* Tappable cards */
.card[onclick],
.card[style*="cursor"],
[data-activity-id],
.tl-day,
.cal-tile[data-activity-id],
.readiness-chip {
  cursor: pointer;
}

/* Ensure minimum touch targets */
.btn, .btn-primary, .btn-secondary, .btn-ghost,
.auth-btn, .tab-link, .hud-pill, .mode-seg-btn,
.onboarding-enable-btn, .hero-start-btn,
.plan-expand-btn, .overflow-action {
  min-height: var(--touch-target);
}

.tab-link {
  min-width: var(--touch-target);
}

/* Hero start button arrow animation */
.hero-start-btn svg {
  transition: transform var(--duration-short) var(--ease-snappy);
}

.hero-start-btn:hover svg {
  transform: translateX(4px);
}

.hero-start-btn:hover {
  box-shadow: var(--accent-glow-lg);
}

/* ════════════════════════════════════════════════════
   Empty & Error States
   ════════════════════════════════════════════════════ */

.empty-state {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 60px var(--space-6);
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-4);
  color: var(--text-tertiary);
}

.empty-state-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state h3 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--text-primary);
  text-transform: uppercase;
  margin-bottom: var(--space-2);
}

.empty-state p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-5);
  line-height: 1.6;
  max-width: 320px;
}

/* Calm error state (not alarming) */
.error-state {
  text-align: center;
  padding: 40px var(--space-6);
}

.error-state-icon {
  width: 40px;
  height: 40px;
  color: var(--text-tertiary);
  margin: 0 auto var(--space-4);
}

.error-state-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
}

.error-state p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
  line-height: 1.5;
}

/* ════════════════════════════════════════════════════
   Reduced Motion
   ════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .loading-screen.dismissed {
    transition: none;
  }

  .dial-fill {
    transition: none;
  }

  body {
    animation: none;
  }

  .zone-animate {
    opacity: 1;
    animation: none;
  }

  .scan-line,
  .scan-laser {
    animation: none;
    display: none;
  }
}

/* ════════════════════════════════════════════════════
   Responsive Refinements
   ════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  .dashboard {
    padding: 0 10px var(--space-6);
  }
}

@media (max-width: 375px) {
  .dials-row {
    gap: 4px;
  }

  .dial-svg {
    max-width: 80px;
  }

  .hero-card-inner {
    min-height: 240px;
    padding: 20px 16px 16px;
  }

  .readiness-minibar {
    gap: 4px;
    padding: 0 10px;
  }

  .readiness-chip {
    padding: 4px 8px;
  }
}

/* ── Utility classes ── */
.hidden { display: none !important; }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text-tertiary); }
.text-center { text-align: center; }
.font-display { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.font-mono { font-family: var(--font-mono); }
.gap-sm { gap: var(--space-2); }
.gap-md { gap: 14px; }
