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

:root {
  --mac-black:    #0d0d0d;
  --mac-charcoal: #1a1a1a;
  --mac-dark:     #252525;
  --mac-mid:      #3a3a3a;
  --mac-border:   rgba(255,255,255,0.08);
  --mac-white:    #f5f0eb;
  --mac-cream:    #e8ddd3;
  --mac-red:      #c8102e;
  --mac-red-glow: rgba(200,16,46,0.25);
  --mac-gold:     #c9a96e;
  --mac-gold-lt:  #e8c98a;
  --mac-pink:     #e8a0b4;
  --mac-pink-lt:  #f5c6d5;
  --mac-nude:     #c4956a;
  --mac-glass:    rgba(255,255,255,0.04);
  --mac-glass-h:  rgba(255,255,255,0.08);
  --chat-max:     800px;
  --radius:       16px;
  --radius-sm:    10px;
  --shadow:       0 8px 32px rgba(0,0,0,0.45);
  --transition:   0.25s cubic-bezier(0.4,0,0.2,1);
  --text-primary:   #f5f0eb;
  --text-secondary: rgba(255,255,255,0.6);
  --text-muted:     rgba(255,255,255,0.3);
}

/* ── Light theme ─────────────────────────────────────── */
[data-theme="light"] {
  --mac-black:    #ffffff;
  --mac-charcoal: #f7f5f3;
  --mac-dark:     #eeebe8;
  --mac-mid:      #d4cfc9;
  --mac-border:   rgba(0,0,0,0.08);
  --mac-white:    #2c2a28;
  --mac-cream:    #3d3a36;
  --mac-glass:    rgba(0,0,0,0.03);
  --mac-glass-h:  rgba(0,0,0,0.06);
  --text-primary:   #2c2a28;
  --text-secondary: rgba(0,0,0,0.55);
  --text-muted:     rgba(0,0,0,0.35);
  --shadow:         0 8px 32px rgba(0,0,0,0.1);
}

html, body {
  height: 100%;
  background: var(--mac-black);
  color: var(--mac-white);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

button, input, textarea, select {
  font: inherit;
}

button, .nav-tab, .icon-btn, .user-pill, .login-btn {
  -webkit-tap-highlight-color: transparent;
}

/* ── Full-page layout ────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: var(--app-height, 100dvh);
}

/* ── Top nav bar ─────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 36px;
  height: 84px;
  background: var(--mac-charcoal);
  border-bottom: 1px solid var(--mac-border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand-logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 5px;
  text-transform: uppercase;
  color: var(--mac-white);
}

/* Tabs */
.nav-tabs {
  display: flex;
  gap: 4px;
}

.nav-tab {
  padding: 8px 18px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.3px;
}

.nav-tab:hover {
  background: var(--mac-glass-h);
  color: var(--mac-white);
}

.nav-tab.active {
  background: var(--mac-glass-h);
  color: var(--mac-white);
}

.nav-tab.active::after {
  content: '';
  display: block;
  height: 2px;
  background: var(--mac-red);
  border-radius: 1px;
  margin-top: 4px;
}

/* VTO Toggle switch */
.vto-toggle-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.vto-toggle-wrap input { display: none; }
.vto-toggle-slider {
  width: 36px; height: 20px;
  background: var(--mac-mid);
  border-radius: 10px;
  position: relative;
  transition: background 0.25s ease;
}
.vto-toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--mac-white);
  transition: transform 0.25s ease;
}
.vto-toggle-wrap input:checked + .vto-toggle-slider {
  background: var(--mac-red);
}
.vto-toggle-wrap input:checked + .vto-toggle-slider::after {
  transform: translateX(16px);
}
[data-theme="light"] .vto-toggle-slider { background: var(--mac-mid); }
[data-theme="light"] .vto-toggle-slider::after { background: #fff; }
[data-theme="light"] .vto-toggle-wrap input:checked + .vto-toggle-slider { background: var(--mac-red); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Small icon buttons */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--mac-border);
  background: var(--mac-glass);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  font-size: 15px;
}

.icon-btn:hover {
  background: var(--mac-glass-h);
  color: var(--mac-white);
  border-color: rgba(255,255,255,0.15);
}

.icon-btn.active {
  background: var(--mac-red);
  border-color: var(--mac-red);
  color: white;
  box-shadow: 0 0 12px var(--mac-red-glow);
}

/* User pill in topbar */
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 20px;
  background: var(--mac-glass);
  border: 1px solid var(--mac-border);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.user-pill:hover {
  background: var(--mac-glass-h);
}

.user-pill-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mac-gold), var(--mac-nude));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  overflow: hidden;
}

.user-pill-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-pill-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--mac-white);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-pill-badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.user-pill-badge.dev {
  background: rgba(34,197,94,0.15);
  color: #4ade80;
}

.user-pill-badge.guest {
  background: rgba(201,169,110,0.15);
  color: var(--mac-gold-lt);
}

/* User dropdown */
.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--mac-charcoal);
  border: 1px solid var(--mac-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  min-width: 160px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 50;
}

.user-dropdown.open { display: block; }

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--mac-white);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
  transition: background var(--transition);
}

.user-dropdown-item:hover { background: var(--mac-glass-h); }

.user-dropdown-item.danger { color: #ff6b7a; }

.vto-toggle-row {
  justify-content: space-between;
  cursor: default;
}
.vto-toggle-row:hover { background: var(--mac-glass-h); }

/* Voice waveform */
.voice-wave { display: none; align-items: center; gap: 2px; padding: 0 6px; }
.voice-wave.active { display: flex; }
.wave-bar { width: 2px; border-radius: 1px; background: var(--mac-gold); animation: wave 0.8s infinite; }
.wave-bar:nth-child(1) { height: 6px; }
.wave-bar:nth-child(2) { height: 10px; animation-delay: 0.1s; }
.wave-bar:nth-child(3) { height: 8px; animation-delay: 0.2s; }
.wave-bar:nth-child(4) { height: 12px; animation-delay: 0.3s; }
.wave-bar:nth-child(5) { height: 6px; animation-delay: 0.4s; }
@keyframes wave { 0%, 100% { transform: scaleY(0.5); opacity: 0.6; } 50% { transform: scaleY(1); opacity: 1; } }

/* ── Page panels ─────────────────────────────────────── */
.page-panel { flex: 1; display: none; flex-direction: column; overflow: hidden; position: relative; }
.page-panel.active { display: flex; }

/* ── Login / landing page ────────────────────────────── */
#login-page { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; background: var(--mac-black); }
#login-page.hidden { display: none; }
.login-card { text-align: center; padding: 48px 40px; max-width: 520px; width: 100%; }
.login-logo { font-family: 'Cormorant Garamond', serif; font-size: 40px; font-weight: 500; letter-spacing: 8px; text-transform: uppercase; color: var(--mac-white); margin-bottom: 8px; }
.login-tagline { font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: var(--mac-gold); font-weight: 300; margin-bottom: 40px; }
.login-icon { font-size: 56px; margin-bottom: 24px; filter: drop-shadow(0 4px 16px var(--mac-red-glow)); }
.login-title { font-family: 'Cormorant Garamond', serif; font-size: 28px; font-weight: 300; letter-spacing: 1px; color: var(--mac-white); margin-bottom: 8px; }
.login-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 36px; line-height: 1.6; }
.login-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px; border-radius: var(--radius-sm); border: 1px solid var(--mac-border); font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 500; cursor: pointer; transition: all var(--transition); letter-spacing: 0.5px; margin-bottom: 12px; }
.login-btn.sso { background: linear-gradient(135deg, var(--mac-red), #9a0d24); border-color: var(--mac-red); color: white; }
.login-btn.sso:hover { box-shadow: 0 4px 20px var(--mac-red-glow); transform: translateY(-1px); }
.login-btn.guest { background: var(--mac-glass); color: var(--mac-white); }
.login-btn.guest:hover { background: var(--mac-glass-h); border-color: rgba(255,255,255,0.15); }
.login-footer { margin-top: 32px; font-size: 11px; color: var(--text-muted); }

/* ── Toast ───────────────────────────────────────────── */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--mac-dark); border: 1px solid var(--mac-border); color: var(--mac-cream); padding: 10px 20px; border-radius: 20px; font-size: 13px; z-index: 300; transition: transform 0.3s ease; pointer-events: none; }
#toast.show { transform: translateX(-50%) translateY(0); }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1024px) {
  #topbar { padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left)); }
  .topbar-left { gap: 16px; min-width: 0; }
  .brand-logo { letter-spacing: 4px; }
  .nav-tab { padding: 8px 14px; min-height: 40px; }
}

@media (max-width: 768px) {
  #topbar {
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    height: 64px;
    gap: 10px;
  }
  .brand-logo { font-size: 18px; letter-spacing: 3px; white-space: nowrap; }
  .topbar-left { gap: 10px; flex: 1; min-width: 0; }
  .topbar-right { gap: 6px; }
  .nav-tabs { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tab { font-size: 12px; padding: 6px 10px; min-height: 44px; white-space: nowrap; }
  .icon-btn { width: 44px; height: 44px; }
  .user-pill { min-height: 44px; padding-right: 8px; }
  .user-pill-name { display: none; }
  .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; padding: 12px; }
  .catalog-card-img { padding: 12px; }
  .catalog-card { min-height: auto; }
}

@media (max-width: 600px) {
  .brand-logo { font-size: 16px; letter-spacing: 2px; }
  .topbar-left { gap: 8px; }
  .nav-tab { font-size: 11px; padding: 6px 8px; }
  .user-pill-badge { display: none; }
}

@media (max-width: 480px) {
  #topbar { height: 60px; }
  .brand-logo { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
  .nav-tabs { flex: 1; }
  .nav-tab { flex: 1 0 auto; justify-content: center; }
  .login-card { padding: 32px 20px; }
  .login-logo { font-size: 30px; letter-spacing: 5px; }
  #toast { width: calc(100vw - 32px); text-align: center; bottom: max(16px, env(safe-area-inset-bottom)); }
}
