/* ===== CSS VARIABLES ===== */
:root {
  --accent: #AFB4C3;
}

/* ===== RESET & BASE STYLES ===== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, 'Helvetica Neue', Arial;
  background: #f5f7fb;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== LAYOUT CONTAINER ===== */
.wrap {
  max-width: 1200px;
  margin: 0 auto;
  background: #fff;
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

/* ===== HEADER ===== */
.head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #eef0f4;
  flex-shrink: 0;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
}

.title {
  font-weight: 600;
  color: #0e1628;
}

.powered {
  color: #7a8699;
  font-size: 12px;
}

/* ===== CHAT PANE ===== */
.pane {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  background: #fafbfe;
  min-height: 0;
}

/* ===== MESSAGES ===== */
.msg {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  word-wrap: break-word;
  position: relative;
}

.user {
  margin-left: auto;
  background: var(--accent);
  color: #000;
}

.bot {
  margin-right: auto;
  background: #f0f3f9;
  color: #101828;
}

/* ===== MESSAGE CHART BUTTON ===== */
.msg-chart-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 10px;
  color: #374151;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.msg-chart-btn:hover {
  opacity: 1;
  background: #fff;
}

.user .msg-chart-btn {
  display: none;
}

/* ===== MESSAGE CONTENT ===== */
.sql {
  background: #fff;
  border: 1px solid #e6e8ef;
  border-radius: 8px;
  padding: 8px;
  margin-top: 8px;
}

.msg ul {
  margin: 8px 0;
  padding-left: 20px;
}

.msg li {
  margin: 4px 0;
  line-height: 1.4;
}

.msg strong {
  font-weight: 600;
}

.msg em {
  font-style: italic;
}

/* ===== FOOTER & INPUT ===== */
.foot {
  border-top: 1px solid #eef0f4;
  padding: 16px 20px;
  background: #fff;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea {
  flex: 1;
  border: 1px solid #d9dce3;
  border-radius: 12px;
  padding: 10px 12px;
  resize: none;
  outline: none;
  font-size: 14px;
  height: 40px;
}

textarea::placeholder {
  font-size: 12px;
  color: #9ca3af;
}

.row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* ===== BUTTONS ===== */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  height: 40px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn img {
  display: block;
  filter: brightness(0) invert(1);
}

/* ===== UTILITY CLASSES ===== */
.muted {
  color: #7a8699;
  font-size: 12px;
}

details summary {
  cursor: pointer;
  color: #475467;
  font-size: 12px;
}

pre {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

/* ===== CHARTS ===== */
.chart-container {
  width: 100%;
  height: 400px;
  margin: 10px 0;
  overflow: hidden;
}

.chart-container > div {
  width: 100%;
  height: 100%;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
  body {
    background: #fff;
  }

  .wrap {
    height: 100vh;
    max-width: 100%;
  }

  .head {
    padding: 12px 16px;
  }

  .logo {
    width: 40px;
    height: 40px;
  }

  .title {
    font-size: 16px;
  }

  .powered {
    font-size: 11px;
  }

  .pane {
    padding: 16px 12px;
  }

  .msg {
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14px;
  }

  .foot {
    padding: 12px 16px;
  }

  .input-row {
    gap: 8px;
  }

  textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 10px;
    height: 44px; /* Better touch target */
  }

  .btn {
    padding: 10px 12px;
    min-width: 60px;
    height: 44px; /* Better touch target */
    font-size: 14px;
  }

  .btn img {
    width: 20px;
    height: 20px;
  }

  .chart-container {
    height: 300px;
    margin: 8px 0;
  }
}

@media (max-width: 480px) {
  .head {
    padding: 10px 12px;
  }

  .logo {
    width: 36px;
    height: 36px;
  }

  .title {
    font-size: 15px;
  }

  .pane {
    padding: 12px 10px;
  }

  .msg {
    max-width: 90%;
    padding: 10px 12px;
    font-size: 14px;
    margin-bottom: 10px;
  }

  .foot {
    padding: 10px 12px;
  }

  .input-row {
    gap: 6px;
  }

  textarea {
    padding: 8px 10px;
  }

  .btn {
    padding: 8px 10px;
    min-width: 50px;
  }

  .chart-container {
    height: 250px;
  }
}

/* ===== LOADING ANIMATION ===== */
.loader {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #cbd5e1;
  border-top-color: #E30E43;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
