@import "design-tokens.css";

/* L2 navigation */
.l2-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.l2-tab {
  padding: var(--space-2) var(--space-5);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast), background var(--duration-fast);
}
.l2-tab:hover { color: var(--text); background: var(--surface-hover); }
.l2-tab.active { color: var(--text); background: var(--bg); }

/* === LIGHT-FIRST OVERRIDES === */
:root {
  color-scheme: light;
  --bg:            #ffffff;
  --surface:       #f4f5f7;
  --surface-hover: #ecedf0;
  --card:          #ffffff;
  --border:        #d4d7de;
  --text:          #1a1d27;
  --text-muted:    #636981;
  --green:         #0f9960;
  --red:           #d93025;
  --yellow:        #b45309;
  --blue:          #2563eb;
  --overlay:       rgba(0, 0, 0, 0.3);
  --btn-contrast:  #ffffff;

  /* Backward-compat aliases (old LLM-Router var names -> shared tokens) */
  --font-base:      var(--font-sans);
  --font-mono:      var(--font-mono);
  --bg-page:        var(--bg);
  --bg-surface:     var(--card);
  --bg-user:        var(--surface);
  --bg-hover:       var(--surface-hover);
  --bg-active:      var(--text);
  --text-primary:   var(--text);
  --text-secondary: var(--text-muted);
  --text-inverse:   var(--btn-contrast);
  --border-light:   var(--border);
  --border-focus:   var(--text);
  --status-healthy: var(--green);
  --status-error:   var(--red);

  /* Spacing aliases */
  --space-xs: var(--space-2);
  --space-sm: var(--space-4);
  --space-md: var(--space-5);
  --space-lg: var(--space-6);
  --space-xl: var(--space-8);
}

/* === DARK THEME === */
[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0f1117;
  --surface:       #1a1d27;
  --surface-hover: #222632;
  --card:          #1a1d27;
  --border:        #2a2e3a;
  --text:          #e1e4eb;
  --text-muted:    #8b90a0;
  --green:         #34d399;
  --red:           #f87171;
  --yellow:        #fbbf24;
  --blue:          #60a5fa;
  --overlay:       rgba(0, 0, 0, 0.5);
  --btn-contrast:  #000000;
}

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

body {
  font-family: var(--font-base);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
  height: 100vh;
  overflow: hidden;
}

/* === FOCUS === */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === LAYOUT === */
.app-layout {
  display: flex;
  height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-light);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) 0;
}

.conv-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-sm) var(--space-lg);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.conv-item:hover {
  background: var(--bg-hover);
}

.conv-item.active {
  background: var(--bg-user);
  border-left-color: var(--border-focus);
}

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

.conv-title {
  font-size: var(--text-sm);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.4;
}

.conv-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  padding: 2px 4px;
  opacity: 0;
  transition: opacity 0.1s;
}

.conv-item:hover .conv-delete {
  opacity: 1;
}

.conv-delete:hover {
  color: var(--status-error);
}

/* === MAIN PANEL === */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* === TOPBAR === */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) var(--space-lg);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.topbar-right {
  position: relative;
}

.param-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.topbar select,
.topbar input[type="number"] {
  font-size: var(--text-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-surface);
  color: var(--text-primary);
}

.topbar input[type="number"] {
  width: 64px;
}

.topbar select {
  min-width: 120px;
}

/* === TOGGLE GROUP === */
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.toggle-btn {
  font-size: var(--text-sm);
  padding: var(--space-xs) var(--space-md);
  border: none;
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
}

.toggle-btn.active {
  background: var(--bg-active);
  color: var(--text-inverse);
}

.toggle-btn:hover:not(.active) {
  background: var(--bg-hover);
}

/* === SETTINGS DROPDOWN === */
.settings-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: var(--space-md);
  min-width: 220px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.settings-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: block;
  margin-bottom: var(--space-xs);
}

.settings-input {
  width: 100%;
  font-size: var(--text-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: var(--space-sm);
}

.settings-dropdown hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: var(--space-sm) 0;
}

/* === CHAT AREA === */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
}

.chat-messages {
  max-width: 720px;
  margin: 0 auto;
}

.message {
  margin-bottom: var(--space-lg);
}

.message-role {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-xs);
}

.message-content {
  font-size: var(--text-base);
  line-height: 1.7;
  word-break: break-word;
  color: var(--text-primary);
}

.message-user .message-content {
  background: var(--bg-user);
  padding: var(--space-md) var(--space-lg);
  border-radius: 6px;
  white-space: pre-wrap;
}

.message-content p { margin: 0 0 12px 0; }
.message-content p:last-child { margin-bottom: 0; }

.message-content h1, .message-content h2, .message-content h3, .message-content h4 {
  margin: 20px 0 8px 0;
  font-weight: 600;
  line-height: 1.3;
}
.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 15px; }
.message-content h4 { font-size: 14px; }
.message-content *:first-child { margin-top: 0; }

.message-content pre {
  background: #282c34;
  color: #abb2bf;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  border: 1px solid rgba(255,255,255,0.06);
}
.message-content pre:empty { display: none; }

.message-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  color: #c7254e;
}
[data-theme="dark"] .message-content code {
  background: rgba(255,255,255,0.08);
  color: #e06c75;
}
.message-content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

.message-content ul, .message-content ol {
  margin: 8px 0;
  padding-left: 24px;
}
.message-content li { margin-bottom: 4px; line-height: 1.6; }
.message-content li p { margin-bottom: 4px; }

.message-content blockquote {
  border-left: 3px solid var(--border);
  margin: 12px 0;
  padding: 8px 16px;
  color: var(--text-secondary);
  background: var(--bg-page);
  border-radius: 0 4px 4px 0;
}
.message-content blockquote p:last-child { margin-bottom: 0; }

.message-content hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 16px 0;
}

.message-content table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
  font-size: 13px;
}
.message-content th, .message-content td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
}
.message-content th { background: var(--bg-page); font-weight: 600; }

.message-content a { color: var(--blue); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }

.message-content em { font-style: italic; }
.message-content strong { font-weight: 600; }
.message-content img { max-width: 100%; border-radius: 4px; }

.message-metrics {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-xs);
  line-height: 1.4;
}

/* === STREAMING CURSOR === */
.streaming-cursor::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--text-primary);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

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

.streaming-status {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: var(--space-sm) 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.streaming-status::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* === COMPARE UI === */
.compare-container {
  display: flex;
  gap: var(--space-lg);
}

.compare-panel {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: var(--space-md);
  background: var(--bg-surface);
}

.compare-header {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border-light);
}

.compare-content {
  font-size: var(--text-base);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.compare-metrics {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-sm);
  padding-top: var(--space-xs);
  border-top: 1px solid var(--border-light);
}

.compare-spinner {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.compare-error {
  color: var(--status-error);
  font-size: var(--text-sm);
  padding: var(--space-md);
}

/* === INPUT AREA === */
.input-area {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.input-area textarea {
  flex: 1;
  font-family: var(--font-base);
  font-size: var(--text-base);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: 4px;
  resize: none;
  outline: none;
  line-height: 1.5;
  background: var(--bg-surface);
  color: var(--text-primary);
}

.input-area textarea:focus {
  border-color: var(--border-focus);
}

/* === METRICS PANEL === */
.metrics-panel {
  width: 220px;
  min-width: 220px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  padding: var(--space-md) var(--space-lg);
  overflow-y: auto;
}

.metrics-panel.hidden {
  display: none;
}

.metrics-group {
  margin-top: var(--space-lg);
}

.metrics-subheader {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-sm);
}

.metric-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  font-size: var(--text-xs);
  line-height: 1.4;
}

.metric-label {
  color: var(--text-muted);
}

.metric-value {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.health-status {
  font-size: var(--text-xs);
}

.health-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.health-name {
  color: var(--text-muted);
}

.health-ok {
  color: var(--status-healthy);
}

.health-down {
  color: var(--status-error);
}

/* Model status indicators */
.model-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-left: 4px;
}
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.status-dot-ok {
  background: var(--status-healthy);
  box-shadow: 0 0 4px var(--status-healthy);
}
.status-dot-down {
  background: var(--status-error);
  box-shadow: 0 0 4px var(--status-error);
}

/* === BUTTONS === */
.btn {
  font-family: var(--font-base);
  font-size: var(--text-sm);
  padding: var(--space-xs) var(--space-md);
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn:active {
  opacity: 0.8;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--bg-active);
  color: var(--text-inverse);
  border-color: var(--bg-active);
}

.btn-primary:hover {
  opacity: 0.9;
  background: var(--bg-active);
}

.btn-danger {
  color: var(--status-error);
  border-color: var(--status-error);
}

.btn-danger:hover {
  background: var(--status-error);
  color: var(--text-inverse);
}

.btn-sm {
  font-size: var(--text-xs);
  padding: 2px var(--space-sm);
}

.btn-stop {
  background: var(--status-error);
  color: var(--text-inverse);
  border-color: var(--status-error);
}

.btn-stop:hover {
  opacity: 0.9;
}

/* === SECTION LABEL === */
.section-label {
  font-size: var(--text-lg);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.4;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-surface);
  padding: var(--space-xl);
  border-radius: 4px;
  width: 360px;
  max-width: 90vw;
}

.modal-content h2 {
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.modal-content input {
  width: 100%;
  font-size: var(--text-base);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: var(--space-md);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.modal-content input:focus {
  border-color: var(--border-focus);
  outline: none;
}

.modal-content .btn {
  width: 100%;
}

.auth-error {
  color: var(--status-error);
  font-size: var(--text-sm);
  margin-bottom: var(--space-sm);
}

/* === EMPTY STATES === */
.empty-state {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: var(--space-md) var(--space-lg);
}

.center-empty {
  text-align: center;
  padding-top: 120px;
}

/* === ERROR STATES === */
.error-badge {
  display: inline-block;
  font-size: var(--text-xs);
  color: var(--status-error);
  margin-top: var(--space-xs);
}

.retry-btn {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px var(--space-sm);
  cursor: pointer;
  margin-left: var(--space-xs);
}

.retry-btn:hover {
  background: var(--bg-hover);
}

/* === THEME TOGGLE === */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: color var(--duration-fast), border-color var(--duration-fast);
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* === UTILITIES === */
.text-muted {
  color: var(--text-muted);
}

.hidden {
  display: none;
}
