:root {
  --bg: #f7f3ec;
  --bg-elevated: #ffffff;
  --sidebar-bg: #f5edff;
  --sidebar-border: #e0d2ff;
  --accent: #f4a425;
  --accent-soft: #ffe6ba;
  --purple: #5a35b1;
  --purple-soft: #e4daff;
  --text: #22172f;
  --text-soft: #6a5c7a;
  --danger: #e0564a;
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-soft: 0 22px 45px rgba(0, 0, 0, 0.08);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at top left, #fdf7ef 0, #f4f0ff 40%, #f7f3ec 100%);
  color: var(--text);
}

/* ========== LAYOUT SHELL ========== */

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

/* ========== SIDEBAR ========== */

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
  background: linear-gradient(180deg, var(--sidebar-bg), #faf3ff);
  border-right: 1px solid var(--sidebar-border);
}

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

.logo {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--accent-soft);
  object-fit: contain;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-soft);
}

.sidebar-section {
  margin-top: 18px;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.model-list,
.chat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 30vh;
  overflow-y: auto;
}

.model-item,
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-soft);
  cursor: pointer;
}

.model-item:hover,
.chat-item:hover {
  background: var(--purple-soft);
  color: var(--purple);
}

.model-item.active,
.chat-item.active {
  background: var(--purple);
  color: #fff;
}

.model-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-soft);
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--danger);
}

/* ========== MAIN AREA ========== */

.main {
  position: relative;
  padding: 20px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(
    180deg,
    #f5efff 0,
    #f5efff 80px,
    transparent 160px
  );
}

/* HEADER */

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  width: 100%;
  max-width: 1120px;
}

.main-header h1 {
  margin: 0;
  font-size: 22px;
}

.header-subtitle {
  display: inline-block;
  font-size: 13px;
  color: var(--text-soft);
  margin-top: 2px;
}

/* WATERMARK */

.watermark {
  position: absolute;
  top: 90px;
  bottom: 40px;
  left: 50%;
  width: 1120px;
  max-width: calc(100% - 64px);
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0.26;
  background-image: url("img/logo.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 58%;
  filter: saturate(1.1);
}

/* CHAT PANEL */

.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 14px 14px 10px;
  height: calc(100vh - 110px);
  width: 100%;
  max-width: 1120px;
  z-index: 1;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

.message {
  max-width: 75%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.message.system {
  border-left: 3px solid var(--purple);
}

.message.user {
  margin-left: auto;
  background: var(--accent-soft);
  border-color: rgba(0, 0, 0, 0.03);
}

.message.assistant {
  background: #f4f0ff;
}

.message-meta {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  margin-bottom: 2px;
}

.message-body {
  font-size: 14px;
  line-height: 1.5;
}

/* INPUT ROW */

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

#chat-input {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  background: #faf7ff;
}

#chat-input:focus {
  outline: 2px solid var(--purple-soft);
  border-color: var(--purple);
}

/* BUTTONS */

.btn {
  border-radius: 999px;
  border: none;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn.primary {
  background: var(--purple);
  color: white;
}

.btn.accent {
  background: var(--accent);
  color: #402200;
}

.btn.ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid rgba(0, 0, 0, 0.09);
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn.accent:hover {
  filter: brightness(1.04);
}

.btn.ghost:hover {
  background: rgba(0, 0, 0, 0.03);
}

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

.w-full {
  width: 100%;
}

/* MODAL */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 7, 15, 0.36);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: 360px;
  max-width: 90vw;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-soft);
}

.modal h2 {
  margin: 0 0 4px;
}

.modal-subtitle {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-soft);
}

.modal label {
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}

.modal input {
  width: 100%;
  margin-top: 2px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.12);
  font-family: inherit;
}

.modal-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* RESPONSIVE */

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 12px;
    background: #f7f3ec;
  }

  .main-header,
  .chat-panel {
    max-width: 100%;
  }

  .chat-panel {
    height: calc(100vh - 70px);
  }

  .watermark {
    display: none;
  }
}
