/* Data Crawler Carl — Standalone full-screen styles */
/* Same .eda-* class names as the csv-explorer component, sized for normal browser context */

:root {
  --gold: #f1b300;
  --ink: #191919;
  --muted: #666;
  --bg: #fafafa;
  --card-bg: #fff;
  --border: rgba(25,25,25,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

/* ── App shell ── */
.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--ink);
  color: #fff;
}

.app-title-link {
  text-decoration: none;
  color: inherit;
}

.app-title-link:hover h1 {
  opacity: 0.8;
}

.app-header h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  transition: opacity 0.15s;
}

.app-header h1 span {
  color: var(--gold);
}

.app-header-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#load-sample {
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: 2px solid var(--gold);
  background: rgba(241,179,0,0.15);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

#load-sample:hover { background: rgba(241,179,0,0.3); }

.app-subtitle {
  font-size: 0.85rem;
  color: #999;
  font-weight: 400;
}

.app-body {
  height: calc(100vh - 52px);
  padding: 0;
}

/* ── Two-column layout ── */
.eda-layout {
  display: grid;
  grid-template-columns: 40% 6px 1fr;
  gap: 0;
  height: 100%;
  overflow: hidden;
}

/* ── Resizer handle ── */
.eda-resizer {
  background: var(--border);
  cursor: col-resize;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.eda-resizer:hover,
.eda-resizer:active {
  background: var(--gold);
}

/* ── Left pane (Data/SQL tabs) ── */
.eda-left-pane {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  overflow: hidden;
  min-height: 0;
}

/* ── Tab bar ── */
.eda-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: #f5f5f5;
}

.eda-tab {
  padding: 0.6rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.eda-tab.active {
  color: var(--ink);
  border-bottom-color: var(--gold);
}

.eda-tab:hover:not(.active) {
  color: var(--ink);
}

.eda-tabs .eda-meta {
  margin-left: auto;
  padding-right: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

/* ── Tab content panels ── */
.eda-tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  flex-direction: column;
}

.eda-tab-content.active {
  display: flex;
}

/* ── Upload zone ── */
.eda-upload-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px dashed rgba(25,25,25,0.15);
  background: rgba(241,179,0,0.04);
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s;
}

.eda-upload-zone.hover {
  background: rgba(241,179,0,0.15);
  border-color: var(--gold);
}

.eda-upload-zone .eda-upload-link {
  color: var(--gold);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.eda-upload-zone input[type="file"] { display: none; }

/* ── Data table ── */
.eda-table-scroll {
  flex: 1;
  overflow: auto;
  padding: 0;
  min-height: 0;
}

.eda-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.eda-table th {
  position: sticky;
  top: 0;
  background: #f8f8f8;
  padding: 0.45rem 0.6rem;
  text-align: left;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 2px solid var(--gold);
  white-space: nowrap;
  z-index: 1;
}

.eda-table td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid rgba(25,25,25,0.06);
  color: var(--ink);
  white-space: nowrap;
}

.eda-table tr:hover {
  background: rgba(241,179,0,0.06);
}

.eda-missing {
  color: #ef4444;
  font-style: italic;
  font-weight: 600;
}

/* ── SQL tab ── */
.eda-sql-query {
  border-bottom: 1px solid var(--border);
}

.eda-sql-display {
  margin: 0;
  padding: 0.8rem 1rem;
  background: #1e1e1e;
  color: #d4d4d4;
  font-size: 0.82rem;
  font-family: 'SF Mono', Consolas, 'Courier New', monospace;
  overflow-x: auto;
  max-height: 200px;
  white-space: pre-wrap;
  word-break: break-word;
}

.eda-sql-display code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

.eda-sql-results {
  flex: 1;
  overflow: auto;
  padding: 0;
  min-height: 0;
}

.eda-sql-label {
  display: block;
  padding: 3rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
}

.eda-sql-empty {
  display: block;
  padding: 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ── Chat pane (right) ── */
.eda-chat-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  min-height: 0;
  position: relative;
}

/* ── Preset buttons ── */
.eda-presets {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
  background: var(--card-bg);
}

.eda-preset {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 2px solid rgba(241,179,0,0.4);
  background: rgba(241,179,0,0.08);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.eda-preset:hover { background: rgba(241,179,0,0.2); border-color: var(--gold); }


/* ── Info button (in presets row) ── */
.eda-info-btn {
  margin-left: auto;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 2px solid rgba(25,25,25,0.15);
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.eda-info-btn:hover { border-color: var(--gold); color: var(--ink); }

/* ── Chat messages ── */
.eda-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 0;
}

.eda-msg {
  padding: 0.6rem 0.8rem;
  border-radius: 0.5rem;
  line-height: 1.55;
  max-width: 90%;
}

.eda-msg-user {
  align-self: flex-end;
  background: rgba(241,179,0,0.15);
  border: 1px solid rgba(241,179,0,0.3);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.9rem;
}

.eda-msg-model {
  align-self: flex-start;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 0.88rem;
}

/* ── Markdown inside model messages ── */
.eda-msg-model h1, .eda-msg-model h2, .eda-msg-model h3 {
  font-size: 1rem;
  margin: 0.5rem 0 0.25rem;
  color: var(--ink);
}
.eda-msg-model p { margin: 0.3rem 0; }
.eda-msg-model ul, .eda-msg-model ol {
  margin: 0.3rem 0;
  padding-left: 1.2rem;
  display: block;
}
.eda-msg-model li { margin: 0.15rem 0; font-size: 0.88rem; }
.eda-msg-model table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0;
  font-size: 0.82rem;
}
.eda-msg-model table th,
.eda-msg-model table td {
  padding: 0.3rem 0.5rem;
  border: 1px solid rgba(25,25,25,0.12);
  text-align: left;
}
.eda-msg-model table th {
  background: rgba(241,179,0,0.1);
  font-weight: 700;
}
.eda-msg-model strong { color: var(--ink); }
.eda-msg-model code {
  font-size: 0.82rem;
  background: rgba(25,25,25,0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}
.eda-msg-model pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 0.6rem 0.8rem;
  border-radius: 0.4rem;
  overflow-x: auto;
  font-size: 0.8rem;
  margin: 0.4rem 0;
}
.eda-msg-model pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* ── Inline SQL results in chat ── */
.eda-sql-result-inline {
  margin: 0.4rem 0;
  max-height: 250px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
}

.eda-sql-result-inline table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.8rem;
}

.eda-sql-result-inline th,
.eda-sql-result-inline td {
  padding: 0.25rem 0.5rem;
  border: 1px solid rgba(25,25,25,0.1);
  text-align: left;
  white-space: nowrap;
}

.eda-sql-result-inline th {
  background: rgba(241,179,0,0.1);
  font-weight: 700;
  position: sticky;
  top: 0;
}

.eda-sql-error {
  color: #ef4444;
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  background: rgba(239,68,68,0.08);
  border-radius: 0.3rem;
  margin: 0.3rem 0;
}

/* ── Chart containers in chat ── */
.eda-chart-container {
  margin: 0.5rem 0;
  border: 1px solid rgba(25,25,25,0.08);
  border-radius: 0.4rem;
  overflow: hidden;
  min-height: 300px;
}

.eda-chart-error {
  color: #ef4444;
  font-size: 0.85rem;
  padding: 0.6rem;
  text-align: center;
}

/* ── Error message ── */
.eda-msg-error {
  align-self: center;
  color: #ef4444;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  background: rgba(239,68,68,0.08);
  border-radius: 0.3rem;
}

/* ── Loading dots ── */
.eda-loading {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0;
}
.eda-loading span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gold);
  animation: eda-bounce 1.4s infinite ease-in-out both;
}
.eda-loading span:nth-child(1) { animation-delay: -0.32s; }
.eda-loading span:nth-child(2) { animation-delay: -0.16s; }
@keyframes eda-bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input row ── */
.eda-input-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  position: relative;
  z-index: 10;
}
.eda-input-row input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border: 2px solid rgba(25,25,25,0.12);
  border-radius: 0.4rem;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}
.eda-input-row input:focus { border-color: var(--gold); }

.eda-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.4rem;
  border: 2px solid var(--gold);
  background: rgba(241,179,0,0.12);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.eda-btn:hover { background: rgba(241,179,0,0.25); }
.eda-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.eda-btn-clear {
  border-color: rgba(25,25,25,0.15);
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.5rem 0.7rem;
}
.eda-btn-clear:hover { background: rgba(25,25,25,0.06); color: var(--ink); }

/* ── No-key state ── */
.eda-no-key {
  text-align: center;
  padding: 4rem 2rem;
}
.eda-no-key p { font-size: 1.1rem; color: var(--muted); line-height: 1.6; }
.eda-key-inline {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
  max-width: 24rem;
  margin-left: auto;
  margin-right: auto;
}
.eda-key-inline input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border: 2px solid rgba(25,25,25,0.15);
  border-radius: 0.4rem;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}
.eda-key-inline input:focus { border-color: var(--gold); }

/* ── Info modal ── */
.eda-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
}

.eda-modal-overlay.visible {
  display: grid;
  place-items: center;
}

.eda-modal {
  background: #fff;
  padding: 2rem 2.5rem;
  border-radius: 1rem;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
}

.eda-modal .eda-modal-close {
  display: inline-block;
  margin-top: 1.2rem;
  padding: 0.6rem 1.5rem;
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: rgba(241,179,0,0.1);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.eda-modal .eda-modal-close:hover {
  background: rgba(241,179,0,0.25);
}

/* ── About nav button ── */
.about-btn {
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.2);
  background: transparent;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.about-btn:hover {
  border-color: var(--gold);
  background: rgba(241,179,0,0.1);
}

/* ── API Key nav button ── */
.api-key-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.2);
  background: transparent;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.api-key-btn:hover {
  border-color: var(--gold);
  background: rgba(241,179,0,0.1);
}

.api-key-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  transition: background 0.2s;
}

.api-key-dot.connected {
  background: #22c55e;
}

/* ── Modal overlay (shared) ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
}

.modal-overlay.visible {
  display: grid;
  place-items: center;
}

.modal-dialog {
  background: #fff;
  padding: 2rem 2.5rem;
  border-radius: 1rem;
  max-width: 520px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  color: var(--ink);
}

.modal-dialog h2 {
  margin: 0 0 1rem;
  font-size: 1.3rem;
}

.modal-dialog h3 {
  margin: 1.2rem 0 0.5rem;
  font-size: 1rem;
  color: var(--ink);
}

.modal-dialog ol {
  padding-left: 1.3em;
  line-height: 1.8;
  color: #333;
  margin: 0 0 0.8rem;
}

.modal-dialog ol a {
  color: var(--gold);
  font-weight: 700;
}

.api-key-input-section {
  background: rgba(241,179,0,0.05);
  border: 2px solid rgba(241,179,0,0.2);
  border-radius: 0.5rem;
  padding: 0.8rem;
}

.api-key-row {
  display: flex;
  gap: 0.4rem;
}

.api-key-row input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border: 2px solid rgba(25,25,25,0.15);
  border-radius: 0.4rem;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.api-key-row input:focus {
  border-color: var(--gold);
}

.api-key-status {
  font-size: 0.82rem;
  margin-top: 0.4rem;
  color: var(--muted);
}

.api-key-status.ok {
  color: #22c55e;
  font-weight: 600;
}

.api-key-privacy {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
  margin: 0.5rem 0;
}

.api-key-facilitator {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 0.8rem;
}

.api-key-facilitator code {
  background: rgba(25,25,25,0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.8rem;
}

.modal-close-btn {
  display: inline-block;
  padding: 0.5rem 1.5rem;
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: rgba(241,179,0,0.1);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.modal-close-btn:hover {
  background: rgba(241,179,0,0.25);
}

/* ── Mongo no! easter egg ── */
.eda-btn-mongo {
  border-color: rgba(239,68,68,0.4);
  background: rgba(239,68,68,0.08);
  color: #ef4444;
  font-size: 0.82rem;
  padding: 0.5rem 0.7rem;
  white-space: nowrap;
}
.eda-btn-mongo:hover {
  background: rgba(239,68,68,0.18);
  border-color: #ef4444;
}

.mongo-run {
  position: absolute;
  bottom: -110px;
  left: calc(50% - 50px);
  height: 110px;
  z-index: 5;
  pointer-events: none;
  animation: mongo-zoom 5s ease-in-out forwards;
}

@keyframes mongo-zoom {
  0%   { bottom: -110px; left: calc(50% - 50px); transform: scaleX(1); }
  /* Rise up behind the input box */
  20%  { bottom: 35px;   left: calc(50% - 50px); transform: scaleX(1); }
  /* Looking right... */
  32%  { bottom: 35px;   left: calc(50% - 50px); transform: scaleX(1); }
  /* Flip to look left */
  36%  { bottom: 35px;   left: calc(50% - 50px); transform: scaleX(-1); }
  /* Looking left... */
  52%  { bottom: 35px;   left: calc(50% - 50px); transform: scaleX(-1); }
  /* Flip back to look right */
  56%  { bottom: 35px;   left: calc(50% - 50px); transform: scaleX(1); }
  /* Pause, then bolt! */
  65%  { bottom: 35px;   left: calc(50% - 50px); transform: scaleX(1); }
  100% { bottom: 20px;   left: calc(100% + 110px); transform: scaleX(1); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .eda-layout {
    grid-template-columns: 1fr !important;
    grid-template-rows: 40vh 1fr;
  }

  .eda-resizer { display: none; }

  .eda-left-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .app-header h1 { font-size: 1rem; }
  .app-subtitle { display: none; }
}
