/* ═══════════════════════════════════════════════════════════════════════════
   OpenPilot Component Library
   Uses Tier 2 semantic tokens exclusively — no raw values
   Fully compliant with platform.md §10-§11
   ═══════════════════════════════════════════════════════════════════════════ */

@import './tokens.css';

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
html {
  font-family: var(--font-sans);
  font-size: var(--font-size-body);
  line-height: var(--line-height-relaxed);
  color: var(--text-default);
  background: var(--surface-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color-scheme: light dark;
}
body {
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Focus styles (WCAG 2.4.7, 2.4.13) ─────────────────────────────────── */
:focus-visible {
  outline: var(--focus-ring-width) solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

/* ── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-neutral-300);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-neutral-400); }

/* ── Skip to content (WCAG 2.4.1) ──────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-inset-md);
  z-index: 10000;
  padding: var(--space-inset-sm) var(--space-inset-md);
  background: var(--surface-raised);
  color: var(--text-default);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-semibold);
  transition: top var(--motion-duration-fast) var(--motion-ease-standard);
}
.skip-link:focus { top: var(--space-2); }

/* ═══════════════════════════════════════════════════════════════════════════
   BUTTONS (platform.md §10-§11)
   ═══════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-inline-sm);
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-body-sm);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: all var(--motion-duration-fast) var(--motion-ease-standard);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary */
.btn-primary {
  background: var(--action-primary);
  color: var(--action-primary-text);
  border-color: var(--action-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--action-primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--action-primary-active); transform: scale(0.98); }

/* Secondary / Ghost */
.btn-secondary {
  background: var(--action-secondary);
  color: var(--action-secondary-text);
  border-color: var(--action-secondary-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--action-secondary-hover); }

/* Danger */
.btn-danger {
  background: var(--action-danger);
  color: var(--action-danger-text);
  border-color: var(--action-danger);
}
.btn-danger:hover:not(:disabled) { background: var(--action-danger-hover); }

/* Icon only */
.btn-icon {
  padding: var(--space-2);
  min-width: var(--touch-target-min);
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-icon:hover { background: var(--action-secondary-hover); color: var(--text-default); }

/* ── Button sizes ── */
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--font-size-caption); min-height: 36px; }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--font-size-body); }

/* ═══════════════════════════════════════════════════════════════════════════
   INPUTS & FORM CONTROLS
   ═══════════════════════════════════════════════════════════════════════════ */
.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-raised);
  color: var(--text-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-body-sm);
  line-height: var(--line-height-normal);
  transition: border-color var(--motion-duration-fast) var(--motion-ease-standard),
              box-shadow var(--motion-duration-fast) var(--motion-ease-standard);
  min-height: var(--touch-target-min);
}
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  outline: none;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }

.form-textarea {
  resize: vertical;
  min-height: 80px;
  max-height: 320px;
  line-height: var(--line-height-relaxed);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23727a88' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
  cursor: pointer;
}

.form-label {
  display: block;
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CHIPS / TAGS
   ═══════════════════════════════════════════════════════════════════════════ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  background: var(--surface-secondary);
  cursor: pointer;
  transition: all var(--motion-duration-fast) var(--motion-ease-standard);
  user-select: none;
  min-height: 28px;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-secondary); }
.chip.active {
  background: var(--action-primary);
  border-color: var(--action-primary);
  color: var(--action-primary-text);
}

/* ═══════════════════════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-inset-md);
  box-shadow: var(--elevation-raised);
}
.card-header {
  padding-bottom: var(--space-stack-sm);
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-stack-md);
}
.card-title {
  font-size: var(--font-size-h4);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
}

/* ═══════════════════════════════════════════════════════════════════════════
   MESSAGES / BUBBLES
   ═══════════════════════════════════════════════════════════════════════════ */
.message {
  display: flex;
  gap: var(--space-3);
  max-width: 85%;
  animation: msgFadeIn var(--motion-duration-base) var(--motion-ease-decelerate);
}
@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.message.assistant { align-self: flex-start; }

.message-avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--font-size-body-sm);
  flex-shrink: 0;
  line-height: 1;
}
.message.user .message-avatar { background: var(--action-primary); color: var(--action-primary-text); }
.message.assistant .message-avatar { background: var(--color-green-500); color: var(--color-neutral-0); }

.message-bubble {
  background: var(--bubble-assist-bg);
  color: var(--bubble-assist-text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-body-sm);
  line-height: var(--line-height-relaxed);
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.message.user .message-bubble {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
}
.message-bubble pre {
  background: var(--surface-sunken);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--font-size-code);
  margin: var(--space-2) 0;
  max-width: 600px;
}
.message-bubble code {
  font-family: var(--font-mono);
  font-size: var(--font-size-code);
  background: var(--surface-sunken);
  padding: 1px 5px;
  border-radius: 3px;
}
.message.user .message-bubble code { background: rgba(255,255,255,0.15); }

/* ── Tool use block inside message ── */
.tool-block {
  background: var(--bubble-tool-bg);
  border: 1px solid var(--bubble-tool-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  margin: var(--space-2) 0;
  font-family: var(--font-mono);
  font-size: var(--font-size-caption);
}
.tool-block-header {
  display: flex; align-items: center; gap: var(--space-2);
  color: var(--color-amber-600); font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-1);
}
.tool-block-input {
  color: var(--text-secondary);
  max-height: 100px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.tool-block-output {
  color: var(--color-green-600);
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: var(--space-1);
  padding-top: var(--space-1);
  border-top: 1px solid var(--border-default);
}

/* ═══════════════════════════════════════════════════════════════════════════
   STATUS INDICATORS
   ═══════════════════════════════════════════════════════════════════════════ */
.status-dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-green-500);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.disconnected { background: var(--color-neutral-300); }
.status-dot.error { background: var(--color-red-500); }
.status-text {
  font-size: var(--font-size-caption);
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════════════════════════
   THINKING / LOADING INDICATOR
   ═══════════════════════════════════════════════════════════════════════════ */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  color: var(--text-muted);
  font-size: var(--font-size-body-sm);
  font-style: italic;
}
.thinking-dots { display: flex; gap: 3px; }
.thinking-dots span {
  width: 5px; height: 5px;
  border-radius: var(--radius-full);
  background: var(--action-primary);
  animation: dotBounce 1.4s infinite ease-in-out both;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATE (platform.md §16)
   ═══════════════════════════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-4);
  text-align: center;
  gap: var(--space-3);
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; opacity: 0.25; }
.empty-state-title { font-size: var(--font-size-h4); font-weight: var(--font-weight-medium); color: var(--text-secondary); }
.empty-state-desc { font-size: var(--font-size-body-sm); max-width: 420px; line-height: var(--line-height-relaxed); }

/* ═══════════════════════════════════════════════════════════════════════════
   ERROR STATE
   ═══════════════════════════════════════════════════════════════════════════ */
.error-banner {
  background: var(--feedback-error-bg);
  border: 1px solid var(--feedback-error-border);
  color: var(--feedback-error-text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-body-sm);
  margin: var(--space-3);
}

/* ═══════════════════════════════════════════════════════════════════════════
   OBSERVABILITY ITEMS
   ═══════════════════════════════════════════════════════════════════════════ */
.obs-item {
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-caption);
  font-family: var(--font-mono);
  border-left: 2px solid var(--border-default);
  margin-bottom: var(--space-1);
  color: var(--text-secondary);
  line-height: var(--line-height-snug);
}
.obs-item.thinking   { border-left-color: var(--color-amber-400); }
.obs-item.tool_use   { border-left-color: var(--color-blue-400); }
.obs-item.tool_result { border-left-color: var(--color-green-400); }
.obs-item.error      { border-left-color: var(--color-red-400); color: var(--feedback-error-text); }

/* ═══════════════════════════════════════════════════════════════════════════
   FILE CHANGE ITEM
   ═══════════════════════════════════════════════════════════════════════════ */
.file-change-item {
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--font-size-caption);
}
.file-change-path {
  font-family: var(--font-mono);
  color: var(--text-brand);
  font-size: var(--font-size-caption);
  margin-bottom: var(--space-1);
}
.file-change-diff {
  font-family: var(--font-mono);
  font-size: 10px;
  max-height: 120px;
  overflow-y: auto;
  background: var(--surface-base);
  padding: var(--space-1);
  border-radius: 3px;
  white-space: pre-wrap;
  color: var(--text-secondary);
  margin: var(--space-1) 0;
}
.file-change-status {
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-medium);
}
.file-change-status.accepted { color: var(--color-green-600); }
.file-change-status.rejected { color: var(--color-red-500); }
.file-change-status.pending  { color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   ISSUE ITEM
   ═══════════════════════════════════════════════════════════════════════════ */
.issue-item {
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}
.issue-title {
  font-size: var(--font-size-body-sm);
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-1);
}
.issue-meta {
  display: flex; gap: var(--space-2); flex-wrap: wrap;
  font-size: var(--font-size-caption);
  color: var(--text-muted);
  margin-top: var(--space-1);
}
.issue-status {
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
  font-size: calc(var(--font-size-caption) - 1px);
  font-weight: var(--font-weight-semibold);
}
.issue-status.open { background: var(--color-green-500); color: var(--color-neutral-0); }
.issue-status.in_progress { background: var(--color-amber-500); color: var(--color-neutral-900); }
.issue-status.resolved { background: var(--color-blue-500); color: var(--color-neutral-0); }

/* ═══════════════════════════════════════════════════════════════════════════
   SESSION LIST ITEM
   ═══════════════════════════════════════════════════════════════════════════ */
.session-item {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin-bottom: 1px;
  border-left: 3px solid transparent;
  transition: background var(--motion-duration-fast) var(--motion-ease-standard);
}
.session-item:hover { background: var(--action-secondary-hover); }
.session-item.active {
  background: var(--surface-raised);
  border-left-color: var(--action-primary);
}
.session-item-title {
  font-size: var(--font-size-body-sm);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item-meta {
  font-size: var(--font-size-caption);
  color: var(--text-muted);
  margin-top: 2px;
  display: flex; gap: var(--space-2);
}
.session-item-mode {
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  background: var(--surface-sunken);
  color: var(--text-brand);
}
.session-item-mode.dev { color: var(--color-amber-600); }
.session-item-mode.agent { color: var(--color-green-600); }

/* ═══════════════════════════════════════════════════════════════════════════
   LOADING SKELETON
   ═══════════════════════════════════════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--surface-secondary) 50%, var(--surface-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-line { height: 14px; margin-bottom: var(--space-2); }
.skeleton-line:last-child { width: 60%; }
.skeleton-card { height: 64px; margin-bottom: var(--space-2); }

/* ═══════════════════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════════ */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.hidden { display: none !important; }
.flex-1 { flex: 1; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--font-size-body-sm); }
.font-mono { font-family: var(--font-mono); }

/* ── Responsive visibility ── */
@media (max-width: 767px) {
  .hide-mobile { display: none !important; }
}

/* ── Touch target enforcement ── */
@media (pointer: coarse) {
  .btn, .form-input, .form-select, .chip { min-height: var(--touch-target-min); }
}
