/* ───── BASE ───── */
:root {
  color-scheme: dark;
  --bg: #070b14;
  --bg-soft: #0c1220;
  --panel: #111728;
  --panel-strong: #0d1322;
  --text: #f5f7ff;
  --muted: #98a4c3;
  --line: rgba(255,255,255,0.1);
  --line-strong: rgba(255,255,255,0.16);
  --pink: #ff4c76;
  --cyan: #37d4ff;
  --violet: #745cff;
  --red: #ff5d72;
  --green: #34d399;
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --max: 1200px;
  --font-ui: 'Manrope', system-ui, sans-serif;
  --font-display: 'Sora', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at 18% 18%, rgba(116,92,255,0.24), transparent 26%),
    radial-gradient(circle at 80% 14%, rgba(55,212,255,0.16), transparent 20%),
    radial-gradient(circle at 24% 78%, rgba(255,76,118,0.18), transparent 24%),
    linear-gradient(180deg, #1a1634 0%, #111728 45%, #2a1120 100%);
  background-attachment: fixed;
  color: var(--text);
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ───── TOPBAR ───── */
.topbar {
  position: sticky;
  top: 14px;
  z-index: 20;
  width: min(var(--max), calc(100% - 32px));
  margin: 18px auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  min-height: 68px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9,14,27,0.72);
  backdrop-filter: blur(16px);
  box-shadow: 0 12px 48px rgba(0,0,0,0.25);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  flex: 0 0 300px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.1rem;
  line-height: 1;
}

.brand img { width: 36px; height: 36px; }
.brand-name { display: inline-block; min-width: 152px; flex: 0 0 auto; }

.web-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.66rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(55,212,255,0.3);
  background: rgba(55,212,255,0.1);
  color: var(--cyan);
  letter-spacing: 0.06em;
  font-weight: 700;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-web-badge {
  height: 44px;
  min-height: 44px;
  padding-inline: 16px;
  background: rgba(55,212,255,0.06);
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.topbar-web-badge:hover,
.topbar-web-badge:focus-visible {
  background: rgba(55,212,255,0.12);
  border-color: rgba(55,212,255,0.42);
  transform: translateY(-1px);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  flex: 0 0 auto;
}

.icon-btn:hover { background: rgba(255,255,255,0.08); border-color: var(--line-strong); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  height: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.08);
  border-color: var(--line-strong);
}

.install-btn {
  height: 44px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  background: rgba(55,212,255,0.08);
  border-color: rgba(55,212,255,0.28);
}

.install-btn.is-installed {
  cursor: default;
  pointer-events: none;
  background: rgba(255,255,255,0.04);
  border-color: var(--line);
  color: var(--muted);
  box-shadow: none;
}

.install-btn.is-installed:hover,
.install-btn.is-installed:focus-visible {
  background: rgba(255,255,255,0.04);
  border-color: var(--line);
}

.runtime-banner {
  width: min(var(--max), calc(100% - 32px));
  margin: 10px auto 16px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.runtime-banner-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  font-size: 1rem;
}

.runtime-banner-copy {
  display: grid;
  gap: 4px;
}

.runtime-banner-head {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.runtime-banner-head strong {
  font-family: var(--font-display);
  font-size: 0.94rem;
}

.runtime-banner-copy p {
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.86rem;
}

.runtime-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(55,212,255,0.28);
  background: rgba(55,212,255,0.08);
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 700;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px rgba(255,93,114,0.5);
  transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 8px rgba(52,211,153,0.5);
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
}

.lang-select-label { color: var(--muted); font-size: 0.9rem; }

.lang-select {
  min-width: 168px;
  height: 36px;
  border: 0;
  outline: 0;
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
  color-scheme: dark;
}

.lang-select:focus-visible { box-shadow: 0 0 0 2px rgba(55,212,255,0.3); }
.lang-select option { background: #0f1526; color: var(--text); }

/* ───── SETTINGS PANEL ───── */
.settings-panel {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  overflow: hidden;
  max-height: min(620px, calc(100vh - 128px));
  transition: max-height 0.4s ease, opacity 0.3s ease;
  opacity: 1;
}

.settings-panel.hidden {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.settings-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  backdrop-filter: blur(10px);
  max-height: min(620px, calc(100vh - 128px));
  overflow-y: auto;
}

.settings-card h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.settings-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.settings-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.settings-row input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(7,11,20,0.8);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  outline: none;
  transition: border-color 0.2s;
}

.settings-row input:focus { border-color: var(--cyan); }
.settings-inline-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
}

.settings-inline-grid input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(7,11,20,0.8);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  outline: none;
}

.settings-note {
  color: var(--muted);
  font-size: 0.78rem;
}


.settings-card::-webkit-scrollbar { width: 10px; }
.settings-card::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 999px; }
.settings-card::-webkit-scrollbar-track { background: transparent; }

.settings-footer {
  position: sticky;
  bottom: 0;
  margin-top: 16px;
  padding-top: 14px;
  background: linear-gradient(180deg, rgba(13,19,34,0), rgba(13,19,34,0.92) 28%, rgba(13,19,34,0.98) 100%);
  backdrop-filter: blur(10px);
}

.settings-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.connection-result {
  margin-top: 10px;
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* ───── APP LAYOUT ───── */
 .app-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  width: min(var(--max), calc(100% - 32px));
  margin: 18px auto 24px;
  min-height: min(780px, calc(100vh - 180px));
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  overflow: hidden;
  background: rgba(7,11,20,0.5);
  box-shadow: 0 30px 120px rgba(0,0,0,0.45);
}

.panel {
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
  gap: 20px;
  min-height: 0;
}

.left-panel {
  border-right: 1px solid var(--line);
}

/* ───── INPUT GROUPS ───── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.url-row {
  display: flex;
  gap: 8px;
}

.url-row input {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(7,11,20,0.8);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.url-row input:focus { border-color: var(--cyan); }

.text-input {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(7,11,20,0.8);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.text-input:focus { border-color: var(--cyan); }

.model-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.select-styled {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(7,11,20,0.8);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.86rem;
  outline: none;
  cursor: pointer;
  color-scheme: dark;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2398a4c3'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.select-styled:focus { border-color: var(--cyan); }
.select-styled option { background: #0f1526; color: var(--text); }

.style-row {
  display: flex;
  gap: 6px;
}

.style-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.style-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); }

.style-btn.active {
  background: rgba(55,212,255,0.12);
  border-color: rgba(55,212,255,0.3);
  color: var(--cyan);
}

/* ───── BUTTONS ───── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--red), var(--pink) 48%, var(--violet));
  color: white;
  font: inherit;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 8px 24px rgba(255,76,118,0.25);
  white-space: nowrap;
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 32px rgba(255,76,118,0.35); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-analyze {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: white;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 8px 24px rgba(116,92,255,0.3);
}

.btn-analyze:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 32px rgba(116,92,255,0.4); }
.btn-analyze:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-sm {
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-sm:hover { background: rgba(255,255,255,0.08); }

.btn-cyan {
  border-color: rgba(55,212,255,0.3);
  color: var(--cyan);
  background: rgba(55,212,255,0.08);
}

.btn-cyan:hover { background: rgba(55,212,255,0.15); }

.btn-pink {
  border-color: rgba(255,76,118,0.3);
  color: var(--pink);
  background: rgba(255,76,118,0.08);
}

.btn-pink:hover { background: rgba(255,76,118,0.15); }

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
}

.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.04); }

/* ───── STATUS TEXT ───── */
.status-text {
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1.4em;
  line-height: 1.4;
}

.status-text.error { color: var(--red); }
.status-text.success { color: var(--green); }

/* ───── RESULT CARDS ───── */
.results { display: flex; flex-direction: column; gap: 14px; }
.results.hidden { display: none; }

.result-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  backdrop-filter: blur(8px);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.card-icon { font-size: 1.1rem; }
.card-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.86rem;
  letter-spacing: -0.02em;
  flex: 1;
}

.result-text {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

.result-list {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.7;
  list-style: none;
  padding: 0;
}

.result-list li { padding: 4px 0; }
.result-list li::before { content: "• "; color: var(--cyan); font-weight: 700; }

.collapsible { max-height: 0; overflow: hidden; transition: max-height 0.4s ease; margin: 0; }
.collapsible.open { max-height: 600px; }

.share-text { font-size: 0.85rem; }

.copy-feedback {
  font-size: 0.8rem;
  color: var(--cyan);
  min-height: 1em;
  margin-top: 6px;
}

/* ───── LOADING ───── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
}

.loading.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading p { color: var(--muted); font-size: 0.9rem; }

/* ───── RIGHT PANEL / CHAT ───── */
.right-panel {
  display: flex;
  flex-direction: column;
  padding: 0 0 28px;
  background: linear-gradient(180deg, rgba(255,255,255,0.01), rgba(255,255,255,0));
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
}

.chat-icon { font-size: 1.2rem; }

.chat-model-name {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(55,212,255,0.25);
  background: rgba(55,212,255,0.08);
  color: var(--cyan);
  font-family: var(--font-ui);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.chat-placeholder {
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
  padding: 60px 20px;
  line-height: 1.6;
  opacity: 0.7;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 90%;
}

.chat-msg.user { align-self: flex-end; }
.chat-msg.assistant { align-self: flex-start; }

.chat-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user .chat-bubble {
  background: linear-gradient(135deg, rgba(116,92,255,0.2), rgba(255,76,118,0.15));
  border: 1px solid rgba(116,92,255,0.2);
  color: var(--text);
}

.chat-msg.assistant .chat-bubble {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  color: var(--muted);
}

.chat-role {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chat-msg.user .chat-role { color: var(--pink); text-align: right; }
.chat-msg.assistant .chat-role { color: var(--cyan); }

.chat-composer {
  margin: 0 0 12px;
  padding: 18px 20px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 60px;
  max-height: 160px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(7,11,20,0.8);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
}

.chat-composer textarea:focus { border-color: var(--cyan); }

.composer-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.select-sm {
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line-strong);
  background: rgba(7,11,20,0.8);
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  outline: none;
  cursor: pointer;
  color-scheme: dark;
}

.select-sm option { background: #0f1526; color: var(--text); }

.btn-send {
  margin-left: auto;
  min-width: 90px;
}

#btn-chat-improve {
  min-width: 160px;
}

/* ───── TOAST ───── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  background: rgba(255,76,118,0.15);
  border: 1px solid rgba(255,76,118,0.3);
  color: var(--pink);
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.hidden { display: block; }

/* ───── SCROLLBAR ───── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ───── RESPONSIVE ───── */
@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
    margin: 12px;
    border-radius: var(--radius-lg);
  }
  .left-panel { border-right: none; border-bottom: 1px solid var(--line); }
  .topbar { width: min(var(--max), calc(100% - 24px)); margin: 12px auto 0; border-radius: 20px; }
  .settings-panel { width: min(var(--max), calc(100% - 24px)); margin: 0 auto; }
  .chat-messages { min-height: 300px; max-height: 50vh; }
}

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .topbar-right { width: 100%; justify-content: flex-end; }
  .panel { padding: 16px; }
  .url-row { flex-direction: column; }
  .style-row { flex-wrap: wrap; }
  .settings-inline-grid { grid-template-columns: 1fr; }
  .composer-row { align-items: stretch; }
  .btn-send, #btn-chat-improve, .select-sm { width: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 960px) {
  .topbar { align-items: flex-start; }
  .topbar-right { width: 100%; justify-content: flex-start; }
  .runtime-banner { grid-template-columns: 1fr; }
}
