:root {
  --bg-dark: #0b0f19;
  --bg-card: rgba(21, 30, 47, 0.75);
  --bg-card-hover: rgba(30, 42, 66, 0.85);
  --border-color: rgba(255, 255, 255, 0.12);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --primary-glow: rgba(56, 189, 248, 0.25);
  --accent-gold: #fbbf24;
  --success: #10b981;
  --danger: #f87171;
  --warning: #fb923c;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow: 0 12px 36px -10px rgba(0, 0, 0, 0.6);
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Consolas', 'Fira Code', 'Courier New', monospace;
}

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

html, body {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(56, 189, 248, 0.14) 0px, transparent 55%),
    radial-gradient(at 100% 100%, rgba(251, 191, 36, 0.09) 0px, transparent 55%);
  color: var(--text-main);
  font-family: var(--font-family);
}

.app-viewport {
  display: flex;
  height: 100vh;
  max-height: 100vh;
  padding: 1rem;
}

.grid-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 1.25rem;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
}

.brand-sidebar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.85rem;
}
.brand-icon-sm {
  font-size: 1.6rem;
  background: rgba(15, 23, 42, 0.8);
  padding: 0.4rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}
.brand-sidebar h2 { font-size: 1.1rem; font-weight: 700; color: var(--text-main); }
.brand-sidebar p { font-size: 0.78rem; color: var(--text-muted); }

.btn-new-chat {
  width: 100%;
  background: linear-gradient(135deg, var(--primary), #0284c7);
  color: #000;
  font-weight: 700;
  border: none;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  transition: all 0.2s;
  margin-bottom: 0.85rem;
}
.btn-new-chat:hover { opacity: 0.9; transform: translateY(-1px); }

.chat-session-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 280px;
  overflow-y: auto;
}
.chat-session-list::-webkit-scrollbar { width: 4px; }
.chat-session-list::-webkit-scrollbar-thumb { background: var(--border-color); }

.chat-session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.chat-session-item:hover {
  background: rgba(30, 42, 66, 0.8);
  border-color: rgba(56, 189, 248, 0.3);
}
.chat-session-item.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: var(--primary);
}

.session-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow: hidden;
}
.session-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-date { font-size: 0.72rem; color: var(--text-muted); }

.btn-del-session {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  font-size: 0.85rem;
  border-radius: 4px;
  transition: color 0.2s;
}
.btn-del-session:hover { color: var(--danger); background: rgba(248, 113, 113, 0.15); }

/* CHAT BOX & HEADER BAR */
.chat-box {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 1rem;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.select-icon {
  position: absolute;
  right: 0.75rem;
  font-size: 0.95rem;
  pointer-events: none;
  z-index: 2;
}

.select-control-custom {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: rgba(15, 23, 42, 0.9);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%3c38bdf8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  background-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 2.2rem 0.5rem 2.2rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: all 0.2s;
  direction: ltr;
  text-align: left;
}

.select-control-custom:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.select-control-custom option {
  background-color: #0f172a;
  color: #f8fafc;
  padding: 0.5rem;
}

.role-select-width { width: 190px; }
.model-select-width { width: 220px; }

.chat-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

.chat-history::-webkit-scrollbar { width: 6px; }
.chat-history::-webkit-scrollbar-track { background: rgba(15, 23, 42, 0.5); }
.chat-history::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
.chat-history::-webkit-scrollbar-thumb:hover { background: var(--primary); }

.msg {
  max-width: 85%;
  padding: 0.95rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.6;
  animation: fadeIn 0.25s ease-in-out;
  word-break: break-word;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-start;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--text-main);
  white-space: pre-wrap;
  direction: auto;
}

.msg.assistant {
  align-self: flex-end;
  background: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  direction: auto;
}

.msg.assistant.dir-ltr {
  direction: ltr !important;
  text-align: left !important;
}

/* 🎯 STRICT SCOPED ASSISTANT AI RESPONSE HTML SELECTORS */
.ai-response-content.dir-ltr th,
.ai-response-content.dir-ltr td {
  text-align: left !important;
}

.ai-response-content.dir-ltr ul,
.ai-response-content.dir-ltr ol {
  margin-left: 1.25rem !important;
  margin-right: 0 !important;
}

.ai-response-content h1,
.ai-response-content h2,
.ai-response-content h3,
.ai-response-content h4 {
  color: var(--primary);
  font-weight: 700;
  margin-top: 0.6rem;
  margin-bottom: 0.4rem;
  font-size: 1.05rem;
  line-height: 1.3;
  border-bottom: 1px solid rgba(56, 189, 248, 0.2);
  padding-bottom: 0.25rem;
}
.ai-response-content h1:first-child,
.ai-response-content h2:first-child,
.ai-response-content h3:first-child { margin-top: 0; }

.ai-response-content p { margin-bottom: 0.5rem; color: #e2e8f0; }
.ai-response-content strong, .ai-response-content b { color: var(--accent-gold); font-weight: 600; }
.ai-response-content ul, .ai-response-content ol { margin-right: 1.25rem; margin-bottom: 0.6rem; }
.ai-response-content li { margin-bottom: 0.3rem; color: #cbd5e1; }

.ai-response-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.85rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.ai-response-content th {
  background: rgba(56, 189, 248, 0.2);
  color: var(--primary);
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.ai-response-content td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}
.ai-response-content tr:last-child td { border-bottom: none; }

/* 🛠️ TOOL CARD COMPONENT — DATA-OPEN ATTRIBUTE DRIVEN */
.tool-card {
  width: 95%;
  margin: 0.6rem auto;
  background: rgba(13, 20, 38, 0.98);
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: var(--radius-md);
  /* NO overflow:hidden — that was clipping the body */
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  animation: fadeIn 0.25s ease-in-out;
  direction: ltr;
  text-align: left;
}

/* Body hidden by default via data-open=false */
.tool-card[data-open="false"] .tool-card-body {
  display: none;
}

/* Body shown when data-open=true */
.tool-card[data-open="true"] .tool-card-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Chevron points down when open, right when closed */
.tool-card[data-open="true"] .toggle-icon {
  transform: rotate(180deg);
}
.tool-card[data-open="false"] .toggle-icon {
  transform: rotate(0deg);
}

.tool-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(13, 20, 38, 0.95));
  border-bottom: 1px solid rgba(251, 191, 36, 0.25);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease-in-out;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tool-card[data-open="false"] .tool-card-header {
  border-bottom: none;
  border-radius: var(--radius-md);
}

.tool-card-header:hover {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.28), rgba(30, 42, 66, 0.98));
}

.tool-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-gold);
  overflow: hidden;
  min-width: 0;
}

.tool-emoji { flex-shrink: 0; }

.tool-name-title {
  color: #f8fafc;
  font-weight: 700;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.tool-args-preview {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.tool-badge {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.5);
  padding: 0.15rem 0.55rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.tool-badge.elicitation {
  background: rgba(248, 113, 113, 0.2);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.5);
}

.toggle-icon {
  font-size: 0.82rem;
  color: var(--accent-gold);
  transition: transform 0.25s ease-in-out;
  flex-shrink: 0;
}

.tool-card-body {
  padding: 1rem 1rem;
  background: rgba(8, 12, 24, 0.98);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  border-top: 1px solid rgba(251, 191, 36, 0.2);
  width: 100%;
}

.tool-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
}

.tool-section-title {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

pre.json-block {
  background: #020408;
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  color: #e2f0ff;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 48px;
  max-height: 300px;
  overflow-x: auto;
  overflow-y: auto;
  line-height: 1.5;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.7);
  margin: 0;
  display: block;
  width: 100%;
}

pre.json-block::-webkit-scrollbar { width: 6px; height: 6px; }
pre.json-block::-webkit-scrollbar-track { background: rgba(15, 23, 42, 0.6); }
pre.json-block::-webkit-scrollbar-thumb { background: rgba(56, 189, 248, 0.5); border-radius: 3px; }
pre.json-block::-webkit-scrollbar-thumb:hover { background: var(--primary); }



/* ELICITATION CARD */
.elicitation-card {
  width: 90%;
  align-self: center;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin: 0.5rem 0;
}
.elicitation-title { color: var(--danger); font-weight: 700; margin-bottom: 0.4rem; font-size: 0.9rem; }
.elicitation-btns { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.btn-approve { background: var(--success); color: #000; width: 50%; padding: 0.55rem; border-radius: var(--radius-md); border: none; font-weight: 700; cursor: pointer; }
.btn-deny { background: var(--danger); color: #fff; width: 50%; padding: 0.55rem; border-radius: var(--radius-md); border: none; font-weight: 700; cursor: pointer; }

.chat-input-area {
  display: flex;
  gap: 0.75rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  align-items: flex-end;
}

textarea.chat-input {
  flex: 1;
  resize: none;
  min-height: 48px;
  max-height: 140px;
  line-height: 1.5;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.85) !important;
  border: 1px solid rgba(56, 189, 248, 0.3) !important;
  border-radius: var(--radius-md) !important;
  padding: 0.75rem 1rem !important;
  color: var(--text-main) !important;
  font-family: inherit !important;
  font-size: 0.92rem !important;
  outline: none !important;
  transition: all 0.2s ease-in-out !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  direction: auto;
}

textarea.chat-input::placeholder {
  color: rgba(148, 163, 184, 0.55) !important;
}

textarea.chat-input:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 16px var(--primary-glow), inset 0 0 6px rgba(56, 189, 248, 0.1) !important;
  background: rgba(21, 30, 47, 0.95) !important;
}

.btn {
  background: linear-gradient(135deg, var(--primary), #0284c7);
  color: #000;
  font-weight: 700;
  border: none;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { opacity: 0.95; transform: translateY(-1px); box-shadow: 0 4px 12px var(--primary-glow); }

.caps-list { list-style: none; }

.caps-list li {
  padding: 0.45rem 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.caps-list li .concern-name {
  text-align: right;
  flex: 1;
  color: var(--text-muted);
}

.caps-list li span.val {
  color: var(--success);
  font-weight: 600;
  font-size: 0.75rem;
  text-align: left;
  direction: ltr;
  max-width: 175px;
  word-break: break-word;
  white-space: normal;
}

.pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}
