/* ============================================================
   Echo AI Assistant — style.css
   Bright & colorful light theme
   ============================================================ */

/* --- Base Reset & Variables --- */
:root {
  --bg-base:      #f0f2ff;
  --bg-surface:   #ffffff;
  --bg-surface2:  #ebebf8;
  --bg-input:     #fafbff;
  --accent:       #6d28d9;
  --accent-hover: #5b21b6;
  --accent-light: #7c3aed;
  --bubble-user:  #ede9fe;
  --bubble-bot:   #f9fafb;
  --text-primary: #18181b;
  --text-muted:   #52525b;
  --text-dim:     #a1a1aa;
  --border:       #d4d4e8;
  --border-focus: #7c3aed;
  --red:          #dc2626;
  --green:        #16a34a;
  --yellow:       #d97706;
  --teal:         #0d9488;
  --sky:          #0284c7;
  --radius:       0.5rem;
  --radius-lg:    0.75rem;
  --shadow:       0 4px 24px rgba(109,40,217,0.08);
}

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

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-base);
}
::-webkit-scrollbar-thumb {
  background: #c4b5fd;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
* {
  scrollbar-width: thin;
  scrollbar-color: #c4b5fd var(--bg-base);
}

/* ============================================================
   Typography
   ============================================================ */
h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.01em;
}

a {
  color: var(--accent-light);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  color: var(--accent);
}

/* ============================================================
   Layout
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
#app-header {
  background: linear-gradient(135deg, #6d28d9 0%, #4f46e5 60%, #0d9488 100%);
  border-bottom: none;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(109,40,217,0.3);
}

#app-header h1 {
  font-size: 1.125rem;
  color: #ffffff;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

#app-header .header-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  transition: background 0.3s;
  box-shadow: 0 0 6px rgba(74,222,128,0.6);
}
#app-header .header-dot.streaming {
  background: #fbbf24;
  animation: pulse-yellow 1s infinite;
}
#app-header .header-dot.error {
  background: #f87171;
}

/* Main two-column flex */
#main-content {
  display: flex;
  flex: 1;
  gap: 0;
  overflow: hidden;
  height: calc(100vh - 48px - 36px);
}

/* Chat panel */
#chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 0;
  border-right: 1px solid var(--border);
}

/* Tools panel */
#tools-panel {
  width: 340px;
  flex-shrink: 0;
  overflow-y: auto;
  background: #f7f7ff;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Footer */
#app-footer {
  background: linear-gradient(90deg, #6d28d9 0%, #4f46e5 100%);
  border-top: none;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.8);
  height: 36px;
}

/* Responsive — stack on mobile */
@media (max-width: 768px) {
  #main-content {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  #chat-panel {
    height: 60vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #tools-panel {
    width: 100%;
    height: auto;
    max-height: none;
  }
}

/* ============================================================
   Chat Area
   ============================================================ */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg-base);
}

/* Message bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: fade-in 0.2s ease;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message .bubble {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: linear-gradient(135deg, #ede9fe, #ddd6fe);
  border: 1px solid #c4b5fd;
  border-bottom-right-radius: 4px;
  color: #1e1b4b;
}

.message.assistant .bubble {
  background: #ffffff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(109,40,217,0.07);
}

.message .meta {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
  padding: 0 0.25rem;
}

/* Markdown rendered content inside bubbles */
.bubble strong { color: #6d28d9; }
.bubble em { color: var(--text-muted); font-style: italic; }
.bubble ul, .bubble ol {
  margin: 0.4rem 0 0.4rem 1.2rem;
}
.bubble li {
  margin-bottom: 0.2rem;
}
.bubble code {
  background: #f3e8ff;
  color: #6d28d9;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82em;
  border: 1px solid #e9d5ff;
}
.bubble pre {
  background: #1e1b4b;
  border: 1px solid #3730a3;
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8em;
  line-height: 1.5;
}
.bubble pre code {
  background: transparent;
  padding: 0;
  color: #c4b5fd;
  border: none;
}

/* Thinking indicator */
.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.1em 0;
}
.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-light);
  display: inline-block;
  animation: thinking-bounce 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   Input Area
   ============================================================ */
#input-area {
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#msg-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 0.6rem 0.8rem;
  font-family: inherit;
  font-size: 0.875rem;
  resize: none;
  line-height: 1.5;
  transition: border-color 0.2s;
}
#msg-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(109,40,217,0.12);
}
#msg-input::placeholder {
  color: var(--text-dim);
}

.input-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Voice status */
#voice-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--red);
  padding: 0.25rem 0.5rem;
}
#voice-status.hidden { display: none; }

/* Recording red dot */
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse-red 1s infinite;
  flex-shrink: 0;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
  box-shadow: 0 2px 6px rgba(109,40,217,0.3);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #6d28d9, #5b21b6);
  box-shadow: 0 3px 10px rgba(109,40,217,0.4);
}

.btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-surface2);
  border-color: #c4b5fd;
}

.btn-danger {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
}
.btn-danger:hover:not(:disabled) {
  background: #fee2e2;
}

.btn-mic {
  background: #f3f4f6;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 1rem;
  padding: 0.45rem 0.7rem;
}
.btn-mic.recording {
  background: #fef2f2;
  color: var(--red);
  border-color: #fca5a5;
  animation: pulse-border 1s infinite;
}
.btn-mic:hover:not(.recording):not(:disabled) {
  background: var(--bg-surface2);
  border-color: #c4b5fd;
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
}

.btn-full {
  width: 100%;
}

/* ============================================================
   Form Controls
   ============================================================ */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
textarea,
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 0.4rem 0.6rem;
  font-family: inherit;
  font-size: 0.8rem;
  width: 100%;
  transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="datetime-local"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(109,40,217,0.1);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-dim);
}
select option {
  background: #ffffff;
  color: var(--text-primary);
}
textarea {
  resize: vertical;
  min-height: 56px;
}

/* Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #ddd6fe;
  border-radius: 2px;
  border: none;
  padding: 0;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
  box-shadow: 0 1px 4px rgba(109,40,217,0.3);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
input[type="range"]:focus {
  outline: none;
  box-shadow: none;
}
input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(109,40,217,0.2);
}

/* File input */
input[type="file"] {
  background: var(--bg-input);
  border: 1px dashed #c4b5fd;
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
}

/* Labels */
label {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.2rem;
}

/* Slider display value */
.slider-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.slider-row input[type="range"] { flex: 1; }
.slider-value {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
  min-width: 2.5em;
  text-align: right;
}

/* ============================================================
   Tools Panel — details/summary collapsibles
   ============================================================ */
details {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(109,40,217,0.05);
}

details[open] {
  box-shadow: 0 3px 12px rgba(109,40,217,0.1);
  border-color: #c4b5fd;
}

details > summary {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: #6d28d9;
  background: linear-gradient(90deg, #f5f3ff, #ede9fe);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
  transition: background 0.15s;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: '▶';
  font-size: 0.6rem;
  color: #a78bfa;
  transition: transform 0.2s;
}
details[open] > summary::before {
  transform: rotate(90deg);
}
details > summary:hover {
  background: linear-gradient(90deg, #ede9fe, #ddd6fe);
}

.tool-body {
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid #e9d5ff;
  background: #ffffff;
}

/* Subsection label */
.tool-subsection {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding-top: 0.25rem;
  border-top: 1px solid #e0f2f1;
  margin-top: 0.25rem;
}
.tool-body > .tool-subsection:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* Output pre blocks in tool panels */
.tool-output {
  background: #f8f9ff;
  border: 1px solid #e0e0f5;
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  font-size: 0.75rem;
  color: #374151;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  min-height: 2rem;
}

/* Row layout for tool buttons */
.tool-btn-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Model dropdown in header */
#model-select {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius);
  color: #ffffff;
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}
#model-select:focus {
  outline: none;
  border-color: rgba(255,255,255,0.7);
}
#model-select option {
  background: #1e1b4b;
  color: #ffffff;
}

/* Header label */
#app-header label {
  color: rgba(255,255,255,0.8);
}

/* Token count */
#token-count {
  color: var(--text-dim);
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.8); }
}

@keyframes pulse-yellow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251,191,36,0.6); }
  50%       { box-shadow: 0 0 0 5px rgba(251,191,36,0); }
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.3); }
  50%       { box-shadow: 0 0 0 4px rgba(220,38,38,0); }
}

/* ============================================================
   Utility
   ============================================================ */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-accent { color: var(--accent-light); }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
