/* ═══════════════════════════════════════════════════════════════════════
   Jarvis PWA — Design System
   CSS Custom Properties + Responsive Layout
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* Colors — Dark Theme */
  --color-bg: #0f0f23;
  --color-surface: #1a1a2e;
  --color-surface-hover: #222240;
  --color-border: #333355;
  --color-border-light: #444466;
  --color-text: #e0e0e0;
  --color-text-dim: #888;
  --color-text-muted: #666;
  --color-accent: #00d4ff;
  --color-accent-hover: #00b8e0;
  --color-accent-dim: rgba(0, 212, 255, 0.12);
  --color-success: #4caf50;
  --color-error: #ef5350;
  --color-warning: #ffa726;
  --color-approve: #4caf50;
  --color-reject: #ef5350;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 14px;
  --font-size-lg: 16px;
  --font-size-xl: 18px;
  --font-size-2xl: 24px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 50%;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;

  /* Layout */
  --header-height: 52px;
  --max-content-width: 1200px;
}

/* ── Global Reset ─────────────────────────────────────────────────── */

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

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Layout ───────────────────────────────────────────────────── */

.app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ── Header ───────────────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  z-index: 10;
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.app-logo {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: -0.5px;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  transition: background var(--transition-base);
}
.connection-dot.connected { background: var(--color-success); }
.connection-dot.disconnected { background: var(--color-error); }

.app-nav {
  display: flex;
  gap: var(--space-xs);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  color: var(--color-text-dim);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
}
.nav-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}
.nav-btn-active {
  color: var(--color-bg);
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.nav-btn-active:hover {
  color: var(--color-bg);
  background: var(--color-accent-hover);
}

/* ── Main ─────────────────────────────────────────────────────────── */

.app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-panel.with-canvas {
  flex: 1;
}

.canvas-panel {
  width: 45%;
  min-width: 300px;
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
}

/* ── Chat ─────────────────────────────────────────────────────────── */

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  scroll-behavior: smooth;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-md);
  color: var(--color-text-dim);
}

.chat-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: var(--color-accent-dim);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-2xl);
  font-weight: 700;
}

.chat-bubble {
  max-width: 85%;
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-md);
  border-radius: var(--radius-lg);
  word-break: break-word;
  animation: bubble-in 200ms ease;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-bubble-user {
  margin-left: auto;
  background: var(--color-accent-dim);
  border: 1px solid rgba(0, 212, 255, 0.25);
}

.chat-bubble-assistant {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.chat-bubble-text {
  font-size: var(--font-size-base);
  line-height: 1.6;
  white-space: pre-wrap;
}

.chat-bubble-time {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-md) var(--space-lg);
}
.chat-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-text-dim);
  animation: typing-bounce 1.4s infinite;
}
.chat-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Status bar */
.chat-status {
  padding: var(--space-xs) var(--space-lg);
  font-size: var(--font-size-xs);
  color: var(--color-text-dim);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  text-align: center;
  font-style: italic;
}

/* Input bar */
.chat-input-bar {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.chat-input {
  flex: 1;
  padding: var(--space-md) var(--space-lg);
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-family: var(--font-sans);
  outline: none;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  transition: border-color var(--transition-fast);
}
.chat-input:focus {
  border-color: var(--color-accent);
}
.chat-input::placeholder {
  color: var(--color-text-muted);
}

.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: var(--color-accent);
  color: var(--color-bg);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.chat-send-btn:hover:not(:disabled) {
  background: var(--color-accent-hover);
}
.chat-send-btn:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: default;
}

/* ── Canvas ───────────────────────────────────────────────────────── */

.canvas-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-surface);
}

.canvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.canvas-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.canvas-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  color: var(--color-text-dim);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.canvas-close-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.canvas-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--color-surface);
}

/* ── Voice Controls ───────────────────────────────────────────────── */

.voice-controls {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  display: flex;
  gap: var(--space-sm);
  z-index: 20;
}

.voice-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: var(--color-bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
}
.voice-btn:hover:not(:disabled) {
  background: var(--color-accent-hover);
  transform: scale(1.05);
}
.voice-btn:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: default;
}
.voice-btn.recording {
  background: var(--color-error);
  color: white;
  animation: pulse-ring 1.5s infinite;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(239, 83, 80, 0.5); }
  70% { box-shadow: 0 0 0 12px rgba(239, 83, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 83, 80, 0); }
}

.talk-mode-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text-dim);
  border: 1px solid var(--color-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  align-self: flex-end;
}
.talk-mode-btn:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.talk-mode-btn.active {
  background: var(--color-accent-dim);
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.talk-mode-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Settings ─────────────────────────────────────────────────────── */

.settings-container {
  max-width: 600px;
  margin: 0 auto;
  padding: var(--space-xl);
  width: 100%;
}

.settings-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  margin-bottom: var(--space-xl);
}

.settings-group {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.settings-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.settings-subtitle {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.settings-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  margin-bottom: var(--space-md);
  line-height: 1.5;
}

.settings-version {
  font-size: var(--font-size-sm);
  color: var(--color-accent);
  font-weight: 500;
  margin-bottom: var(--space-xs);
}

.settings-input {
  width: 100%;
  padding: var(--space-md);
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-family: var(--font-mono);
  outline: none;
  transition: border-color var(--transition-fast);
}
.settings-input:focus {
  border-color: var(--color-accent);
}

.settings-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.settings-btn {
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.settings-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.settings-btn-primary {
  background: var(--color-accent);
  color: var(--color-bg);
}
.settings-btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
}
.settings-btn-secondary {
  background: var(--color-surface-hover);
  color: var(--color-text);
}
.settings-btn-secondary:hover:not(:disabled) {
  background: var(--color-border);
}

.settings-status {
  margin-top: var(--space-sm);
  font-size: var(--font-size-sm);
}

.status-ok {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-success);
}

.status-error {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-error);
}

.settings-shortcuts {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--font-size-sm);
}

.shortcut-row kbd {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

/* ── Approval Dialog ──────────────────────────────────────────────── */

.approval-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-in 200ms ease;
  padding: var(--space-lg);
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.approval-dialog {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: dialog-in 250ms ease;
}

@keyframes dialog-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.approval-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  margin-bottom: var(--space-lg);
  color: var(--color-warning);
}

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

.approval-field {
  margin-bottom: var(--space-sm);
  font-size: var(--font-size-sm);
}
.approval-field strong {
  margin-right: var(--space-xs);
}
.approval-field code {
  background: var(--color-bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

.approval-params {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  margin-top: var(--space-xs);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  overflow-x: auto;
  max-height: 120px;
  white-space: pre-wrap;
}

.approval-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.approval-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.approval-btn-approve {
  background: var(--color-approve);
  color: white;
}
.approval-btn-approve:hover {
  filter: brightness(1.1);
}

.approval-btn-reject {
  background: var(--color-reject);
  color: white;
}
.approval-btn-reject:hover {
  filter: brightness(1.1);
}

/* ── Responsive ───────────────────────────────────────────────────── */

/* Mobile: < 640px */
@media (max-width: 639px) {
  .app-header {
    padding: 0 var(--space-md);
  }

  .app-logo {
    font-size: var(--font-size-lg);
  }

  .nav-btn {
    padding: var(--space-sm);
    font-size: var(--font-size-xs);
  }
  .nav-btn svg {
    display: none;
  }

  .canvas-panel {
    display: none; /* Canvas hidden on mobile, use full screen */
  }
  .chat-panel.with-canvas {
    flex: 1;
  }

  .chat-bubble {
    max-width: 92%;
  }

  .chat-input-bar {
    padding: var(--space-sm) var(--space-md);
  }

  .voice-controls {
    bottom: 80px;
    right: var(--space-md);
  }

  .voice-btn {
    width: 44px;
    height: 44px;
  }

  .talk-mode-btn {
    width: 32px;
    height: 32px;
  }

  .settings-container {
    padding: var(--space-lg);
  }

  .approval-dialog {
    padding: var(--space-lg);
  }

  .approval-actions {
    flex-direction: column;
  }
}

/* Tablet: 640px - 1024px */
@media (min-width: 640px) and (max-width: 1023px) {
  .canvas-panel {
    width: 40%;
    min-width: 280px;
  }
}

/* Desktop: > 1024px */
@media (min-width: 1024px) {
  .chat-messages {
    padding: var(--space-xl);
  }

  .chat-bubble {
    max-width: 70%;
  }
}

/* Safe area for mobile browsers */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-input-bar {
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  }
  .voice-controls {
    bottom: calc(var(--space-xl) + env(safe-area-inset-bottom));
  }
}

/* ── Scrollbar ────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-light);
}

/* ── Focus Styles ─────────────────────────────────────────────────── */

*:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-accent);
  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;
  }
}
