@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400&display=swap');

:root {
  --bg: #f8fafc;
  --sidebar-bg: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  
  --bubble-user: linear-gradient(135deg, #0f766e 0%, #14b8a6 100%);
  --bubble-user-fg: #ffffff;
  --bubble-agent: #ffffff;
  --bubble-agent-border: #e2e8f0;
  
  --pill-bg: #ffffff;
  --pill-border: #cbd5e1;
  
  --accent: #0f766e;
  --accent-gradient: linear-gradient(135deg, #0f766e 0%, #14b8a6 100%);
  --accent-fg: #ffffff;
  
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.04), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.08), 0 10px 10px -5px rgba(15, 23, 42, 0.04);
  
  --error-bg: #fef2f2;
  --error-fg: #b91c1c;
  --error-border: #fca5a5;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 9999px;
}

/* Forced light theme -- intentionally does not follow system dark mode. */

* {
  box-sizing: border-box;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

html, body {
  height: 100%;
  margin: 0;
  background-color: var(--bg);
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#layout {
  display: flex;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ---------------- sidebar ---------------- */
.sidebar {
  width: 260px;
  flex: 0 0 auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px 16px;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
}
.sidebar.collapsed {
  width: 72px;
  padding: 24px 12px;
}
.sidebar.collapsed .sidebar-label {
  display: none;
}
.sidebar.collapsed .sidebar-top {
  justify-content: center;
}
.sidebar.collapsed .sidebar-logo {
  display: none;
}
.sidebar.collapsed .sidebar-item {
  justify-content: center;
  padding: 12px 10px;
}
.sidebar.collapsed .sidebar-icon {
  margin: 0;
  font-size: 1.1rem;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--fg);
}
.logo-mark {
  display: inline-flex;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}
.logo-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.icon-btn:hover {
  background: #f1f5f9;
  color: var(--fg);
  transform: scale(1.05);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-item:hover {
  background: #f1f5f9;
  transform: translateX(2px);
}

#new-session-btn {
  background: var(--accent-gradient);
  color: var(--accent-fg);
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.12);
  margin-bottom: 6px;
}
#new-session-btn:hover {
  background: var(--accent-gradient);
  color: var(--accent-fg);
  opacity: 0.95;
  transform: translateY(-1px) translateX(0);
  box-shadow: 0 6px 16px rgba(15, 118, 110, 0.2);
}
#new-session-btn .sidebar-icon {
  color: var(--accent-fg);
}

.sidebar-icon {
  width: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}
.sidebar-item:hover .sidebar-icon {
  color: var(--fg);
}
#new-session-btn:hover .sidebar-icon {
  color: var(--accent-fg);
}

/* ---------------- main column ---------------- */
#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: relative;
  /* Soft ambient background glow for premium UI feel */
  background-image: 
    radial-gradient(at 0% 0%, rgba(20, 184, 166, 0.03) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(59, 130, 246, 0.03) 0px, transparent 50%);
}

.chat-log {
  order: 1;
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 32px 24px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.hero-stage {
  order: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 24px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  transition: flex 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#main.chat-started .chat-log {
  flex: 1 1 auto;
}
#main.chat-started .hero-stage {
  flex: 0 0 auto;
  justify-content: flex-end;
  padding-bottom: 24px;
}
#main.chat-started .hero-title,
#main.chat-started .hero-hint {
  display: none;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: 800;
  margin: 0;
  text-align: center;
  letter-spacing: -0.03em;
  line-height: 1.15;
  background: linear-gradient(135deg, #0f172a 30%, #0d9488 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: floatUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes floatUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-hint {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  margin: 0;
  text-align: center;
  line-height: 1.5;
  max-width: 440px;
  animation: floatUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ---------------- composer pill ---------------- */
.composer {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 10px 12px;
  box-shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.08), var(--shadow);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12), 0 10px 30px -10px rgba(15, 23, 42, 0.12);
  background: #ffffff;
}
.composer.dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.2), var(--shadow);
  background: #f0fdfa;
}

.attach-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-pill);
  border: none;
  background: #f1f5f9;
  color: var(--fg);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.attach-btn:hover {
  background: var(--border);
  transform: rotate(90deg);
}

.composer input[type="text"] {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--fg);
  font-size: 0.98rem;
  padding: 8px 6px;
  outline: none;
  font-family: inherit;
}
.composer input[type="text"]::placeholder {
  color: #94a3b8;
}
.composer input[type="text"]:disabled {
  cursor: not-allowed;
}

.send-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--accent-gradient);
  color: var(--accent-fg);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(15, 118, 110, 0.15);
  transition: all 0.2s ease;
}
.send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.25);
}
.send-btn:active:not(:disabled) {
  transform: translateY(0);
}
.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---------------- chat bubbles ---------------- */
.bubble {
  max-width: 85%;
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-fg);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.1);
}
.bubble.agent {
  align-self: flex-start;
  background: var(--bubble-agent);
  color: var(--fg);
  border: 1px solid var(--bubble-agent-border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
.bubble.error {
  align-self: flex-start;
  background: var(--error-bg);
  color: var(--error-fg);
  border: 1px solid var(--error-border);
  border-bottom-left-radius: 4px;
}
/* Model-generated formatting inside assistant replies (see renderMarkdown in
   app.js) -- kept tight so lists/paragraphs read as a normal chat message
   rather than a raw HTML dump with default browser spacing. */
.bubble.agent p {
  margin: 0;
}
.bubble.agent p + p {
  margin-top: 10px;
}
.bubble.agent ol,
.bubble.agent ul {
  margin: 8px 0;
  padding-left: 22px;
}
.bubble.agent li {
  margin: 4px 0;
}
.bubble.agent li + li {
  margin-top: 4px;
}
.bubble.agent strong {
  font-weight: 700;
}

.bubble.thinking {
  align-self: flex-start;
  background: var(--bubble-agent);
  border: 1px solid var(--bubble-agent-border);
  color: var(--muted);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dots::after {
  content: "…";
  animation: dots 1.2s steps(4, end) infinite;
  display: inline-block;
  width: 12px;
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
  100% { content: ""; }
}

/* ---------------- inline result card ---------------- */
.result-card {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: messageIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.result-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.result-card-header {
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg);
}
.result-card-actions {
  display: flex;
  gap: 12px;
}

.export-btn {
  background: var(--accent-gradient);
  color: var(--accent-fg);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(15, 118, 110, 0.15);
  transition: all 0.2s ease;
}
.export-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.25);
  opacity: 0.95;
}
.export-btn:active {
  transform: translateY(0);
}

.view-btn {
  background: #f1f5f9;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.view-btn:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

/* ---------------- table (shared: modal) ---------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
  color: var(--fg);
}
th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  transition: background-color 0.15s ease;
}
th:nth-child(1), th:nth-child(2), th:nth-child(3), th:nth-child(4),
td:nth-child(1), td:nth-child(2), td:nth-child(3), td:nth-child(4) {
  text-align: left;
}
thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
  z-index: 10;
}
tbody tr:hover td {
  background-color: #f8fafc;
}
tbody tr:nth-child(even) {
  background-color: #fafbfc;
}
tfoot td {
  font-weight: 700;
  background: #f1f5f9;
  color: var(--fg);
  border-top: 2px solid #cbd5e1;
  border-bottom: none;
}

/* ---------------- modal ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal.hidden {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.25s ease-out forwards;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  position: relative;
  z-index: 1;
  width: min(95vw, 1400px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes slideUp {
  from {
    transform: translateY(24px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}
.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-close {
  background: #f1f5f9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  font-size: 1.2rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.modal-close:hover {
  background: var(--error-bg);
  color: var(--error-fg);
  transform: rotate(90deg);
}

.modal-table-wrap {
  overflow: auto;
  flex: 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 60;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(16px) scale(0.95);
}

.hidden {
  display: none;
}
