/* ═══════════════════════════════════════════════════════════════════════════
   OpenPilot Layout — App Shell
   Uses semantic tokens + components
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Header ────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  height: var(--header-height);
  background: var(--surface-header);
  border-bottom: 1px solid var(--border-default);
  z-index: 100;
  flex-shrink: 0;
}
.app-logo {
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-bold);
  color: var(--color-blue-400);
  letter-spacing: -0.5px;
  text-decoration: none;
}
.app-logo span { color: var(--color-green-400); }
.app-nav {
  display: flex; gap: var(--space-1);
  margin-left: var(--space-4);
}
.app-nav .btn {
  background: transparent;
  color: var(--color-neutral-400);
  border: none;
  font-size: var(--font-size-body-sm);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  min-height: 32px;
}
.app-nav .btn:hover { background: rgba(255,255,255,0.08); color: var(--color-neutral-200); }
.app-nav .btn.active { background: rgba(255,255,255,0.12); color: var(--color-blue-400); }
.app-header-actions {
  margin-left: auto;
  display: flex; gap: var(--space-2); align-items: center;
}

/* ── Main Layout Grid ──────────────────────────────────────────────────── */
.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--surface-sidebar);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--motion-duration-base) var(--motion-ease-standard);
}
.app-sidebar.collapsed {
  width: 0;
  border-right: none;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-default);
}
.sidebar-title {
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sidebar-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-1);
}

/* ── Content Area ──────────────────────────────────────────────────────── */
.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── Tab panels ────────────────────────────────────────────────────────── */
.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.tab-panel.active { display: flex; }

/* ── Session View (chat + right panel) ─────────────────────────────────── */
.session-view {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Chat Panel ────────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
}
.chat-messages > * + * { margin-top: var(--space-3); }
.chat-input-area {
  border-top: 1px solid var(--border-default);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-secondary);
  flex-shrink: 0;
}
.chat-config-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}
.chat-config-bar .form-label { margin-bottom: 0; }
.chat-config-bar .form-select {
  width: auto;
  min-width: 140px;
  min-height: 36px;
}
.chat-tools-row {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}
.chat-input-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}
.chat-input-row .form-textarea {
  flex: 1;
  min-height: 44px;
  max-height: 200px;
  resize: none;
  line-height: var(--line-height-relaxed);
}

/* ── Right Panel ───────────────────────────────────────────────────────── */
.right-panel {
  width: var(--right-panel-width);
  background: var(--surface-secondary);
  border-left: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
.panel-section {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-default);
}
.panel-section-title {
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-2);
  display: flex; align-items: center; gap: var(--space-2);
}

/* ── Issues Page ───────────────────────────────────────────────────────── */
.issues-page {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}
.issues-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
}
.issues-header h2 {
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-semibold);
}
.issues-list { display: flex; flex-direction: column; gap: var(--space-2); }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  :root {
    --right-panel-width: 100%;
    --sidebar-width: 240px;
  }
  .right-panel { display: none; }
  .right-panel.mobile-visible { display: flex; }
  .session-view { flex-direction: column; }
}

@media (max-width: 767px) {
  :root { --sidebar-width: 100%; }
  .app-sidebar {
    position: fixed; top: var(--header-height); left: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
  }
  .app-sidebar.mobile-open { transform: translateX(0); }
  .app-sidebar-overlay {
    display: none;
    position: fixed; inset: 0; top: var(--header-height);
    background: rgba(0,0,0,0.4);
    z-index: 49;
  }
  .app-sidebar-overlay.visible { display: block; }

  .chat-config-bar { flex-direction: column; align-items: flex-start; }
  .chat-input-row { flex-direction: column; }
  .issues-header { flex-direction: column; gap: var(--space-3); align-items: flex-start; }
}

/* ── Theme Toggle ──────────────────────────────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid var(--color-neutral-600);
  color: var(--color-neutral-400);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--font-size-caption);
  min-height: 32px;
}
.theme-toggle:hover { border-color: var(--color-neutral-400); color: var(--color-neutral-200); }
