* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100%;     /* fallback */
  height: 100dvh;   /* dynamic viewport — shrinks with keyboard on mobile */
  width: 100%;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  height: 100dvh;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s ease;
}

.sidebar-header {
  padding: 17px 8px 17px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 10px;
  font-size: 13px;
  font-weight: 500;
}

.sidebar-logo-img {
  height: 22px;
  width: auto;
}

/* Sidebar date row */
.sidebar-date-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 0;
}

.sidebar-date-chip {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: border-color 0.15s;
  white-space: nowrap;
}
.sidebar-date-chip:hover { border-color: var(--border-focus); }
.sidebar-date-chip.open { border-color: var(--accent); }

.sidebar-date-nav {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  padding: 8px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
  flex-shrink: 0;
}
.sidebar-date-nav:hover { border-color: var(--border-focus); }

/* Track animation — uses global enter tokens */
@keyframes trackIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes trackOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(6px); }
}
.track-in { animation: trackIn var(--enter-duration) var(--enter-easing) both; }
.track-out { animation: trackOut 180ms ease-in both; }

/* Track list */
.sidebar-tracks {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 8px;
  flex-shrink: 0;
  max-height: 40vh;
  transition: max-height 0.25s ease, padding 0.25s ease;
}
.sidebar-tracks:empty,
.sidebar-tracks:has(.sidebar-tracks-empty) {
  padding: 0 8px;
}

.sidebar-tracks-empty {
  padding: 12px 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.sidebar-track-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.12s;
}
.sidebar-track-item:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-track-item.active {
  background: var(--bg-active);
  color: var(--text);
}

.sidebar-track-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.sidebar-track-time {
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.sidebar-track-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Section label */
.sidebar-section-label {
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 10px 16px 4px;
}

/* History list */
.sidebar-history {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.history-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.12s;
  position: relative;
}
.history-item:hover { background: var(--bg-hover); color: var(--text); }
.history-item.active { background: var(--bg-active); color: var(--text); }

.history-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-date {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}


/* User profile footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.12s;
}
.sidebar-footer:hover { background: var(--bg-hover); }

.user-avatar {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}

.user-tier-badge {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 400;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
}

.user-tier {
  font-size: 11px;
  color: var(--text-dim);
}

.usage-bar {
  height: 3px;
  background: var(--bg-hover);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}
.usage-bar-fill.full {
  background: var(--error, #e54);
}

/* Prominent bar for anonymous free-tier users */
.sidebar-footer.tier-free .usage-bar {
  height: 6px;
  margin-top: 6px;
  border-radius: 3px;
}
.sidebar-footer.tier-free .user-tier {
  color: var(--text-dim);
  font-size: 10px;
}

/* ── Main Area ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  height: 100dvh;
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}

.mobile-header {
  display: none;
  padding: 8px 16px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mobile-header-info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.mobile-header-track {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-header-badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn-hamburger {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: transform 0.2s ease;
}
.sidebar.open ~ .main .btn-hamburger { transform: rotate(180deg); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
