:root {
  --bg: #ffffff;
  --bg-card: #f8fafc;
  --bg-card-hover: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-dim: #64748b;
  --accent: #0891b2;
  --accent2: #0d9488;
  --accent3: #0e7490;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --bar-bg: #f1f5f9;
  --input-bg: #ffffff;
  --msg-user: #0891b2;
  --msg-ai: #f1f5f9;
}

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

html {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
}

/* --- Login Page --- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  height: 100dvh;
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  margin-bottom: 8px;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

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

.error-msg {
  color: var(--red);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}

/* --- Chat Page --- */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.chat-header .title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

.chat-header .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.chat-header .user-name {
  color: var(--text);
  font-weight: 500;
}

.chat-header .role-badge {
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}
.logout-btn:hover { border-color: var(--red); color: var(--red); }

/* Messages */
.messages {
  flex: 1 1 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
  flex-shrink: 0;
}

.message.user {
  align-self: flex-end;
  background: var(--msg-user);
  color: #ffffff;
  border: none;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--msg-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message a {
  color: var(--accent3);
  text-decoration: underline;
  word-break: break-all;
}
.message a:hover { color: var(--accent); }
.message code {
  background: var(--input-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.message .msg-time {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Message wrapper — relative for copy button positioning */
.message-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
  flex-shrink: 0;
}
.message-wrap.user { align-items: flex-end; }

.message-wrap .copy-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  margin-top: 2px;
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
}
.message-wrap:hover .copy-btn,
.message-wrap .copy-btn:focus { opacity: 0.7; }
.message-wrap .copy-btn:active { opacity: 1; }
.message-wrap .copy-btn.copied { opacity: 1; color: var(--green); }

/* Mobile: always show copy button */
@media (max-width: 600px) {
  .message-wrap .copy-btn { opacity: 0.5; }
}
@media (pointer: coarse) {
  .message-wrap .copy-btn { opacity: 0.5; }
}

/* Chat-Bilder */
/* Chat Media — Bilder */
.message-image {
  margin-top: 8px;
  max-width: 85%;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}
.message-image img {
  width: 100%;
  max-width: 420px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
  display: block;
}
.message-image img:hover {
  transform: scale(1.02);
  filter: brightness(1.05);
}
.message-image .image-prompt {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 24px 12px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  font-size: 11px;
  color: rgba(255,255,255,0.8);
  border-radius: 0 0 14px 14px;
  opacity: 0;
  transition: opacity 0.2s;
}
.message-image:hover .image-prompt { opacity: 1; }

/* Chat Media — Dokumente */
.message-document {
  margin-top: 8px;
  max-width: 85%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.message-document:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}
.message-document .doc-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.message-document .doc-icon.pdf { background: rgba(255,68,102,0.15); color: var(--red); }
.message-document .doc-icon.doc { background: rgba(102,178,255,0.15); color: var(--accent3); }
.message-document .doc-icon.file { background: rgba(136,136,170,0.15); color: var(--text-dim); }
.message-document .doc-info { flex: 1; min-width: 0; }
.message-document .doc-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.message-document .doc-meta {
  font-size: 11px; color: var(--text-dim); margin-top: 2px;
}
.message-document .doc-download {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: rgba(179,102,255,0.12);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

/* Lightbox Overlay */
.media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  animation: lbFadeIn 0.2s ease-out;
  touch-action: none;
}
@keyframes lbFadeIn { from { opacity: 0; } to { opacity: 1; } }

.media-lightbox .lb-toolbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 12px 16px;
  z-index: 10001;
  background: linear-gradient(rgba(0,0,0,0.5), transparent);
}
.media-lightbox .lb-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: white;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.media-lightbox .lb-btn:hover { background: rgba(255,255,255,0.2); }
.media-lightbox .lb-btn svg { width: 20px; height: 20px; }

.media-lightbox .lb-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  cursor: grab;
}
.media-lightbox .lb-image-wrap:active { cursor: grabbing; }
.media-lightbox .lb-image-wrap img {
  max-width: 95vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 6px;
  transition: transform 0.15s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.media-lightbox .lb-caption {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  text-align: center;
  padding: 20px 24px 24px;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  line-height: 1.5;
}

/* Zoom indicator */
.media-lightbox .lb-zoom-level {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.media-lightbox .lb-zoom-level.visible { opacity: 1; }

/* Video in Lightbox */
.media-lightbox .lb-video-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  padding: 60px 16px 16px;
}
.media-lightbox .lb-video-wrap video {
  max-width: 95vw;
  max-height: 85vh;
  border-radius: 12px;
  outline: none;
}

/* PDF / Document in Lightbox */
.media-lightbox .lb-pdf-wrap {
  width: 90vw;
  height: 85vh;
  margin-top: 50px;
}
.media-lightbox .lb-pdf-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 12px;
  background: white;
}

/* Audio in Lightbox */
.media-lightbox .lb-audio-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  padding: 40px;
  text-align: center;
}
.media-lightbox .lb-audio-icon { font-size: 64px; }
.media-lightbox .lb-audio-name {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  max-width: 400px;
  word-break: break-all;
}
.media-lightbox .lb-audio-wrap audio {
  width: 80vw;
  max-width: 500px;
}

/* Inline Video in Chat */
.message-video {
  position: relative;
  cursor: pointer;
  margin: 8px 0;
  display: inline-block;
  border-radius: 12px;
  overflow: hidden;
}
.message-video video {
  max-width: 280px;
  max-height: 200px;
  border-radius: 12px;
  display: block;
  pointer-events: none;
}
.message-video .play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.message-video:hover .play-overlay { background: rgba(0,0,0,0.7); }
.message-video .play-overlay svg { margin-left: 4px; }

/* Inline Audio in Chat */
.message-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-card-hover);
  border-radius: 12px;
  margin: 8px 0;
  max-width: 340px;
}
.message-audio .audio-icon { font-size: 20px; flex-shrink: 0; }
.message-audio audio {
  width: 100%;
  max-width: 260px;
  height: 32px;
}
.message-audio .audio-name {
  font-size: 11px;
  color: var(--text-dim);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Inline image in text (markdown ![alt](url)) */
.inline-image {
  margin: 8px 0;
  max-width: 100%;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s;
}
.inline-image:hover { transform: scale(1.02); }

.typing-indicator {
  padding: 12px 16px;
  color: var(--text-dim);
  font-style: italic;
  display: none;
  flex-shrink: 0;
}
.typing-indicator.visible { display: block; }

/* Thinking Status — Live-Anzeige waehrend Agent arbeitet */
.thinking-status-indicator {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin: 8px 16px;
  background: rgba(8, 145, 178, 0.08);
  border-radius: 12px;
  border-left: 3px solid var(--accent);
  animation: thinking-fade-in 0.3s ease;
}
.thinking-status-indicator.active { display: flex; }

.thinking-dots {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinking-bounce 1.4s infinite ease-in-out both;
}
.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0s; }

.thinking-status-text {
  font-size: 13px;
  color: var(--text-dim, #a0a0a0);
  font-style: italic;
  transition: opacity 0.2s ease;
}

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}
@keyframes thinking-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Input Area */
.chat-input-area {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex: 1;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 44px;
  line-height: 1.4;
}

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

.send-btn, .voice-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.send-btn {
  background: var(--accent);
  color: white;
}
.send-btn:hover { opacity: 0.9; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.voice-btn {
  background: var(--bar-bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.voice-btn:hover { border-color: var(--accent); color: var(--accent); }
.voice-btn.recording {
  background: var(--red);
  border-color: var(--red);
  color: white;
  animation: pulse 1.5s infinite;
}
.voice-btn.recording.speaking {
  background: var(--green);
  border-color: var(--green);
  animation: pulse-speak 0.8s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
@keyframes pulse-speak {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.1); }
}

/* Connection Status */
.connection-status {
  text-align: center;
  padding: 4px;
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bar-bg);
  display: none;
  flex-shrink: 0;
}
.connection-status.disconnected {
  display: block;
  background: var(--red);
  color: white;
}

/* ============================================================
   Tools Panel — iOS Sheet Design
   ============================================================ */

/* Header toggle button */
.tools-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  min-height: 34px;
  min-width: 44px;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.tools-toggle:hover { border-color: var(--accent); color: var(--accent); }
.tools-toggle:active { transform: scale(0.96); }
.portal-link {
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  transition: all 0.2s;
}
.portal-link:hover { border-color: var(--accent); color: var(--accent); }
.tools-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(8, 145, 178, 0.1);
}

/* Backdrop overlay */
.tools-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease-out;
}
.tools-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Sheet container */
.tools-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 910;
  max-height: calc(100dvh - 48px);
  background: var(--bg-card);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.tools-sheet.visible {
  transform: translateY(0);
}
/* When dragging — no transition so it follows the finger */
.tools-sheet.dragging {
  transition: none;
}

/* Drag handle */
.tools-sheet-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.tools-handle-bar {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.18);
}

/* Sheet header */
.tools-sheet-header {
  padding: 4px 20px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.tools-sheet-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.tools-sheet-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.tools-close-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 50%;
  transition: color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  margin: -8px -8px -8px 0;
}
.tools-close-btn:hover { color: var(--text); }
.tools-close-btn:active { opacity: 0.7; }

/* Plan row */
.tools-plan-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.tools-plan-badge {
  background: var(--accent);
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.tools-stats {
  font-size: 0.8rem;
  color: var(--text-dim);
}
.tools-stats .stat-value {
  color: var(--text);
  font-weight: 600;
}

/* Progress bar */
.tools-progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}
.tools-progress-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.32, 0.72, 0, 1);
  width: 0%;
}

/* Scrollable body */
.tools-sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 0;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  min-height: 0;
}

/* Category section — iOS grouped list style */
.tools-category {
  margin-bottom: 4px;
}

.tools-category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 16px 20px 6px;
}
.tools-category-header .cat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Grouped list container */
.tools-list {
  margin: 0 16px;
  background: var(--input-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Individual tool row */
.tool-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  min-height: 48px;
  position: relative;
  transition: background-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.tool-row:active {
  background: rgba(255, 255, 255, 0.04);
}

/* Row separator — iOS style, indented from left */
.tool-row + .tool-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 56px;
  right: 0;
  height: 1px;
  background: var(--border);
  opacity: 0.5;
}

/* Tool icon container */
.tool-row .tool-icon-wrap {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.85rem;
}

/* Icon backgrounds by status */
.tool-row.available .tool-icon-wrap {
  background: rgba(68, 204, 136, 0.12);
  color: var(--green);
}
.tool-row.locked .tool-icon-wrap {
  background: rgba(136, 136, 170, 0.1);
  color: var(--text-dim);
}

/* Tool label */
.tool-row .tool-label {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-row.locked .tool-label {
  color: var(--text-dim);
}

/* Status indicator — right side */
.tool-row .tool-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Active green dot */
.tool-row .tool-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.tool-row.available .tool-dot {
  background: var(--green);
  box-shadow: 0 0 6px rgba(68, 204, 136, 0.4);
}

/* Lock badge */
.tool-row .tool-lock-badge {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tool-row .tool-lock-badge svg {
  width: 11px;
  height: 11px;
  opacity: 0.6;
}

/* Risk indicator dots */
.tool-row .tool-risk {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tool-row .tool-risk.low { background: var(--green); opacity: 0.4; }
.tool-row .tool-risk.medium { background: var(--yellow); opacity: 0.5; }
.tool-row .tool-risk.high { background: var(--red); opacity: 0.5; }

/* Download row in tools sheet */
.download-row {
  display: flex;
  align-items: center;
}
.download-row .tool-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-left: auto;
  margin-right: 12px;
  white-space: nowrap;
}
.download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.download-btn:hover {
  background: var(--accent2);
}
.download-btn:active {
  transform: scale(0.92);
}

/* Empty state */
.tools-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}
.tools-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  color: var(--text-dim);
}
.tools-empty h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.tools-empty p {
  font-size: 0.85rem;
  color: var(--text-dim);
  max-width: 260px;
  line-height: 1.4;
}

/* Loading skeleton */
.tools-skeleton {
  padding: 0 16px;
}
.tools-skeleton-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.tools-skeleton-circle {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  animation: toolsShimmer 1.2s ease-in-out infinite;
}
.tools-skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  animation: toolsShimmer 1.2s ease-in-out infinite;
}
.tools-skeleton-line.w60 { width: 60%; }
.tools-skeleton-line.w40 { width: 40%; }
.tools-skeleton-line.w80 { width: 80%; }

@keyframes toolsShimmer {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* Entrance animation for rows */
.tool-row {
  animation: toolRowIn 0.3s ease-out both;
}
@keyframes toolRowIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .tools-sheet,
  .tools-backdrop,
  .tools-progress-fill,
  .tool-row {
    transition: none;
    animation: none;
  }
}

/* Desktop: larger sheets, centered */
@media (min-width: 768px) {
  .tools-sheet {
    left: 50%;
    right: auto;
    width: 480px;
    max-height: calc(100dvh - 80px);
    border-radius: 16px;
    bottom: 24px;
    transform: translate(-50%, 120%);
    box-shadow: 0 -8px 60px rgba(0, 0, 0, 0.5);
  }
  .tools-sheet.visible {
    transform: translate(-50%, 0);
  }
  .tools-sheet-handle { display: none; }
  .tools-list { margin: 0 20px; }
  .tools-category-header { padding-left: 24px; padding-right: 24px; }
  .tools-sheet-header { padding: 16px 24px 14px; }
}

/* Admin Panel */
.admin-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}
.admin-toggle:hover { border-color: var(--accent); color: var(--accent); }

.admin-panel {
  display: none;
  padding: 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 40vh;
  overflow-y: auto;
}
.admin-panel.visible { display: block; }

.admin-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--accent);
}

.admin-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-panel th, .admin-panel td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.admin-panel th { color: var(--text-dim); font-weight: 500; }

.admin-panel .add-user-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.admin-panel .add-user-form input,
.admin-panel .add-user-form select {
  padding: 8px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
}

.admin-panel .add-user-form button {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 600px) {
  .message { max-width: 90%; }
  .chat-header { padding: 10px 14px; }
  .chat-header .user-info { gap: 6px; font-size: 0.75rem; }
  .chat-header .role-badge { display: none; }
  .messages { padding: 12px; }
  .chat-input-area { padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0)); }

  /* Tools sheet already handles mobile via its own responsive rules */
}

/* ================================================================
   Task Status Bar
   ================================================================ */
.task-status-bar {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.task-status-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.task-status-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim, #888);
}
.task-status-icon {
  font-size: 14px;
  flex-shrink: 0;
}
.task-status-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text, #eee);
}
.task-status-age {
  flex-shrink: 0;
  font-size: 11px;
  opacity: 0.6;
}
.task-progress-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.task-progress-fill {
  height: 100%;
  background: var(--accent, #6c5ce7);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* Voice Emotion Indicator */
.voice-emotion-indicator {
  position: absolute;
  bottom: 100%;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  margin-bottom: 6px;
}
.voice-emotion-indicator.visible {
  opacity: 1;
  transform: translateY(0);
}
.emotion-emoji { font-size: 16px; }
.emotion-label { color: var(--text); font-weight: 500; }
.emotion-conf { color: var(--text-dim); font-size: 11px; }
.emotion-prov {
  color: var(--accent);
  font-size: 10px;
  padding: 1px 5px;
  background: rgba(8, 145, 178, 0.12);
  border-radius: 6px;
}
