/* ExplainToMe — BMW-inspired design system */

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

:root {
  --white: #ffffff;
  --black: #262626;
  --blue: #1c69d4;
  --blue-focus: #0653b6;
  --gray-meta: #757575;
  --gray-silver: #bbbbbb;
  --bg-dark: #0a0a0a;
  --bg-surface: #111111;
  --bg-panel: #0d0d0d;
  --border: #1a1a1a;
  --input-bg: #1a1a1a;
  --input-border: #2a2a2a;
  --text-primary: #ffffff;
  --text-secondary: #d4d4d4;
  --text-muted: #555555;
  --scrollbar: #2a2a2a;
  --viewer-empty-bg: #f5f5f5;
  --loader-track: #e0e0e0;
  --font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

:root.light {
  --white: #ffffff;
  --black: #262626;
  --gray-meta: #666666;
  --gray-silver: #999999;
  --bg-dark: #f5f5f5;
  --bg-surface: #ffffff;
  --bg-panel: #fafafa;
  --border: #e0e0e0;
  --input-bg: #f0f0f0;
  --input-border: #d0d0d0;
  --text-primary: #262626;
  --text-secondary: #444444;
  --text-muted: #999999;
  --scrollbar: #d0d0d0;
  --viewer-empty-bg: #f0f0f0;
  --loader-track: #d0d0d0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.15;
  font-weight: 400;
}

/* ── Top Bar ── */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  flex-shrink: 0;
}

.topbar-url {
  flex: 1;
  display: flex;
  gap: 0;
}

.topbar-url input {
  flex: 1;
  height: 36px;
  padding: 0 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-right: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  border-radius: 0;
}

.topbar-url input::placeholder {
  color: var(--gray-meta);
}

.topbar-url input:focus {
  border-color: var(--blue);
}

#go-btn {
  height: 36px;
  padding: 0 20px;
  background: var(--blue);
  color: #ffffff;
  border: none;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 0;
}

#go-btn:hover {
  background: var(--blue-focus);
}

.topbar-level {
  display: flex;
  gap: 0;
  flex-shrink: 0;
}

.level-btn {
  height: 36px;
  padding: 0 14px;
  background: transparent;
  color: var(--gray-meta);
  border: 1px solid var(--input-border);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 0;
  transition: all 0.15s;
}

.level-btn + .level-btn {
  border-left: none;
}

.level-btn:hover {
  color: var(--text-primary);
  background: var(--input-bg);
}

.level-btn.active {
  color: #ffffff;
  background: var(--blue);
  border-color: var(--blue);
}

/* ── Theme Toggle ── */

.theme-toggle {
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--gray-meta);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 0;
  flex-shrink: 0;
  transition: all 0.15s;
}

.theme-toggle:hover {
  color: var(--text-primary);
  background: var(--input-bg);
}

/* ── Main Layout ── */

.main {
  display: flex;
  height: calc(100vh - 56px - 24px);
}

/* ── Footer ── */

.site-footer {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  letter-spacing: 0.03em;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--blue);
}

/* ── Content Viewer ── */

.viewer {
  flex: 1;
  position: relative;
  background: var(--white);
  overflow: hidden;
}

.viewer-empty,
.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--viewer-empty-bg);
}

.viewer-empty-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--black);
}

.viewer-empty-sub {
  font-size: 14px;
  color: var(--gray-meta);
}

.viewer-loading p {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--gray-meta);
}

.loader {
  width: 32px;
  height: 32px;
  border: 2px solid var(--loader-track);
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite;
}

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

#content-frame {
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Selection floating button ── */

.explain-fab {
  position: fixed;
  z-index: 9999;
  padding: 6px 16px;
  background: var(--blue);
  color: #ffffff;
  border: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  border-radius: 0;
  pointer-events: auto;
}

.explain-fab:hover {
  background: var(--blue-focus);
}

/* ── Panel ── */

.panel {
  width: 420px;
  min-width: 420px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.2s, min-width 0.2s;
}

.panel.collapsed {
  width: 0;
  min-width: 0;
}

.panel.collapsed .panel-content,
.panel.collapsed .panel-input-area {
  display: none;
}

.panel-toggle {
  position: absolute;
  left: -28px;
  top: 12px;
  width: 28px;
  height: 28px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-right: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--gray-meta);
  z-index: 10;
}

.panel-toggle:hover {
  color: var(--text-primary);
}

.panel .panel-toggle svg {
  transform: rotate(180deg);
}

.panel.collapsed .panel-toggle svg {
  transform: rotate(0deg);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  text-align: center;
}

.panel-empty-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--gray-meta);
}

.panel-empty-sub {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 260px;
  line-height: 1.4;
}

.panel-empty-level {
  font-size: 12px;
  color: var(--blue);
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-top: 4px;
  max-width: 280px;
  line-height: 1.4;
  text-align: center;
}

/* ── Selection display ── */

.panel-selection {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.panel-selection-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--gray-meta);
  margin-bottom: 8px;
}

.panel-selection-text {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  padding: 10px;
  background: var(--input-bg);
  border-left: 3px solid var(--blue);
  max-height: 120px;
  overflow-y: auto;
}

/* ── Chat Messages ── */

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-msg {
  font-size: 14px;
  line-height: 1.6;
}

.chat-msg.assistant {
  color: var(--text-secondary);
}

.chat-msg.assistant p {
  margin-bottom: 8px;
}

.chat-msg.assistant h1,
.chat-msg.assistant h2,
.chat-msg.assistant h3 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-primary);
  margin: 16px 0 8px;
}

.chat-msg.assistant h1:first-child,
.chat-msg.assistant h2:first-child,
.chat-msg.assistant h3:first-child {
  margin-top: 0;
}

.chat-msg.assistant ul,
.chat-msg.assistant ol {
  padding-left: 18px;
  margin-bottom: 8px;
}

.chat-msg.assistant li {
  margin-bottom: 4px;
}

.chat-msg.assistant code {
  background: var(--input-bg);
  padding: 2px 6px;
  font-size: 13px;
  color: var(--blue);
}

.chat-msg.assistant pre {
  background: var(--input-bg);
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
}

.chat-msg.assistant pre code {
  padding: 0;
  background: none;
}

.chat-msg.assistant strong {
  color: var(--text-primary);
  font-weight: 700;
}

.chat-msg.assistant a {
  color: var(--blue);
  text-decoration: none;
}

.chat-msg.assistant a:hover {
  text-decoration: underline;
}

.chat-msg.user {
  color: var(--gray-meta);
  font-style: italic;
  padding: 8px 10px;
  border-left: 2px solid var(--input-border);
}

.chat-msg .typing-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--blue);
  margin-left: 2px;
  animation: blink 0.8s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ── Panel Input ── */

.panel-input-area {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.panel-input-wrap {
  display: flex;
  gap: 0;
}

.panel-input-wrap input {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-right: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  border-radius: 0;
}

.panel-input-wrap input::placeholder {
  color: var(--text-muted);
}

.panel-input-wrap input:focus {
  border-color: var(--blue);
}

#chat-send {
  width: 36px;
  height: 36px;
  background: var(--blue);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 0;
}

#chat-send:hover {
  background: var(--blue-focus);
}

/* ── Utilities ── */

.hidden {
  display: none !important;
}

/* ── Highlight in iframe content ── */

::selection {
  background: rgba(28, 105, 212, 0.3);
}

/* ── Scrollbar styling ── */

.panel-content::-webkit-scrollbar,
.panel-selection-text::-webkit-scrollbar {
  width: 4px;
}

.panel-content::-webkit-scrollbar-track,
.panel-selection-text::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb,
.panel-selection-text::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 8px;
  }

  .topbar-brand {
    font-size: 14px;
  }

  .topbar-url {
    flex: 1;
    min-width: 0;
  }

  .topbar-url input {
    height: 32px;
    font-size: 13px;
    padding: 0 10px;
  }

  #go-btn {
    height: 32px;
    padding: 0 12px;
    font-size: 12px;
  }

  .topbar-level {
    order: 1;
    flex: 1;
  }

  .level-btn {
    flex: 1;
    height: 28px;
    padding: 0 6px;
    font-size: 10px;
  }

  .theme-toggle {
    order: 1;
    width: 28px;
    height: 28px;
  }

  .main {
    height: calc(100vh - 80px - 24px);
    flex-direction: column;
  }

  .viewer {
    flex: 1;
  }

  .panel {
    width: 100%;
    min-width: 100%;
    position: fixed;
    right: 0;
    top: 80px;
    bottom: 24px;
    transform: translateX(100%);
    transition: transform 0.2s;
    z-index: 100;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .panel:not(.collapsed) {
    transform: translateX(0);
  }

  .panel.collapsed {
    transform: translateX(100%);
  }

  .panel-toggle {
    left: -28px;
    top: 8px;
  }

  .site-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 101;
  }
}
