:root {
  --bg-0: #06131b;
  --bg-1: #0c2431;
  --bg-2: #122f3f;
  --surface: rgba(9, 30, 40, 0.72);
  --surface-strong: rgba(7, 24, 33, 0.92);
  --line: rgba(138, 182, 196, 0.24);
  --text: #ecf4f6;
  --muted: #9ab5bf;
  --accent: #1fc9a9;
  --accent-2: #f9a03f;
  --danger: #ff6b6b;
  --ok: #19d39f;
  --busy: #ffd166;
  --radius: 18px;
  --shadow: 0 22px 58px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Noto Sans SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 14%, rgba(31, 201, 169, 0.22), transparent 45%),
    radial-gradient(circle at 86% 20%, rgba(249, 160, 63, 0.2), transparent 40%),
    linear-gradient(140deg, var(--bg-0), var(--bg-1) 52%, var(--bg-2));
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(8px);
  pointer-events: none;
  z-index: 0;
  animation: float 12s ease-in-out infinite;
}

.bg-shape-a {
  width: 360px;
  height: 360px;
  top: -90px;
  right: -70px;
  background: rgba(31, 201, 169, 0.18);
}

.bg-shape-b {
  width: 270px;
  height: 270px;
  bottom: 5%;
  left: -100px;
  background: rgba(249, 160, 63, 0.18);
  animation-delay: -4s;
}

.bg-shape-c {
  width: 220px;
  height: 220px;
  top: 48%;
  right: 28%;
  background: rgba(73, 153, 196, 0.18);
  animation-delay: -2s;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 26px auto;
  padding: 0 18px 22px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
}

.brand-tag {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 4px 0 0;
  font-family: "Space Grotesk", "Noto Sans SC", sans-serif;
  font-size: clamp(25px, 2.6vw, 34px);
  letter-spacing: 0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid transparent;
}

.status-pill.ok {
  color: #0d352b;
  background: rgba(25, 211, 159, 0.9);
}

.status-pill.busy {
  color: #4a3305;
  background: rgba(255, 209, 102, 0.9);
}

.status-pill.error {
  color: #430909;
  background: rgba(255, 107, 107, 0.92);
}

.layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 132px);
}

.settings-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.settings-panel h2 {
  margin: 6px 0 2px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #d7e7ec;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  font-size: 13px;
  color: var(--muted);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid rgba(158, 190, 201, 0.28);
  background: rgba(4, 19, 28, 0.72);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(31, 201, 169, 0.8);
  transform: translateY(-1px);
}

textarea {
  resize: vertical;
}

.inline-actions {
  display: flex;
  gap: 10px;
  margin: 2px 0 8px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-head {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.chat-head h2 {
  margin: 0;
  font-size: 19px;
}

#modelHint {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.mode-tabs {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  border: 1px solid rgba(143, 178, 188, 0.24);
  border-radius: 12px;
  background: rgba(3, 17, 24, 0.52);
}

.mode-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 9px;
  padding: 7px 12px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.mode-tab:hover {
  color: var(--text);
  background: rgba(81, 155, 186, 0.18);
}

.mode-tab.active {
  color: #05231f;
  background: rgba(31, 201, 169, 0.92);
  border-color: rgba(31, 201, 169, 0.72);
  font-weight: 700;
}

.mode-config.hidden {
  display: none;
}

.chat-timeline {
  flex: 1;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.welcome-card {
  border: 1px solid rgba(127, 172, 186, 0.24);
  border-radius: 16px;
  padding: 16px;
  background: rgba(7, 28, 36, 0.86);
}

.welcome-card h3 {
  margin: 0 0 8px;
  font-family: "Space Grotesk", "Noto Sans SC", sans-serif;
  font-size: 19px;
}

.welcome-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.message {
  max-width: min(86%, 900px);
  border-radius: 14px;
  padding: 10px 12px;
  border: 1px solid transparent;
  animation: rise 0.24s ease;
}

.message .meta {
  font-size: 12px;
  color: rgba(224, 239, 244, 0.7);
  margin-bottom: 7px;
}

.message .content {
  line-height: 1.64;
  word-break: break-word;
}

.message .content code {
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(1, 13, 19, 0.45);
  border: 1px solid rgba(143, 178, 188, 0.2);
}

.message .content strong {
  font-weight: 700;
}

.message .content .rich-link {
  color: #7ce9d2;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message .content .media-block {
  margin: 10px 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(141, 179, 191, 0.28);
  background: rgba(4, 20, 28, 0.78);
}

.message .content .media-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0;
}

.message .content .media-gallery .media-block {
  margin: 0;
}

.message .content .media-gallery .media-image img {
  max-height: 360px;
}

.message .content .media-block figcaption {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(2, 14, 21, 0.85);
}

.message .content .media-image img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.24);
}

.message .content .media-video video {
  display: block;
  width: 100%;
  max-height: 460px;
  background: #000;
}

.message .content .media-placeholder {
  padding: 12px;
  border-style: dashed;
}

.message .content .media-placeholder-title {
  font-size: 13px;
  font-weight: 700;
  color: #95ecdb;
}

.message .content .media-placeholder-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.message.user {
  margin-left: auto;
  background: linear-gradient(130deg, rgba(31, 201, 169, 0.28), rgba(68, 162, 203, 0.3));
  border-color: rgba(31, 201, 169, 0.5);
}

.message.assistant {
  background: rgba(7, 25, 35, 0.9);
  border-color: rgba(157, 185, 195, 0.26);
}

.message.assistant.pending {
  border-style: dashed;
  border-color: rgba(249, 160, 63, 0.72);
}

.composer {
  border-top: 1px solid var(--line);
  padding: 14px 16px 16px;
  background: linear-gradient(180deg, rgba(5, 22, 30, 0.6), rgba(5, 22, 30, 0.9));
}

#promptInput {
  width: 100%;
  min-height: 84px;
  max-height: 220px;
  resize: vertical;
}

.composer-actions {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

#tipText {
  font-size: 12px;
  color: var(--muted);
}

.composer-bottom {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.btn {
  border: 1px solid rgba(142, 178, 190, 0.26);
  background: rgba(7, 31, 42, 0.85);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 14px;
  cursor: pointer;
  transition: transform 0.18s ease, filter 0.18s ease, border-color 0.18s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.btn.primary {
  border-color: rgba(31, 201, 169, 0.68);
  background: linear-gradient(120deg, rgba(31, 201, 169, 0.36), rgba(73, 153, 196, 0.4));
}

.btn.ghost {
  background: rgba(2, 17, 24, 0.48);
}

.btn.danger {
  border-color: rgba(255, 107, 107, 0.6);
  background: rgba(110, 26, 26, 0.8);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  border-radius: 12px;
  padding: 10px 14px;
  background: rgba(4, 19, 28, 0.95);
  color: var(--text);
  border: 1px solid rgba(31, 201, 169, 0.32);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all 0.22s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: rgba(255, 107, 107, 0.64);
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: unset;
  }

  .settings-panel {
    max-height: 42vh;
  }
}

@media (max-width: 720px) {
  .app-shell {
    margin-top: 12px;
    padding: 0 10px 14px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .chat-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .mode-tabs {
    width: 100%;
    justify-content: space-between;
  }

  .message {
    max-width: 100%;
  }

  .message .content .media-gallery {
    grid-template-columns: 1fr;
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) translateX(0);
  }
  50% {
    transform: translateY(-14px) translateX(8px);
  }
}

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