/*
 * HanlanOS Unified Design System
 * Single source of truth for all HanlanOS apps
 * Based on Travel Planner palette with comprehensive component library
 *
 * Rules:
 * - No emojis in UI (use icons or text labels)
 * - Consistent dark theme across all apps
 * - Inset borders on cards (not regular borders)
 * - Subtle hover effects with gradient overlays
 * - Sans-serif for UI, optional serif for reading
 */

:root {
  /* Core Colors - Neutral Gray palette */
  --ha-bg: #0a0a0a;
  --ha-surface: #121212;
  --ha-surface-2: #1a1a1a;
  --ha-surface-3: #222222;

  /* Text */
  --ha-text: #f0f0f0;
  --ha-text-muted: #6b7280;
  --ha-text-subtle: #4b5563;

  /* Borders */
  --ha-border: rgba(255, 255, 255, 0.06);
  --ha-border-light: rgba(255, 255, 255, 0.1);
  --ha-border-hover: rgba(255, 255, 255, 0.12);

  /* Accents - each app can override --ha-accent */
  --ha-accent: #60a5fa;
  --ha-accent-2: #a78bfa;
  --ha-accent-glow: rgba(96, 165, 250, 0.25);

  /* Status Colors */
  --ha-success: #34d399;
  --ha-warning: #fbbf24;
  --ha-error: #f87171;
  --ha-info: #60a5fa;

  /* Interactive States */
  --ha-hover: rgba(255, 255, 255, 0.06);
  --ha-hover-strong: rgba(255, 255, 255, 0.10);

  /* App-specific accent colors - HanlanOS Universal Palette */
  --ha-travel-accent: #3b82f6;      /* Blue - travel, navigation */
  --ha-travel-glow: rgba(59, 130, 246, 0.25);
  --ha-life-accent: #a78bfa;        /* Violet - introspection */
  --ha-life-glow: rgba(167, 139, 250, 0.25);
  --ha-art-accent: #f472b6;         /* Pink - creativity */
  --ha-art-glow: rgba(244, 114, 182, 0.25);
  --ha-tidbit-accent: #38bdf8;      /* Sky blue - discovery */
  --ha-tidbit-glow: rgba(56, 189, 248, 0.25);
  --ha-idea-accent: #6366f1;        /* Indigo-blue - ideation */
  --ha-idea-glow: rgba(99, 102, 241, 0.25);
  --ha-youtube-accent: #ef4444;     /* Red - YouTube brand */
  --ha-youtube-glow: rgba(239, 68, 68, 0.25);
  --ha-health-accent: #22c55e;      /* Green - vitality */
  --ha-health-glow: rgba(34, 197, 94, 0.25);
  --ha-eureka-accent: #f59e0b;      /* Amber - enlightenment */
  --ha-eureka-glow: rgba(245, 158, 11, 0.25);
  --ha-spanish-accent: #14b8a6;     /* Teal - language/culture */
  --ha-spanish-glow: rgba(20, 184, 166, 0.25);
  --ha-tips-accent: #8b5cf6;        /* Purple - AI/Claude */
  --ha-tips-glow: rgba(139, 92, 246, 0.25);

  /* Additional Colors */
  --ha-white: #ffffff;
  --ha-black: #000000;
  --ha-mission-accent: #06b6d4;     /* Cyan - Mission Control */
  --ha-saved-accent: #a855f7;       /* Purple - saved/bookmarked */
  --ha-review-accent: #ec4899;      /* Pink - review status */
  --ha-neutral-muted: #9ca3af;      /* Gray - exploring state */
  --ha-star-gold: #fbbf24;          /* Star rating active */
  --ha-star-hover: #fcd34d;         /* Star rating hover */

  /* Spacing Scale - Travel Planner rhythm */
  --ha-space-xs: 4px;
  --ha-space-sm: 8px;
  --ha-space-md: 12px;
  --ha-space-lg: 16px;
  --ha-space-xl: 20px;
  --ha-space-2xl: 24px;
  --ha-space-3xl: 32px;

  /* Control Heights - Universal button/input sizing */
  --ha-control-height: 32px;
  --ha-control-height-sm: 28px;
  --ha-control-height-lg: 40px;

  /* Icon Sizes - Consistent SVG sizing in buttons */
  --ha-icon-size: 16px;
  --ha-icon-size-sm: 14px;

  /* Typography Scale */
  --ha-text-xs: 10px;   /* Labels, meta, uppercase headers */
  --ha-text-sm: 11px;   /* Tags, badges, small buttons */
  --ha-text-base: 12px; /* Body text, inputs, cards */
  --ha-text-md: 13px;   /* Descriptions, nav items */
  --ha-text-lg: 15px;   /* Card titles, subheadings */
  --ha-text-xl: 18px;   /* Section headings, empty states */
  --ha-text-2xl: 22px;  /* Large stats, hero numbers */

  /* Radius Scale - Travel Planner pattern */
  --ha-radius: 12px;
  --ha-radius-sm: 6px;
  --ha-radius-md: 10px;
  --ha-radius-lg: 16px;
  --ha-radius-full: 9999px;

  /* Shadows */
  --ha-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --ha-shadow-md: 0 4px 24px rgba(0, 0, 0, 0.5);
  --ha-shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.6);
  --ha-shadow-xl: 0 12px 40px rgba(0, 0, 0, 0.6);
  --ha-shadow-glow: 0 0 30px var(--ha-accent-glow);

  /* Typography */
  --ha-font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  --ha-font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, Consolas, monospace;

  /* Transitions - Travel Planner easing functions */
  --ha-transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --ha-transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --ha-transition-smooth: 0.3s cubic-bezier(0.16, 1, 0.3, 1);

  /* Responsive Breakpoints */
  --ha-breakpoint-sm: 640px;
  --ha-breakpoint-md: 840px;
  --ha-breakpoint-lg: 1024px;
  --ha-breakpoint-xl: 1280px;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--ha-font-sans);
  background:
    radial-gradient(1200px 800px at 20% -10%, rgba(255,255,255,.03), transparent 60%),
    radial-gradient(900px 600px at 90% 10%, rgba(255,255,255,.02), transparent 55%),
    var(--ha-bg);
  color: var(--ha-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow: hidden;
}

/* ===== Scroll Lock (when modals are open) ===== */
body:has(dialog[open]),
body:has([data-modal-overlay].open),
body:has(.modal-overlay.open),
body:has(.ha-modal-overlay.open),
body:has(.ha-claude-overlay.open),
body:has([class$="-overlay"].open) {
  overflow: hidden;
}

/* ===== Keyframe Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, -45%) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes slideDown {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(-50%, -55%) scale(0.96); }
}

@keyframes backdropIn {
  from { background: rgba(0,0,0,0); }
  to { background: rgba(0,0,0,0.8); }
}

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

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

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

@keyframes pageIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pageOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-8px) scale(0.98); }
}

@keyframes homeCardEnter {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes claudePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0); }
  50% { box-shadow: 0 0 12px 2px rgba(139, 92, 246, 0.15); }
}

/* ===== Glass Effect (VisionOS-inspired) ===== */
.ha-glass {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: all var(--ha-transition-fast);
}

.ha-glass:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.18);
}

.ha-glass:active {
  background: rgba(255, 255, 255, 0.06);
  transform: scale(0.98);
}

/* Modal glass variant - subtle glassmorphism for modal content */
.ha-modal-glass {
  background: rgba(18, 18, 18, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 1px rgba(255, 255, 255, 0.08);
}

/* Glass button variant */
.ha-glass-btn {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: var(--ha-text);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
}

.ha-glass-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.02);
}

.ha-glass-btn:active {
  background: rgba(255, 255, 255, 0.06);
  transform: scale(0.98);
}

/* ===== App Layout Grid ===== */
.ha-app {
  animation: pageIn 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  display: grid;
  grid-template-columns: 300px 1fr 340px;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}

/* Page transition states */
body.page-transitioning {
  pointer-events: none;
}

body.page-out .ha-app,
body.page-out .ha-simple-layout,
body.page-out main {
  animation: pageOut 0.35s cubic-bezier(0.4, 0, 1, 1) forwards;
}

/* ===== Header - Glass Effect ===== */
.ha-header {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, rgba(14,14,14,.98) 0%, rgba(14,14,14,.95) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--ha-border);
  display: flex;
  align-items: center;
  padding: var(--ha-space-md) var(--ha-space-2xl);
  gap: var(--ha-space-xl);
  position: relative;
  z-index: 10;
  min-height: 56px;
}

.ha-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ha-accent-glow), transparent);
}

.ha-header-title {
  font-size: var(--ha-text-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.ha-header-subtitle {
  font-size: var(--ha-text-base);
  color: var(--ha-text-muted);
  margin-left: 12px;
}

.ha-header-tabs {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
}

.ha-header-tab {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--ha-radius-lg);
  color: var(--ha-text-muted);
  font-size: var(--ha-text-base);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--ha-transition-fast);
}

.ha-header-tab:hover {
  background: rgba(255,255,255,.04);
  color: var(--ha-text);
}

.ha-header-tab.active {
  background: rgba(96,165,250,.12);
  border-color: rgba(96,165,250,.25);
  color: var(--ha-text);
}

/* Header Navigation (Back + App Switcher) */
.ha-header-nav {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--ha-space-md);
  margin-right: var(--ha-space-lg);
}

.ha-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: var(--ha-control-height);
  border-radius: var(--ha-radius-md);
  border: 1px solid var(--ha-border);
  background: transparent;
  color: var(--ha-text-muted);
  font-size: var(--ha-text-base);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
  text-decoration: none;
}

.ha-back-btn:hover {
  border-color: var(--ha-accent);
  color: var(--ha-text);
  background: rgba(255,255,255,.04);
}

.ha-app-switcher {
  position: relative;
  min-width: 90px;
  min-height: var(--ha-control-height);
}

.ha-app-switcher-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: var(--ha-control-height);
  border-radius: var(--ha-radius-md);
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
}

.ha-app-switcher-btn:hover {
  border-color: var(--ha-accent);
}

.ha-app-switcher-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border-light);
  border-radius: var(--ha-radius-lg);
  box-shadow: var(--ha-shadow-xl);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--ha-transition-fast);
  max-height: 70vh;
  overflow-y: auto;
}

.ha-app-switcher.open .ha-app-switcher-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.ha-app-switcher-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--ha-text);
  text-decoration: none;
  font-size: var(--ha-text-md);
  transition: background var(--ha-transition-fast);
  border-bottom: 1px solid var(--ha-border);
}

.ha-app-switcher-item:last-child {
  border-bottom: none;
}

.ha-app-switcher-item:hover {
  background: var(--ha-surface-2);
}

.ha-app-switcher-item.active {
  background: rgba(96,165,250,.12);
  color: var(--ha-accent);
}

.ha-app-switcher-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ha-accent);
}

.ha-app-switcher-section {
  padding: 8px 14px;
  font-size: var(--ha-text-xs);
  color: var(--ha-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--ha-surface-2);
}

/* ===== Sidebar ===== */
.ha-sidebar {
  background: linear-gradient(180deg, var(--ha-surface) 0%, rgba(14,14,14,.98) 100%);
  border-right: 1px solid var(--ha-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
  padding: 16px;
}

.ha-sidebar::after {
  content: '';
  position: absolute;
  right: -1px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg, transparent, var(--ha-accent-glow), transparent);
  pointer-events: none;
}

/* ===== Main Content ===== */
.ha-main {
  padding: var(--ha-space-xl);
  overflow-y: auto;
  position: relative; /* Required for tab-content absolute positioning */
}

/* ===== Right Panel ===== */
.ha-right-panel {
  background: linear-gradient(180deg, var(--ha-surface) 0%, rgba(14,14,14,.98) 100%);
  border-left: 1px solid var(--ha-border);
  padding: var(--ha-space-lg);
  overflow-y: auto;
  position: relative;
}

.ha-right-panel::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg, transparent, var(--ha-accent-glow), transparent);
  pointer-events: none;
}

/* ===== Universal Card Component ===== */
.ha-card {
  background: linear-gradient(180deg, var(--ha-surface-2) 0%, var(--ha-surface) 100%);
  border: 1px solid var(--ha-border);
  border-radius: var(--ha-radius);
  overflow: hidden;
  transition: all var(--ha-transition-normal);
  display: flex;
  flex-direction: column;
  position: relative;
}

.ha-card-clickable { cursor: pointer; }

/* Interactive cards - enhanced hover */
.ha-card-interactive:hover {
  border-color: var(--ha-border-hover);
  transform: translateY(-2px);
  box-shadow: var(--ha-shadow-md);
}

/* === Media Container === */
.ha-card-media {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--ha-surface);
  flex-shrink: 0;
}
.ha-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--ha-transition-smooth);
}
.ha-card-interactive:hover .ha-card-media img {
  transform: scale(1.03);
}
.ha-card-overlay {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
}
.ha-card-badge {
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: var(--ha-text-sm);
  color: var(--ha-text);
}

/* === Content Area === */
.ha-card-content {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.ha-card-header {
  font-size: var(--ha-text-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ha-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ha-card-title {
  font-size: var(--ha-text-lg);
  font-weight: 500;
  color: var(--ha-text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
.ha-card-body {
  font-size: var(--ha-text-md);
  line-height: 1.5;
  color: var(--ha-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ha-card-footer {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--ha-text-sm);
  color: var(--ha-text-subtle);
}

/* === Actions Bar === */
.ha-card-actions {
  display: flex;
  border-top: 1px solid var(--ha-border);
  margin-top: auto;
}
.ha-card-action {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--ha-text-muted);
  font-family: inherit;
  font-size: var(--ha-text-base);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
}
.ha-card-action:hover {
  background: var(--ha-hover-strong);
  color: var(--ha-text);
}
.ha-card-action.active {
  color: var(--ha-accent);
}
.ha-card-action:not(:last-child) {
  border-right: 1px solid var(--ha-border);
}

/* === Size Variants === */
.ha-card-sm .ha-card-content { padding: 10px; gap: 6px; }
.ha-card-sm .ha-card-title { font-size: var(--ha-text-md); }
.ha-card-sm .ha-card-body { font-size: var(--ha-text-base); -webkit-line-clamp: 2; }

.ha-card-lg .ha-card-content { padding: 18px; gap: 10px; }
.ha-card-lg .ha-card-title { font-size: var(--ha-text-xl); }

/* === Direct Padding Utility === */
.ha-card-padded { padding: 16px; }
.ha-card-padded.ha-card-sm { padding: 12px; }
.ha-card-padded.ha-card-lg { padding: 20px; }

/* === Accent Variants === */
.ha-card-accent-success {
  background: linear-gradient(180deg, rgba(34,197,94,.08) 0%, var(--ha-surface) 100%);
  border-color: rgba(34,197,94,.2);
}
.ha-card-accent-warning {
  background: linear-gradient(180deg, rgba(251,191,36,.08) 0%, var(--ha-surface) 100%);
  border-color: rgba(251,191,36,.2);
}
.ha-card-accent-error {
  background: linear-gradient(180deg, rgba(239,68,68,.08) 0%, var(--ha-surface) 100%);
  border-color: rgba(239,68,68,.2);
}

/* === Glass Variant (Spanish Learning style) === */
.ha-card-glass {
  background: linear-gradient(145deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.03) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* === Card Title (direct child) === */
.ha-card-padded > .ha-card-title,
.ha-card > .ha-card-title:first-child {
  padding: 16px 16px 0;
}
.ha-card-padded > .ha-card-title { padding: 0 0 12px; }

/* === Horizontal Layout === */
.ha-card-horizontal {
  flex-direction: row;
}
.ha-card-horizontal .ha-card-media {
  width: 140px;
  flex-shrink: 0;
  aspect-ratio: 1;
}
.ha-card-horizontal .ha-card-content {
  justify-content: center;
}

/* === State Token Indicators === */
.ha-card-token {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ha-card-token-unread {
  background: var(--ha-accent);
}
.ha-card-token-new {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ha-accent);
  background: rgba(96, 165, 250, 0.1);
  padding: 2px 5px;
  border-radius: 3px;
}
.ha-card-token-favorite {
  color: var(--ha-star-gold);
  font-size: 12px;
}

/* === Card State Modifiers === */
.ha-card.is-favorite {
  border-color: rgba(251, 191, 36, 0.3);
}
.ha-card.is-selected {
  border-color: var(--ha-accent);
  box-shadow: 0 0 0 1px var(--ha-accent);
}
.ha-card.is-read {
  opacity: 0.7;
  transition: opacity var(--ha-transition-fast);
}
.ha-card.is-read:hover {
  opacity: 1;
}
.ha-card.is-new::before {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ha-accent);
}

/* === Card Grid === */
.ha-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

@media (max-width: 640px) {
  .ha-card-grid { grid-template-columns: 1fr; gap: 16px; }
  .ha-card-horizontal { flex-direction: column; }
  .ha-card-horizontal .ha-card-media { width: 100%; aspect-ratio: 16/9; }
}

/* ===== Buttons ===== */
.ha-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 14px;
  height: var(--ha-control-height);
  border-radius: var(--ha-radius-md);
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  color: var(--ha-text);
  font-size: var(--ha-text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--ha-transition-fast);
  white-space: nowrap;
  user-select: none;
}

.ha-btn:hover {
  border-color: var(--ha-accent);
  background: var(--ha-surface);
}

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

.ha-btn-primary:hover {
  background: linear-gradient(rgba(255,255,255,0.2), rgba(255,255,255,0.2)), var(--ha-accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Muted link for secondary actions (e.g., "Requirements" in modal footers) */
.ha-link-muted {
  background: none;
  border: none;
  color: var(--ha-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.ha-link-muted:hover { opacity: 1; }

.ha-btn-sm {
  padding: 0 var(--ha-space-md);
  height: var(--ha-control-height-sm);
  font-size: var(--ha-text-base);
}

.ha-btn-icon {
  width: var(--ha-control-height);
  height: var(--ha-control-height);
  min-width: var(--ha-control-height);
  min-height: var(--ha-control-height);
  max-width: var(--ha-control-height);
  max-height: var(--ha-control-height);
  aspect-ratio: 1;
  flex: 0 0 var(--ha-control-height);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ha-radius-sm);
}

.ha-btn-icon svg {
  width: var(--ha-icon-size);
  height: var(--ha-icon-size);
}

/* Small icon button variant */
.ha-btn-icon.ha-btn-sm {
  width: var(--ha-control-height-sm);
  height: var(--ha-control-height-sm);
  min-width: var(--ha-control-height-sm);
  min-height: var(--ha-control-height-sm);
  max-width: var(--ha-control-height-sm);
  max-height: var(--ha-control-height-sm);
  flex: 0 0 var(--ha-control-height-sm);
}

.ha-btn-icon.ha-btn-sm svg {
  width: var(--ha-icon-size-sm);
  height: var(--ha-icon-size-sm);
}

.ha-btn-danger {
  background: rgba(248,113,113,.12);
  border-color: rgba(248,113,113,.25);
  color: var(--ha-error);
}

.ha-btn-danger:hover {
  background: rgba(248,113,113,.2);
  border-color: rgba(248,113,113,.4);
}

.ha-btn-success {
  background: rgba(52,211,153,.12);
  border-color: rgba(52,211,153,.25);
  color: var(--ha-success);
}

.ha-btn-success:hover {
  background: rgba(52,211,153,.2);
  border-color: rgba(52,211,153,.4);
}

/* ===== Inputs ===== */
.ha-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  font-family: var(--ha-font-sans);
  transition: border-color var(--ha-transition-fast);
  color-scheme: dark;
}

.ha-input:focus {
  outline: none;
  border-color: var(--ha-accent);
}

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

.ha-textarea {
  width: 100%;
  min-height: 70px;
  padding: 8px 10px;
  background: var(--ha-surface-2);
  border: 1px solid var(--ha-border);
  border-radius: 6px;
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  font-family: inherit;
  resize: vertical;
  color-scheme: dark;
  transition: border-color var(--ha-transition-fast);
}

.ha-textarea:focus {
  outline: none;
  border-color: var(--ha-accent);
}

.ha-textarea::placeholder {
  color: var(--ha-text-muted);
}

/* ===== Select ===== */
.ha-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 32px 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--ha-transition-fast), background-color var(--ha-transition-fast);
  color-scheme: dark;
}

.ha-select:hover {
  border-color: var(--ha-border-light);
  background-color: var(--ha-surface-3);
}

.ha-select:focus {
  outline: none;
  border-color: var(--ha-accent);
}

/* Custom dropdown menu (JS-powered) */
.ha-dropdown {
  position: relative;
  display: inline-block;
}

.ha-dropdown-trigger {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 32px 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  font-family: inherit;
  cursor: pointer;
  transition: all var(--ha-transition-fast);
}

.ha-dropdown-trigger:hover {
  border-color: var(--ha-border-light);
  background-color: var(--ha-surface-3);
}

.ha-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border);
  border-radius: var(--ha-radius);
  box-shadow: var(--ha-shadow-lg);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--ha-transition-fast);
}

.ha-dropdown.open .ha-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Dropdown flipped above trigger */
.ha-dropdown-menu.ha-dropdown-flipped {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 4px;
  transform-origin: bottom center;
}
.ha-dropdown.open .ha-dropdown-menu.ha-dropdown-flipped {
  transform: translateY(0);
}

/* Portal mode for dropdowns inside modals */
.ha-dropdown-menu.ha-dropdown-portal {
  position: fixed;
  z-index: 10001; /* Must be higher than dialogs (9999) */
}

/* When portaled, menu is outside .ha-dropdown wrapper so needs its own open state */
.ha-dropdown-menu.ha-dropdown-portal.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.ha-dropdown-item {
  display: block;
  padding: 8px 12px;
  border-radius: var(--ha-radius-sm);
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  cursor: pointer;
  transition: background var(--ha-transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.ha-dropdown-item:hover {
  background: var(--ha-surface-2);
}

.ha-dropdown-item.selected {
  color: var(--ha-accent);
  background: rgba(var(--ha-accent-rgb, 96, 165, 250), 0.1);
}

.ha-dropdown-label {
  flex: 1;
}

/* ===== Date Picker ===== */
.ha-datepicker {
  position: relative;
  display: inline-block;
}

.ha-datepicker-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--ha-radius-sm);
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  font-family: var(--ha-font-sans);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
  min-width: 140px;
  height: var(--ha-control-height);
}

.ha-datepicker-trigger:hover {
  border-color: var(--ha-border-light);
  background: var(--ha-surface-3);
}

.ha-datepicker.open .ha-datepicker-trigger,
.ha-datepicker-trigger:focus {
  border-color: var(--ha-accent);
  outline: none;
}

.ha-datepicker-value {
  flex: 1;
  text-align: left;
}

.ha-datepicker-value.placeholder {
  color: var(--ha-text-subtle);
}

.ha-datepicker-icon {
  width: 16px;
  height: 16px;
  stroke: var(--ha-text-muted);
  flex-shrink: 0;
  transition: stroke var(--ha-transition-fast);
}

.ha-datepicker.open .ha-datepicker-icon,
.ha-datepicker-trigger:hover .ha-datepicker-icon {
  stroke: var(--ha-text);
}

/* Calendar popup */
.ha-datepicker-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 280px;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border-light);
  border-radius: var(--ha-radius);
  box-shadow: var(--ha-shadow-lg);
  padding: 12px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--ha-transition-fast);
}

.ha-datepicker.open .ha-datepicker-popup {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Flipped positioning */
.ha-datepicker-popup.ha-datepicker-flipped {
  top: auto;
  bottom: calc(100% + 4px);
  transform-origin: bottom center;
}

.ha-datepicker.open .ha-datepicker-popup.ha-datepicker-flipped {
  transform: translateY(0);
}

/* Portal mode for modals */
.ha-datepicker-popup.ha-datepicker-portal {
  position: fixed;
  z-index: 9000;
}

/* Header with month/year nav */
.ha-datepicker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.ha-datepicker-nav {
  width: 28px;
  height: 28px;
  border-radius: var(--ha-radius-sm);
  border: none;
  background: transparent;
  color: var(--ha-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ha-transition-fast);
}

.ha-datepicker-nav:hover {
  background: var(--ha-hover-strong);
  color: var(--ha-text);
}

.ha-datepicker-nav svg {
  width: 16px;
  height: 16px;
}

.ha-datepicker-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--ha-radius-sm);
  border: none;
  background: transparent;
  color: var(--ha-text);
  font-size: var(--ha-text-md);
  font-weight: 500;
  cursor: default;
}

/* Weekday labels */
.ha-datepicker-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 8px;
}

.ha-datepicker-weekdays span {
  text-align: center;
  font-size: var(--ha-text-xs);
  color: var(--ha-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 0;
}

/* Calendar grid */
.ha-datepicker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.ha-datepicker-day {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  border-radius: var(--ha-radius-sm);
  background: transparent;
  color: var(--ha-text);
  font-size: var(--ha-text-base);
  font-family: var(--ha-font-sans);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.ha-datepicker-day:hover {
  background: var(--ha-hover-strong);
}

.ha-datepicker-day.other-month {
  color: var(--ha-text-subtle);
  opacity: 0.4;
}

.ha-datepicker-day.other-month:hover {
  opacity: 0.6;
}

.ha-datepicker-day.today {
  color: var(--ha-accent);
  font-weight: 600;
}

.ha-datepicker-day.today::after {
  content: '';
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ha-accent);
}

.ha-datepicker-day.selected {
  background: var(--ha-accent);
  color: var(--ha-bg);
  font-weight: 500;
}

.ha-datepicker-day.selected:hover {
  background: var(--ha-accent);
  opacity: 0.9;
}

.ha-datepicker-day.selected.today::after {
  background: var(--ha-bg);
}

.ha-datepicker-day:focus-visible {
  outline: 2px solid var(--ha-accent);
  outline-offset: 1px;
}

/* Footer actions */
.ha-datepicker-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--ha-border);
}

.ha-datepicker-action {
  padding: 6px 12px;
  border-radius: var(--ha-radius-sm);
  border: none;
  background: transparent;
  font-size: var(--ha-text-sm);
  font-family: var(--ha-font-sans);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
}

.ha-datepicker-action:hover {
  background: var(--ha-hover-strong);
}

.ha-datepicker-action.today {
  color: var(--ha-accent);
}

.ha-datepicker-action.clear {
  color: var(--ha-text-muted);
}

/* ===== Checkbox ===== */
.ha-checkbox-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.ha-checkbox-wrapper input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ha-checkbox-visual {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ha-transition-fast);
  flex-shrink: 0;
}

.ha-checkbox-visual svg {
  width: 12px;
  height: 12px;
  opacity: 0;
  transform: scale(0.5);
  transition: all var(--ha-transition-fast);
  color: var(--ha-black);
}

.ha-checkbox-wrapper:hover .ha-checkbox-visual {
  border-color: var(--ha-accent);
}

.ha-checkbox-wrapper input:checked + .ha-checkbox-visual {
  background: var(--ha-accent);
  border-color: var(--ha-accent);
}

.ha-checkbox-wrapper input:checked + .ha-checkbox-visual svg {
  opacity: 1;
  transform: scale(1);
}

.ha-checkbox-wrapper input:focus-visible + .ha-checkbox-visual {
  outline: 2px solid var(--ha-accent);
  outline-offset: 2px;
}

.ha-checkbox-label {
  font-size: var(--ha-text-md);
  color: var(--ha-text);
}

/* ===== Radio ===== */
.ha-radio-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.ha-radio-wrapper input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ha-radio-visual {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ha-transition-fast);
  flex-shrink: 0;
}

.ha-radio-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ha-accent);
  opacity: 0;
  transform: scale(0);
  transition: all var(--ha-transition-fast);
}

.ha-radio-wrapper:hover .ha-radio-visual {
  border-color: var(--ha-accent);
}

.ha-radio-wrapper input:checked + .ha-radio-visual {
  border-color: var(--ha-accent);
}

.ha-radio-wrapper input:checked + .ha-radio-visual .ha-radio-dot {
  opacity: 1;
  transform: scale(1);
}

.ha-radio-wrapper input:focus-visible + .ha-radio-visual {
  outline: 2px solid var(--ha-accent);
  outline-offset: 2px;
}

/* ===== Toggle Switch ===== */
.ha-toggle {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--ha-surface-3);
  border-radius: 11px;
  border: 1px solid var(--ha-border);
  cursor: pointer;
  transition: all var(--ha-transition-fast);
  flex-shrink: 0;
}
.ha-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ha-text-muted);
  transition: all var(--ha-transition-fast);
}
.ha-toggle:hover {
  border-color: var(--ha-border-hover);
}
.ha-toggle.active {
  background: var(--ha-accent);
  border-color: var(--ha-accent);
}
.ha-toggle.active::after {
  left: 20px;
  background: var(--ha-black);
}
.ha-toggle:focus-visible {
  outline: 2px solid var(--ha-accent);
  outline-offset: 2px;
}

/* ===== Progress Bar ===== */
.ha-progress {
  height: 6px;
  background: var(--ha-surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.ha-progress-fill {
  height: 100%;
  background: var(--ha-accent);
  border-radius: 3px;
  transition: width var(--ha-transition-normal);
}
.ha-progress-sm { height: 4px; }
.ha-progress-lg { height: 8px; }

/* Progress variants */
.ha-progress-success .ha-progress-fill { background: var(--ha-success); }
.ha-progress-warning .ha-progress-fill { background: var(--ha-warning); }
.ha-progress-error .ha-progress-fill { background: var(--ha-error); }

/* ===== Global Modal ===== */
.ha-modal {
  background: var(--ha-bg-elevated);
  border: 1px solid var(--ha-border);
  border-radius: var(--ha-radius-lg);
  color: var(--ha-text);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  padding: 0;
  max-width: 500px;
  width: calc(100vw - 40px);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

.ha-modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

.ha-modal-head {
  padding: 16px 20px;
  min-height: calc(var(--ha-control-height) + 32px);
  border-bottom: 1px solid var(--ha-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ha-modal-title {
  font-size: var(--ha-text-xl);
  font-weight: 600;
  color: var(--ha-accent);
  margin: 0;
}

.ha-modal-body {
  padding: 24px;
}

.ha-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--ha-border);
}

/* ===== Native Dialog Styles ===== */
/* Allow dropdowns/tooltips to extend outside dialog bounds */
dialog {
  overflow: visible;
}
dialog form {
  overflow: visible;
}

dialog[open] {
  animation: ha-dialog-open 0.2s ease forwards;
}
dialog.closing {
  animation: ha-dialog-close 0.2s ease forwards;
}
@keyframes ha-dialog-open {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes ha-dialog-close {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}
dialog::backdrop {
  animation: ha-backdrop-fade 0.2s ease forwards;
}
@keyframes ha-backdrop-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Toast Notifications ===== */
.ha-toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.ha-toast {
  padding: 12px 16px;
  border-radius: var(--ha-radius);
  background: var(--ha-surface);
  border: 1px solid var(--ha-border);
  box-shadow: var(--ha-shadow-lg);
  font-size: var(--ha-text-md);
  color: var(--ha-text);
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.ha-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.ha-toast-success {
  border-color: var(--ha-success);
  background: linear-gradient(135deg, var(--ha-surface), rgba(52, 211, 153, 0.1));
}

.ha-toast-error {
  border-color: var(--ha-error);
  background: linear-gradient(135deg, var(--ha-surface), rgba(248, 113, 113, 0.1));
}

.ha-toast-warning {
  border-color: var(--ha-warning);
  background: linear-gradient(135deg, var(--ha-surface), rgba(251, 191, 36, 0.1));
}

/* ===== Tooltips ===== */
.ha-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--ha-surface-3);
  border: 1px solid var(--ha-border-light);
  border-radius: var(--ha-radius-sm);
  padding: 10px 12px;
  font-size: var(--ha-text-base);
  color: var(--ha-text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  max-width: 280px;
  box-shadow: var(--ha-shadow-lg);
}

.ha-tooltip.visible {
  opacity: 1;
}

.ha-tooltip-title {
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ha-tooltip-title .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ha-tooltip-subtitle {
  font-size: var(--ha-text-sm);
  color: var(--ha-text-muted);
  margin-bottom: 4px;
}

.ha-tooltip-meta {
  font-size: var(--ha-text-xs);
  color: var(--ha-text-subtle);
}

.ha-tooltip-badge {
  font-size: var(--ha-text-xs);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 4px;
}

.ha-tooltip-badge.confirmed {
  background: rgba(52, 211, 153, 0.2);
  color: var(--ha-success);
}

.ha-tooltip-badge.likely {
  background: rgba(59, 130, 246, 0.2);
  color: var(--ha-travel-accent);
}

.ha-tooltip-badge.tentative {
  background: rgba(251, 191, 36, 0.2);
  color: var(--ha-warning);
}

.ha-tooltip-badge.exploring {
  background: rgba(107, 114, 128, 0.2);
  color: var(--ha-neutral-muted);
}

/* ===== Tags / Chips ===== */
.ha-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--ha-radius-full);
  background: var(--ha-surface-2);
  border: 1px solid var(--ha-border);
  font-size: var(--ha-text-sm);
  color: var(--ha-text-muted);
  white-space: nowrap;
  user-select: none;
}

.ha-tag-success {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.25);
  color: var(--ha-success);
}

.ha-tag-warning {
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.25);
  color: var(--ha-warning);
}

.ha-tag-error {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.25);
  color: var(--ha-error);
}

.ha-tag-info {
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.25);
  color: var(--ha-info);
}

/* Workflow Status Tags */
.ha-tag-new {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
  color: var(--ha-accent);
}
.ha-tag-saved {
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.3);
  color: var(--ha-saved-accent);
}
.ha-tag-progress {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--ha-eureka-accent);
}
.ha-tag-review {
  background: rgba(236, 72, 153, 0.15);
  border-color: rgba(236, 72, 153, 0.3);
  color: var(--ha-review-accent);
}
.ha-tag-complete {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  color: var(--ha-health-accent);
}

/* ===== Unified Label (uppercase meta text) ===== */
.ha-label {
  font-size: var(--ha-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ha-text-muted);
}

/* ===== Section Headers ===== */
.ha-section-title {
  font-size: var(--ha-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ha-text-muted);
  margin-bottom: var(--ha-space-sm);
}

/* ===== Sidebar Sections ===== */
.sidebar-section {
  margin-bottom: var(--ha-space-2xl);
}

.sidebar-section:last-child {
  margin-bottom: 0;
}

/* ===== Sidebar Navigation ===== */
.ha-nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--ha-space-sm);
  padding: var(--ha-space-sm) var(--ha-space-lg);
  border-radius: var(--ha-radius-lg);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ha-text);
  font-size: var(--ha-text-md);
  text-align: left;
  cursor: pointer;
  transition: all var(--ha-transition-fast);
  user-select: none;
}

.ha-nav-btn + .ha-nav-btn {
  margin-top: var(--ha-space-sm);
}

.ha-nav-btn:hover {
  background: var(--ha-hover-strong);
  color: var(--ha-text);
}

.ha-nav-btn.active {
  background: var(--ha-surface-2);
  box-shadow: inset 0 0 0 1px var(--ha-accent);
  color: var(--ha-text);
  border-radius: var(--ha-radius-lg);
}

.ha-nav-btn.active:hover {
  background: var(--ha-surface-3);
}

/* ===== Modal Overlay ===== */
.ha-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--ha-transition-normal);
  animation: backdropIn var(--ha-transition-normal);
}

.ha-modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.ha-modal-overlay .ha-modal {
  background: var(--ha-bg-elevated);
  border-radius: var(--ha-radius-lg);
  border: 1px solid var(--ha-border);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow: visible; /* Allow dropdowns to escape */
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  transform: scale(0.95);
  transition: transform var(--ha-transition-normal);
  animation: slideUp var(--ha-transition-smooth);
  z-index: 8001;
  position: relative;
}

.ha-modal-overlay.open .ha-modal {
  transform: scale(1);
}

.ha-modal-header {
  padding: 16px 20px;
  min-height: calc(var(--ha-control-height) + 32px);
  border-bottom: 1px solid var(--ha-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ha-modal-title {
  font-size: var(--ha-text-xl);
  font-weight: 600;
}

.ha-modal-body {
  padding: var(--ha-space-2xl);
  overflow: visible; /* Allow dropdowns/tooltips to extend outside */
}

.ha-modal-footer {
  padding: var(--ha-space-2xl);
  border-top: 1px solid var(--ha-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--ha-space-md);
}

/* ===== Scroll Container (gradient fades disabled) ===== */
[data-scroll-fade] {
  position: relative;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ===== Insight Cards ===== */
.ha-insight {
  padding: var(--ha-space-lg);
  border-radius: var(--ha-radius-lg);
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.08), rgba(167, 139, 250, 0.05));
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.15);
  margin-bottom: var(--ha-space-lg);
}

.ha-insight-label {
  font-size: var(--ha-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ha-accent);
  margin-bottom: 6px;
}

.ha-insight-text {
  font-size: var(--ha-text-md);
  line-height: 1.5;
}

/* ===== Grid Layouts ===== */
.ha-grid {
  display: grid;
  gap: 14px;
}

.ha-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.ha-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.ha-grid-auto {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

/* ===== Utility Classes ===== */
.ha-flex {
  display: flex;
}

.ha-flex-col {
  flex-direction: column;
}

.ha-items-center {
  align-items: center;
}

.ha-items-start {
  align-items: flex-start;
}

.ha-justify-between {
  justify-content: space-between;
}

.ha-justify-center {
  justify-content: center;
}

.ha-gap-xs { gap: var(--ha-space-xs); }
.ha-gap-sm { gap: var(--ha-space-sm); }
.ha-gap-md { gap: var(--ha-space-md); }
.ha-gap-lg { gap: var(--ha-space-lg); }

.ha-mt-sm { margin-top: var(--ha-space-sm); }
.ha-mt-md { margin-top: var(--ha-space-md); }
.ha-mt-lg { margin-top: var(--ha-space-lg); }
.ha-mt-xl { margin-top: var(--ha-space-xl); }

.ha-mb-sm { margin-bottom: var(--ha-space-sm); }
.ha-mb-md { margin-bottom: var(--ha-space-md); }
.ha-mb-lg { margin-bottom: var(--ha-space-lg); }
.ha-mb-xl { margin-bottom: var(--ha-space-xl); }

.ha-p-sm { padding: var(--ha-space-sm); }
.ha-p-md { padding: var(--ha-space-md); }
.ha-p-lg { padding: var(--ha-space-lg); }
.ha-p-xl { padding: var(--ha-space-xl); }

/* ===== Responsive Design ===== */

/* Tablet and below: Hide right panel */
@media (max-width: 1024px) {
  .ha-app {
    grid-template-columns: 280px 1fr;
  }

  .ha-right-panel {
    display: none;
  }
}

/* Mobile: Single column stack */
@media (max-width: 840px) {
  .ha-app {
    grid-template-columns: 1fr;
  }

  .ha-sidebar {
    display: none;
  }

  .ha-header {
    padding: 0 var(--ha-space-lg);
  }

  .ha-main {
    padding: var(--ha-space-lg);
  }

  .ha-grid-2,
  .ha-grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Small mobile adjustments */
@media (max-width: 640px) {
  .ha-header {
    padding: 0 var(--ha-space-lg);
    gap: var(--ha-space-md);
  }

  .ha-main {
    padding: var(--ha-space-lg);
  }

  .ha-modal {
    width: 95%;
    max-height: 90vh;
  }

  .ha-header-nav {
    display: none;
  }
}

/* ===== Simple Layout (for apps without 3-panel layout) ===== */
.ha-simple-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.ha-simple-layout .ha-header {
  position: sticky;
  top: 0;
}

.ha-simple-main {
  flex: 1;
  padding: 18px 22px 40px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.ha-simple-main-wide {
  max-width: 1400px;
}

/* Simple layout mobile adjustments */
@media (max-width: 640px) {
  .ha-simple-main {
    padding: 16px 18px 40px;
  }

  .ha-simple-layout .ha-header {
    gap: var(--ha-space-md);
  }

  .ha-simple-layout .ha-header-title {
    font-size: 14px;
  }

  .ha-simple-layout .ha-header-nav {
    display: flex;
    gap: var(--ha-space-sm);
  }

  .ha-simple-layout .ha-back-btn {
    padding: 5px 8px;
    font-size: 11px;
  }

  .ha-simple-layout .ha-app-switcher-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Hide subtitle/description text on small screens */
  .ha-simple-layout .ha-header > div:last-child > div:not(.ha-header-title) {
    display: none;
  }
}

/* ===== Home Page Specific ===== */
.ha-home-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  margin-top: 20px;
}

.ha-home-card {
  grid-column: span 12;
  padding: 20px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  opacity: 0;
  animation: homeCardEnter 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.3s ease;
  /* Flex layout for consistent pill positioning */
  display: flex;
  flex-direction: column;
  min-height: 180px;
}

/* Staggered card entrance */
.ha-home-card:nth-child(1) { animation-delay: 0.05s; }
.ha-home-card:nth-child(2) { animation-delay: 0.1s; }
.ha-home-card:nth-child(3) { animation-delay: 0.15s; }
.ha-home-card:nth-child(4) { animation-delay: 0.2s; }
.ha-home-card:nth-child(5) { animation-delay: 0.25s; }
.ha-home-card:nth-child(6) { animation-delay: 0.3s; }
.ha-home-card:nth-child(7) { animation-delay: 0.35s; }
.ha-home-card:nth-child(8) { animation-delay: 0.4s; }
.ha-home-card:nth-child(9) { animation-delay: 0.45s; }
.ha-home-card:nth-child(10) { animation-delay: 0.5s; }

.ha-home-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--card-accent, var(--ha-accent)), transparent 80%);
  opacity: 0.5;
  transition: opacity 0.3s ease;
}

.ha-home-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--card-accent, var(--ha-accent)), transparent 70%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.ha-home-card:hover {
  transform: translateY(-4px) scale(1.01);
  border-color: color-mix(in srgb, var(--card-accent, var(--ha-accent)) 40%, transparent);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 0 0 1px color-mix(in srgb, var(--card-accent, var(--ha-accent)) 20%, transparent),
    0 0 40px color-mix(in srgb, var(--card-accent, var(--ha-accent)) 15%, transparent);
}

.ha-home-card:hover::before {
  opacity: 1;
}

.ha-home-card:hover::after {
  opacity: 0.06;
}

.ha-home-card:active {
  transform: translateY(-2px) scale(0.99);
  transition-duration: 0.1s;
}

@media (min-width: 840px) {
  .ha-home-card {
    grid-column: span 6;
  }
}

@media (min-width: 1200px) {
  .ha-home-card {
    grid-column: span 4;
  }
}

.ha-home-card-title {
  font-size: var(--ha-text-lg);
  font-weight: 600;
  color: var(--ha-text);
  margin: 0;
  letter-spacing: -0.01em;
}

.ha-home-card-meta {
  font-size: var(--ha-text-base);
  color: var(--ha-text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

.ha-home-card-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--ha-text-sm);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--ha-border);
  background: rgba(255,255,255,.03);
  color: var(--ha-text-muted);
  margin-top: auto;
  align-self: flex-start;
  transition: all 0.3s ease;
}

.ha-home-card:hover .ha-home-card-pill {
  border-color: color-mix(in srgb, var(--card-accent, var(--ha-accent)) 50%, transparent);
  background: color-mix(in srgb, var(--card-accent, var(--ha-accent)) 10%, transparent);
  color: var(--ha-text);
}

.ha-home-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--ha-radius-md);
  background: linear-gradient(135deg, var(--ha-surface-3), var(--ha-surface-2));
  border: 1px solid var(--ha-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--card-accent, var(--ha-accent));
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.ha-home-card-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--card-accent, var(--ha-accent)), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ha-home-card:hover .ha-home-card-icon {
  border-color: color-mix(in srgb, var(--card-accent, var(--ha-accent)) 40%, transparent);
  box-shadow: 0 0 20px color-mix(in srgb, var(--card-accent, var(--ha-accent)) 25%, transparent);
}

.ha-home-card:hover .ha-home-card-icon::before {
  opacity: 0.15;
}

.ha-home-card-stat {
  font-size: var(--ha-text-sm);
  color: var(--card-accent, var(--ha-accent));
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
}

.ha-home-card-active {
  font-size: var(--ha-text-xs);
  color: var(--ha-text-subtle);
  margin-top: 4px;
}

.ha-home-note {
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px dashed var(--ha-border);
  border-radius: var(--ha-radius-lg);
  color: var(--ha-text-muted);
  font-size: var(--ha-text-base);
  line-height: 1.5;
  opacity: 0;
  animation: fadeIn 0.4s ease 0.6s forwards;
}

/* ===== Stats Components ===== */
.ha-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.ha-stat-box {
  background: var(--ha-surface-2);
  border-radius: var(--ha-radius-md);
  padding: 14px;
  text-align: center;
  box-shadow: inset 0 0 0 1px var(--ha-border);
}

.ha-stat-value {
  font-size: var(--ha-text-2xl);
  font-weight: 600;
  color: var(--ha-accent);
}

.ha-stat-label {
  font-size: var(--ha-text-xs);
  color: var(--ha-text-muted);
  margin-top: 4px;
}

/* ===== Timeline Components ===== */
.ha-timeline {
  position: relative;
  padding-left: 24px;
}

.ha-timeline::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--ha-border);
}

.ha-timeline-item {
  position: relative;
  padding-bottom: 18px;
}

.ha-timeline-item::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ha-accent);
  border: 2px solid var(--ha-bg);
}

.ha-timeline-item.upcoming::before { background: var(--ha-warning); }
.ha-timeline-item.completed::before { background: var(--ha-success); }

.ha-timeline-date {
  font-size: var(--ha-text-xs);
  color: var(--ha-text-muted);
}

.ha-timeline-content {
  font-size: var(--ha-text-md);
  margin-top: 4px;
}

/* ===== Empty States ===== */
.ha-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--ha-text-muted);
  min-height: 300px;
  height: 100%;
  flex: 1;
}

/* ha-empty uses flex centering (when not overridden by JS display:block) */
.ha-main > .ha-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 40px);
  max-width: 400px;
  min-height: auto;
  height: auto;
}

.ha-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
  color: var(--ha-text-muted);
  font-weight: 300;
  letter-spacing: -0.02em;
}

.ha-empty-title {
  font-size: var(--ha-text-xl);
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--ha-text);
}

.ha-empty-text {
  font-size: var(--ha-text-md);
  line-height: 1.5;
  max-width: 280px;
  opacity: 0.7;
}

.ha-empty-action {
  margin-top: 20px;
}

/* Legacy .empty-state class support - same styling */
/* Uses absolute positioning to center since JS often sets display:block */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--ha-text-muted);
  width: calc(100% - 40px);
  max-width: 400px;
}

.empty-state > * {
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 20px;
  opacity: 0.25;
  color: var(--ha-text-muted);
  font-weight: 300;
  letter-spacing: 0.05em;
}

.empty-state .empty-title {
  font-size: var(--ha-text-xl);
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--ha-text);
}

.empty-state .empty-text {
  font-size: var(--ha-text-md);
  line-height: 1.5;
  max-width: 280px;
  opacity: 0.7;
}

/* Alternate naming convention support */
.empty-state-icon,
.empty-state .empty-state-icon {
  font-size: 40px;
  margin-bottom: 20px;
  opacity: 0.25;
  color: var(--ha-text-muted);
  font-weight: 300;
  letter-spacing: 0.05em;
}

.empty-state-title,
.empty-state .empty-state-title {
  font-size: var(--ha-text-xl);
  font-weight: 500;
  margin-bottom: 10px;
  color: var(--ha-text);
}

.empty-state-hint,
.empty-state .empty-state-hint,
.empty-state-text,
.empty-state .empty-state-text {
  font-size: var(--ha-text-md);
  line-height: 1.6;
  max-width: 300px;
  opacity: 0.6;
  color: var(--ha-text-muted);
}

/* ===== Progress/Skill Bars ===== */
.ha-skill-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--ha-border);
}

.ha-skill-item:last-child {
  border-bottom: none;
}

.ha-skill-name {
  font-size: var(--ha-text-base);
  flex: 1;
}

.ha-skill-bar {
  width: 80px;
  height: 6px;
  background: var(--ha-surface);
  border-radius: 3px;
  overflow: hidden;
}

.ha-skill-fill {
  height: 100%;
  background: var(--ha-accent);
  border-radius: 3px;
  transition: width 0.3s;
}

.ha-skill-level {
  font-size: var(--ha-text-xs);
  color: var(--ha-text-muted);
  width: 50px;
  text-align: right;
}

/* ===== Star Rating Component ===== */
.ha-star-rating {
  display: inline-flex;
  gap: 2px;
}

.ha-star-rating .ha-star {
  cursor: pointer;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.15);
  transition: color 0.1s, text-shadow 0.1s, transform 0.1s;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  user-select: none;
}

.ha-star-rating .ha-star.filled {
  color: var(--ha-star-gold);
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

.ha-star-rating .ha-star.hovered {
  color: var(--ha-star-hover);
  text-shadow: 0 0 8px rgba(252, 211, 77, 0.5);
  transform: scale(1.1);
}

/* Size variants */
.ha-star-rating-sm .ha-star { font-size: 12px; }
.ha-star-rating-lg .ha-star { font-size: 20px; }

/* Display-only mode (non-interactive) */
.ha-star-rating-display {
  pointer-events: none;
}
.ha-star-rating-display .ha-star {
  cursor: default;
}

/* Context menu star styling (larger touch targets) */
.ha-star-rating-menu {
  gap: 4px;
  padding: 8px 0;
}
.ha-star-rating-menu .ha-star {
  font-size: 24px;
  padding: 4px;
}

/* ===== Context Menu Component ===== */
.ha-context-menu {
  position: fixed;
  z-index: 9999;
  min-width: 180px;
  max-width: 280px;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border-light);
  border-radius: var(--ha-radius);
  box-shadow: var(--ha-shadow-lg);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px) scale(0.98);
  transition:
    opacity var(--ha-transition-fast),
    transform var(--ha-transition-fast),
    visibility var(--ha-transition-fast);
}

.ha-context-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Menu items with rounded corners */
.ha-context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--ha-radius-sm);
  font-size: var(--ha-text-base);
  color: var(--ha-text);
  cursor: pointer;
  transition: background var(--ha-transition-fast);
  user-select: none;
}

.ha-context-menu-item:hover {
  background: var(--ha-hover-strong);
}

.ha-context-menu-item:active {
  background: rgba(255, 255, 255, 0.12);
}

/* Item states */
.ha-context-menu-item.danger {
  color: var(--ha-error);
}
.ha-context-menu-item.danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

.ha-context-menu-item.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.ha-context-menu-item.active {
  background: rgba(96, 165, 250, 0.12);
  color: var(--ha-accent);
}

/* Icon slot */
.ha-context-menu-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.7;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ha-context-menu-icon svg {
  width: 14px;
  height: 14px;
}

/* Section label header */
.ha-context-menu-label {
  padding: 4px 10px 2px;
  font-size: var(--ha-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ha-text-muted);
  user-select: none;
}

/* Divider */
.ha-context-menu-divider {
  height: 1px;
  background: var(--ha-border);
  margin: 2px 6px;
}

/* Submenu support */
.ha-context-menu-submenu {
  position: relative;
}

.ha-context-menu-arrow {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.5;
}

.ha-context-menu-submenu-items {
  position: absolute;
  left: calc(100% + 4px);
  top: -4px;
  min-width: 140px;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border-light);
  border-radius: var(--ha-radius);
  box-shadow: var(--ha-shadow-lg);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-4px);
  transition: all var(--ha-transition-fast);
}

.ha-context-menu-submenu:hover > .ha-context-menu-submenu-items {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

/* Submenu flipped left when near right edge */
.ha-context-menu-submenu-items.flip-left {
  left: auto;
  right: calc(100% + 4px);
  transform: translateX(4px);
}
.ha-context-menu-submenu:hover > .ha-context-menu-submenu-items.flip-left {
  transform: translateX(0);
}

/* Color picker row (for section menus) */
.ha-context-menu-colors {
  display: flex;
  gap: 6px;
  padding: 4px 10px;
  flex-wrap: wrap;
}

.ha-context-menu-color {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform var(--ha-transition-fast), border-color var(--ha-transition-fast);
}

.ha-context-menu-color:hover {
  transform: scale(1.15);
}

.ha-context-menu-color.selected {
  border-color: var(--ha-text);
}

/* Star rating in context menu */
.ha-context-menu .ha-star-rating {
  padding: 4px 10px;
}

/* ===== Keyboard Shortcuts Help ===== */
.ha-kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--ha-surface-2);
  border: 1px solid var(--ha-border);
  font-family: var(--ha-font-mono);
  font-size: 11px;
  color: var(--ha-text-muted);
}

/* ===== Focus Styles for Accessibility ===== */
/*
 * IMPORTANT: Inputs use border-color change for focus, NOT outline.
 * This prevents the double-border effect (border + outline stacking).
 * Global rule catches all inputs regardless of class.
 */
input:focus,
textarea:focus,
select:focus,
.ha-input:focus,
.ha-textarea:focus,
.ha-select:focus,
.ha-dropdown-trigger:focus {
  outline: none !important;
}

/* All buttons - no outline to prevent dual border effect */
button:focus,
button:focus-visible,
.ha-btn:focus,
.ha-btn:focus-visible,
.ha-nav-btn:focus,
.ha-nav-btn:focus-visible,
.ha-card-action:focus-visible,
.ha-card-interactive:focus-visible {
  outline: none;
}

/* ===== Print Styles ===== */
@media print {
  .ha-header,
  .ha-sidebar,
  .ha-right-panel,
  .ha-app-switcher {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }
}

/* ===== Mobile Touch & Layout (shared across all apps) ===== */
@media (max-width: 640px) {
  .ha-btn {
    padding: 10px 16px;
    font-size: 12px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .ha-btn-sm {
    padding: 8px 12px;
    min-height: 36px;
  }

  .ha-grid-auto {
    grid-template-columns: 1fr;
  }

  .ha-tag {
    padding: 8px 14px;
    font-size: 12px;
  }

  /* Form elements - larger touch targets */
  .ha-input,
  .ha-textarea {
    padding: 12px 14px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  .ha-select {
    padding: 12px 36px 12px 14px;
    font-size: 16px;
  }

  .ha-stats-grid {
    grid-template-columns: 1fr;
  }

  /* .ha-app 3-panel: mobile padding */
  .ha-main {
    padding: var(--ha-space-lg);
  }
}

/* ===== Card Menu Button (3-dot) - Mobile Touch Target ===== */
.ha-card-menu-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  border: none;
  cursor: pointer;
  display: none;  /* Hidden by default on desktop */
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: background var(--ha-transition-fast);
}
.ha-card-menu-btn svg { opacity: 0.8; }
.ha-card-menu-btn:hover { background: rgba(0,0,0,.8); }
.ha-card-menu-btn:hover svg { opacity: 1; }

@media (max-width: 640px) {
  .ha-card-menu-btn { display: flex; }
}

/* ===== Claude Notes Header Button ===== */
.ha-claude-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: var(--ha-control-height);
  border-radius: var(--ha-radius-md);
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  color: var(--ha-text);
  font-family: inherit;
  font-size: var(--ha-text-base);
  cursor: pointer;
  transition: all 0.2s ease;
}
.ha-claude-btn:hover {
  border-color: var(--ha-border-light);
  background: var(--ha-surface);
}
.ha-claude-btn svg { width: 14px; height: 14px; opacity: 0.8; }
.ha-claude-btn .ha-claude-badge {
  display: none;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--ha-text-muted);
  color: var(--ha-white);
  font-size: 10px;
  font-weight: 600;
  align-items: center;
  justify-content: center;
}
.ha-claude-btn .ha-claude-badge.has-notes { display: inline-flex; }

/* ===== Claude Notes Modal ===== */
.ha-claude-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}
.ha-claude-overlay.open { opacity: 1; visibility: visible; }
.ha-claude-modal { z-index: 8001; }

.ha-claude-modal {
  background: rgba(18, 18, 18, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  width: 400px;
  max-width: 90vw;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 1px rgba(255, 255, 255, 0.08);
  transform: scale(0.95) translateY(-10px);
  transition: transform 0.25s ease;
}
.ha-claude-overlay.open .ha-claude-modal {
  transform: scale(1) translateY(0);
}

.ha-claude-modal-header {
  padding: 16px 20px;
  min-height: calc(var(--ha-control-height) + 32px);
  border-bottom: 1px solid var(--ha-border);
  font-size: var(--ha-text-lg);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
/* Claude modal close uses standard .ha-btn.ha-btn-icon */

.ha-claude-modal-body { padding: 20px; }
.ha-claude-modal-body textarea {
  width: 100%;
  min-height: 100px;
  resize: vertical;
  background: var(--ha-surface-2);
  border: 1px solid var(--ha-border);
  border-radius: 8px;
  padding: 12px;
  color: var(--ha-text);
  font-family: inherit;
  font-size: var(--ha-text-md);
  line-height: 1.5;
}
.ha-claude-modal-body textarea:focus {
  outline: none;
  border-color: var(--ha-border-light);
}

.ha-claude-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--ha-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.ha-claude-modal-footer .ha-claude-mic {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
  color: var(--ha-text);
  font-family: inherit;
  font-size: var(--ha-text-base);
  cursor: pointer;
  transition: all 0.15s;
}
.ha-claude-modal-footer .ha-claude-mic:hover {
  border-color: var(--ha-border-light);
  color: var(--ha-text);
}
.ha-claude-modal-footer .ha-claude-mic svg { width: 14px; height: 14px; }

.ha-claude-modal-footer .ha-claude-actions {
  display: flex;
  gap: 8px;
}
.ha-claude-modal-footer .ha-claude-cancel {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--ha-border);
  background: transparent;
  color: var(--ha-text-muted);
  font-family: inherit;
  font-size: var(--ha-text-base);
  cursor: pointer;
  transition: all 0.15s;
}
.ha-claude-modal-footer .ha-claude-cancel:hover {
  border-color: var(--ha-border-hover);
  color: var(--ha-text);
}
.ha-claude-modal-footer .ha-claude-save {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--ha-border-light);
  background: var(--ha-surface-2);
  color: var(--ha-text);
  font-family: inherit;
  font-size: var(--ha-text-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.ha-claude-modal-footer .ha-claude-save:hover {
  background: var(--ha-surface);
  border-color: var(--ha-text-muted);
}

/* ===== Tab/View Transitions ===== */
/* Smooth fade transitions when switching sidebar tabs/sections */

/* Global tab-content animation - applies to ALL apps using this pattern */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: ha-view-enter 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Modal tab content transitions */
.modal-tab-content {
  display: none;
}

.modal-tab-content.active {
  display: block;
  animation: ha-view-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* For apps using ha-main as content container */
.ha-main > *:first-child {
  animation: ha-view-enter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes ha-view-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ha-view-exit {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* Base class for tab content areas */
.ha-tab-content {
  animation: ha-view-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Apply to content that's being hidden */
.ha-tab-content.exiting {
  animation: ha-view-exit 0.2s cubic-bezier(0.4, 0, 1, 1) forwards;
}

/* Alternative: simple opacity transition (for inline switching) */
.ha-view-fade {
  opacity: 1;
  transition: opacity 0.2s ease;
}

.ha-view-fade.hidden {
  opacity: 0;
  pointer-events: none;
}

/* For sidebar item content panels */
.ha-panel {
  animation: ha-view-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ===== View Swap Animation (for innerHTML swaps) ===== */
/* Add .ha-view-swap to container, JS triggers animation by toggling .ha-view-animate */
.ha-view-swap {
  transition: opacity 0.15s ease;
}

.ha-view-swap.ha-view-out {
  opacity: 0;
}

.ha-view-swap.ha-view-in {
  animation: ha-view-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Alternative: auto-animate children when class changes */
.ha-view-swap > * {
  animation: ha-view-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Main content area (calendar-container, etc.) smooth transition */
.calendar-container,
.ha-main,
[class*="-container"]:not(.ha-toast-container) {
  transition: opacity 0.15s ease;
}

.calendar-container.view-switching,
.ha-main.view-switching {
  opacity: 0;
}

/* List item entrance stagger (optional enhancement) */
.ha-stagger-item {
  opacity: 0;
  animation: ha-view-enter 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.ha-stagger-item:nth-child(1) { animation-delay: 0.02s; }
.ha-stagger-item:nth-child(2) { animation-delay: 0.04s; }
.ha-stagger-item:nth-child(3) { animation-delay: 0.06s; }
.ha-stagger-item:nth-child(4) { animation-delay: 0.08s; }
.ha-stagger-item:nth-child(5) { animation-delay: 0.10s; }
.ha-stagger-item:nth-child(6) { animation-delay: 0.12s; }
.ha-stagger-item:nth-child(7) { animation-delay: 0.14s; }
.ha-stagger-item:nth-child(8) { animation-delay: 0.16s; }
.ha-stagger-item:nth-child(9) { animation-delay: 0.18s; }
.ha-stagger-item:nth-child(10) { animation-delay: 0.20s; }

/* ===== Chronos McTwisp Panel ===== */
/* Dashboard panel for time-saving insights */

.chronos-panel {
  margin-top: 24px;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border);
  border-radius: var(--ha-radius);
  overflow: hidden;
}

.chronos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--ha-border);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.08) 0%, rgba(245, 158, 11, 0.05) 100%);
}

.chronos-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--ha-text-md);
  font-weight: 600;
  color: var(--ha-text);
}

.chronos-icon {
  font-size: 16px;
  color: var(--ha-eureka-accent);
}

.chronos-meta {
  font-size: var(--ha-text-sm);
  color: var(--ha-text-muted);
}

.chronos-insights {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
}

.chronos-empty {
  padding: 24px;
  text-align: center;
  color: var(--ha-text-muted);
  font-size: var(--ha-text-base);
}

.chronos-empty code {
  background: var(--ha-surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.chronos-insight {
  background: var(--ha-surface-2);
  border: 1px solid var(--ha-border);
  border-radius: 10px;
  padding: 12px 14px;
  transition: all 0.2s ease;
}

.chronos-insight:hover {
  border-color: rgba(139, 92, 246, 0.3);
  background: var(--ha-surface-3);
}

.chronos-insight-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.chronos-insight-category {
  font-size: 9px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(139, 92, 246, 0.15);
  color: var(--ha-life-accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chronos-insight-category[data-category="travel"] {
  background: rgba(59, 130, 246, 0.15);
  color: var(--ha-travel-accent);
}

.chronos-insight-category[data-category="health"] {
  background: rgba(34, 197, 94, 0.15);
  color: var(--ha-health-accent);
}

.chronos-insight-category[data-category="art"] {
  background: rgba(244, 114, 182, 0.15);
  color: var(--ha-art-accent);
}

.chronos-insight-category[data-category="life-admin"] {
  background: rgba(245, 158, 11, 0.15);
  color: var(--ha-eureka-accent);
}

.chronos-insight-title {
  font-size: var(--ha-text-md);
  font-weight: 500;
  color: var(--ha-text);
  flex: 1;
}

.chronos-insight-preview {
  font-size: var(--ha-text-base);
  color: var(--ha-text-muted);
  line-height: 1.5;
  margin-bottom: 10px;
}

.chronos-insight-details {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  font-size: var(--ha-text-base);
  line-height: 1.6;
  color: var(--ha-text);
}

.chronos-insight-savings {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--ha-border);
  font-weight: 500;
  color: var(--ha-health-accent);
}

.chronos-insight-links {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chronos-insight-links a {
  font-size: var(--ha-text-sm);
  color: var(--ha-travel-accent);
  text-decoration: none;
  padding: 4px 10px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 6px;
  transition: background 0.15s;
}

.chronos-insight-links a:hover {
  background: rgba(129, 140, 248, 0.2);
}

.chronos-insight-actions {
  display: flex;
  gap: 8px;
}

.chronos-btn {
  font-size: var(--ha-text-sm);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--ha-border);
  background: transparent;
  color: var(--ha-text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.chronos-btn:hover {
  border-color: var(--ha-border-hover);
  color: var(--ha-text);
}

.chronos-btn-details:hover {
  border-color: rgba(139, 92, 246, 0.4);
  color: var(--ha-life-accent);
}

.chronos-btn-dismiss:hover {
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--ha-error);
}

/* Mobile responsiveness */
@media (max-width: 640px) {
  .chronos-panel {
    margin-top: 16px;
  }

  .chronos-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .chronos-insights {
    max-height: 300px;
  }

  .chronos-insight-actions {
    flex-direction: column;
  }

  .chronos-btn {
    width: 100%;
    text-align: center;
  }
}

/* ===== Mission Control Widget ===== */
/* Dashboard widget for Kaizen proposals */

.mc-widget-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--ha-border);
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.05) 0%, rgba(139, 92, 246, 0.03) 100%);
}

.mc-widget-stat {
  text-align: center;
}

.mc-widget-stat-value {
  font-size: var(--ha-text-2xl);
  font-weight: 600;
  color: var(--ha-mission-accent);
  line-height: 1;
}

.mc-widget-stat-label {
  font-size: var(--ha-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ha-text-muted);
  margin-top: 3px;
}

.mc-widget-proposals {
  padding: 12px;
}

.mc-widget-proposal {
  background: var(--ha-surface-2);
  border: 1px solid var(--ha-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: var(--ha-text-base);
  color: var(--ha-text);
  line-height: 1.5;
  transition: all var(--ha-transition-fast);
}

.mc-widget-proposal:hover {
  border-color: var(--ha-mission-accent);
}

.mc-widget-proposal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.mc-widget-proposal-impact {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.mc-widget-proposal-impact.high {
  background: var(--ha-error);
  color: var(--ha-white);
}

.mc-widget-proposal-impact.medium {
  background: var(--ha-eureka-accent);
  color: var(--ha-white);
}

.mc-widget-empty {
  padding: 16px;
  text-align: center;
  color: var(--ha-text-muted);
  font-size: var(--ha-text-base);
}

@media (max-width: 640px) {
  .mc-widget-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

/* ===== Command Palette (Cmd+K) ===== */
.ha-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.15s ease;
}
.ha-palette-overlay.open {
  opacity: 1;
  visibility: visible;
}

.ha-palette {
  position: fixed;
  top: 15%;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  width: 560px;
  max-width: calc(100vw - 40px);
  max-height: 70vh;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border-light);
  border-radius: var(--ha-radius-lg);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
  z-index: 9001;
  opacity: 0;
  visibility: hidden;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ha-palette.open {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.ha-palette-input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--ha-border);
}
.ha-palette-input-wrapper svg {
  width: 18px;
  height: 18px;
  color: var(--ha-text-muted);
  flex-shrink: 0;
}
.ha-palette-input-wrapper input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: var(--ha-font-sans);
  color: var(--ha-text);
}
.ha-palette-input-wrapper input::placeholder {
  color: var(--ha-text-subtle);
}
.ha-palette-shortcut {
  font-family: var(--ha-font-sans);
  font-size: 11px;
  padding: 3px 6px;
  background: var(--ha-surface-2);
  border: 1px solid var(--ha-border);
  border-radius: 4px;
  color: var(--ha-text-subtle);
  white-space: nowrap;
}

.ha-palette-results {
  overflow-y: auto;
  max-height: calc(70vh - 60px);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: var(--ha-space-sm);
}

.ha-palette-group-title {
  font-size: var(--ha-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ha-text-subtle);
  padding: 8px 8px 4px;
  margin-top: var(--ha-space-sm);
}

.ha-palette-group-title:first-child {
  margin-top: 0;
}

.ha-palette-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  border-radius: var(--ha-radius-md);
  border: 1px solid transparent;
}
.ha-palette-item:hover {
  background: var(--ha-surface-2);
  border-color: var(--ha-border);
}
.ha-palette-item.selected {
  background: rgba(96, 165, 250, 0.08);
  border-color: rgba(96, 165, 250, 0.25);
}

.ha-palette-item-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ha-radius-sm);
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
}

.ha-palette-item-content {
  flex: 1;
  min-width: 0;
}
.ha-palette-item-title {
  font-size: var(--ha-text-lg);
  color: var(--ha-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ha-palette-item-subtitle {
  font-size: var(--ha-text-base);
  color: var(--ha-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ha-palette-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ha-text-muted);
  font-size: var(--ha-text-md);
}

/* Hints bar - subtle, disappears when typing */
.ha-palette-hints {
  display: flex;
  gap: 8px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--ha-border);
  background: var(--ha-surface-2);
}
.ha-palette-hint {
  font-size: 10px;
  font-family: var(--ha-font-mono);
  color: var(--ha-text-subtle);
  padding: 2px 6px;
  background: var(--ha-surface);
  border-radius: 3px;
}

/* Match highlighting */
.ha-palette-item-title mark {
  background: rgba(96, 165, 250, 0.3);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

/* ===== Mobile Responsive System ===== */

/* Mobile hamburger menu button */
.ha-mobile-menu-btn {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--ha-text);
  cursor: pointer;
  border-radius: var(--ha-radius-sm);
  transition: background var(--ha-transition-fast);
  flex-shrink: 0;
}

.ha-mobile-menu-btn:hover,
.ha-mobile-menu-btn:active {
  background: var(--ha-hover-strong);
}

.ha-mobile-menu-btn svg {
  width: 22px;
  height: 22px;
}

/* Mobile drawer overlay */
.ha-mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  transition: all var(--ha-transition-normal);
  -webkit-tap-highlight-color: transparent;
}

.ha-mobile-drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* Slide-out drawer */
.ha-mobile-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 85%;
  max-width: 320px;
  height: 100%;
  background: var(--ha-surface);
  border-right: 1px solid var(--ha-border);
  z-index: 9999;
  transform: translateX(-100%);
  transition: transform var(--ha-transition-smooth);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ha-mobile-drawer.open {
  transform: translateX(0);
}

.ha-mobile-drawer-header {
  padding: 16px 20px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--ha-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  flex-shrink: 0;
}

.ha-mobile-drawer-title {
  font-size: var(--ha-text-lg);
  font-weight: 600;
  color: var(--ha-text);
}

.ha-mobile-drawer-close {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--ha-text-muted);
  cursor: pointer;
  border-radius: var(--ha-radius-sm);
  transition: background var(--ha-transition-fast);
}

.ha-mobile-drawer-close:hover,
.ha-mobile-drawer-close:active {
  background: var(--ha-hover-strong);
  color: var(--ha-text);
}

.ha-mobile-drawer-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* App list in drawer */
.ha-mobile-app-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ha-mobile-app-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--ha-radius-md);
  text-decoration: none;
  color: var(--ha-text);
  transition: background var(--ha-transition-fast);
  min-height: 52px;
  font-size: var(--ha-text-md);
}

.ha-mobile-app-item:hover,
.ha-mobile-app-item:active {
  background: var(--ha-surface-2);
}

.ha-mobile-app-item.active {
  background: rgba(96, 165, 250, 0.12);
}

.ha-mobile-app-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ha-mobile-drawer-section {
  padding: 20px 16px 8px;
  font-size: var(--ha-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ha-text-muted);
}

.ha-mobile-drawer-divider {
  height: 1px;
  background: var(--ha-border);
  margin: 12px 0;
}

/* Home link in drawer */
.ha-mobile-home-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--ha-radius-md);
  text-decoration: none;
  color: var(--ha-text);
  transition: background var(--ha-transition-fast);
  min-height: 52px;
  font-size: var(--ha-text-md);
  margin-bottom: 8px;
}

.ha-mobile-home-link:hover,
.ha-mobile-home-link:active {
  background: var(--ha-surface-2);
}

.ha-mobile-home-link svg {
  width: 20px;
  height: 20px;
  color: var(--ha-text-muted);
}

/* Desktop-only elements */
.ha-desktop-only {
  display: flex;
}

/* ===== Mobile Breakpoint Overrides ===== */

/* Show hamburger at 840px and below */
@media (max-width: 840px) {
  .ha-mobile-menu-btn {
    display: flex;
  }

  /* Hide desktop app switcher */
  .ha-app-switcher {
    display: none;
  }

  /* Ensure main content scrolls */
  .ha-main {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  /* Fix body overflow for mobile scrolling */
  body {
    overflow: auto;
    overflow-x: hidden;
  }

  /* Lock body when drawer is open */
  body:has(.ha-mobile-drawer.open) {
    overflow: hidden;
  }
}

/* Small mobile: keep header-nav visible but compact */
@media (max-width: 640px) {
  /* Override the display:none rule */
  .ha-header-nav {
    display: flex !important;
    gap: var(--ha-space-sm);
  }

  /* Hide back button on mobile - use drawer instead */
  .ha-header-nav .ha-back-btn {
    display: none;
  }

  /* Compact header title */
  .ha-header-title {
    font-size: 14px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* Smaller claude notes button */
  .ha-claude-btn {
    padding: 8px 12px;
    font-size: 11px;
  }

  .ha-claude-btn svg {
    width: 14px;
    height: 14px;
  }

  /* ===== Touch-Friendly Component Styles ===== */

  /* Buttons - minimum 44px touch target */
  .ha-btn {
    min-height: 44px;
    padding: 12px 16px;
  }

  .ha-btn-sm {
    min-height: 40px;
    padding: 10px 14px;
  }

  .ha-btn-icon {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  /* Form inputs - prevent iOS zoom with 16px font */
  .ha-input,
  .ha-textarea,
  .ha-select,
  .ha-dropdown-trigger,
  .ha-datepicker-trigger {
    min-height: 44px;
    padding: 12px;
    font-size: 16px;
  }

  /* Tags */
  .ha-tag {
    padding: 8px 14px;
    font-size: 13px;
  }

  /* Navigation buttons */
  .ha-nav-btn {
    min-height: 44px;
    padding: 12px 14px;
  }

  /* Dropdown items */
  .ha-dropdown-item,
  .ha-app-switcher-item {
    min-height: 44px;
    padding: 12px 16px;
  }

  /* Todo items */
  .todo-item {
    padding: 14px;
    min-height: 56px;
  }

  .todo-checkbox {
    width: 24px;
    height: 24px;
  }

  /* Card actions */
  .ha-card-action,
  .ha-card-menu-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
  }

  /* Tab buttons */
  .ha-tab,
  .sub-tab {
    min-height: 44px;
    padding: 10px 16px;
  }

  /* ===== Context Menu Mobile (Action Sheet Style) ===== */
  .ha-context-menu {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: 8px !important;
    width: auto !important;
    max-width: none !important;
    border-radius: var(--ha-radius-lg);
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }

  .ha-context-menu-item {
    min-height: 48px;
    padding: 14px 16px;
    justify-content: center;
  }

  /* ===== Modal Mobile Fixes ===== */
  .ha-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    height: 100%;
    border-radius: 0;
    margin: 0;
  }

  .ha-modal-body {
    padding: var(--ha-space-lg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
  }

  .ha-modal-header {
    padding: var(--ha-space-lg);
    padding-top: calc(var(--ha-space-lg) + env(safe-area-inset-top, 0px));
  }

  .ha-modal-footer {
    padding: var(--ha-space-lg);
    padding-bottom: calc(var(--ha-space-lg) + env(safe-area-inset-bottom, 0px));
  }

  /* Claude notes modal */
  .ha-claude-modal,
  .ha-claude-overlay .ha-claude-modal {
    width: 100% !important;
    max-width: 100% !important;
    height: 100%;
    border-radius: 0;
  }

  /* Command palette on mobile */
  .ha-palette {
    width: 100%;
    max-width: 100%;
    top: 0;
    border-radius: 0;
    max-height: 100vh;
    height: 100vh;
  }

  /* ===== Home Page Mobile ===== */
  .ha-home-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .ha-home-card {
    grid-column: span 1 !important;
    min-height: 120px;
    padding: 16px;
  }

  .home-header {
    padding: 16px;
  }

  .home-header h1 {
    font-size: 20px;
  }

  /* Hide keyboard shortcuts on mobile */
  .ha-shortcuts,
  .ha-shortcuts-list,
  .shortcut-hint {
    display: none !important;
  }

  /* Spacing adjustments */
  .ha-card-grid {
    gap: 14px;
  }

  .ha-card-content {
    padding: 14px;
  }

  /* Stats grid mobile */
  .ha-stats-grid,
  .stats-row {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

/* ===== iOS Safe Area Insets ===== */
@supports (padding: env(safe-area-inset-top)) {
  .ha-header {
    padding-top: env(safe-area-inset-top);
  }

  .ha-mobile-drawer {
    padding-top: env(safe-area-inset-top);
  }

  @media (max-width: 640px) {
    .ha-main {
      padding-bottom: calc(var(--ha-space-xl) + env(safe-area-inset-bottom));
    }

    .ha-simple-main {
      padding-bottom: calc(40px + env(safe-area-inset-bottom));
    }
  }
}

/* ===== Mobile Horizontal Tab Bar ===== */
.ha-mobile-tabs {
  display: none;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 16px;
  gap: 6px;
  background: var(--ha-surface);
  border-bottom: 1px solid var(--ha-border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-height: 48px;
  align-items: stretch;
}

.ha-mobile-tabs::-webkit-scrollbar {
  display: none;
}

.ha-mobile-tab {
  flex-shrink: 0;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ha-text-muted);
  font-size: 13px;
  font-family: var(--ha-font-sans);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--ha-transition-fast);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.ha-mobile-tab:hover {
  color: var(--ha-text);
}

.ha-mobile-tab.active {
  color: var(--ha-accent);
  border-bottom-color: var(--ha-accent);
}

@media (max-width: 840px) {
  .ha-mobile-tabs {
    display: flex;
  }
}

/* ===== Mobile Header Reorganization ===== */
@media (max-width: 640px) {
  /* Use flexbox ordering for header layout */
  .ha-header {
    display: flex;
    align-items: center;
    gap: var(--ha-space-sm);
  }

  .ha-header-nav {
    display: contents;
  }

  /* Order: Back (1), Notes (2), Title (3), Hamburger (4) */
  .ha-back-btn {
    order: 1;
    display: flex !important;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  .ha-back-btn svg {
    width: 18px;
    height: 18px;
  }

  /* Hide "Back" text on mobile, show only icon */
  .ha-back-btn span,
  .ha-back-btn:not(:has(svg))::after {
    display: none;
  }

  .ha-claude-btn {
    order: 2;
  }

  .ha-header-title {
    order: 3;
    flex: 1;
    text-align: left;
  }

  .ha-mobile-menu-btn {
    order: 4;
    margin-left: auto;
  }

  .ha-app-switcher {
    display: none !important;
  }
}
