:root {
  --navy: #0b1220;
  --navy-2: #151c2b;
  --blue: #2157d8;
  --blue-deep: #1a46b8;
  --bg: #f3f0ea;
  --surface: #fffcf8;
  --surface-soft: #f7f4ee;
  --text: #17191f;
  --muted: #6a7080;
  --line: rgba(23, 25, 31, 0.09);
  --user: #171c27;
  --user-text: #f6f3ed;
  --assistant: transparent;
  --danger: #b3261e;
  --success: #0f766e;
  --shadow: 0 1px 0 rgba(23, 25, 31, 0.04), 0 18px 40px rgba(23, 25, 31, 0.06);
  --sidebar-top: #121826;
  --sidebar-bottom: #0b0f16;
  --sidebar-text: #f2eee6;
  --sidebar-muted: #9aa3b5;
  --control-bg: rgba(255, 252, 248, 0.8);
  --control-text: #3a4150;
  --chat-bg: transparent;
  --composer-bg: #fffcf8;
  --welcome-chip-bg: transparent;
  --welcome-chip-text: #3d4453;
  --attachment-bg: #f4f0e8;
  --font: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
}

body.dark {
  --bg: #0a0c10;
  --surface: #14181f;
  --surface-soft: #1b2029;
  --text: #ece8e1;
  --muted: #9aa1b0;
  --line: rgba(236, 232, 225, 0.1);
  --user: #ece8e1;
  --user-text: #14181f;
  --assistant: transparent;
  --danger: #ff8d84;
  --success: #4adeb3;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --sidebar-top: #10141c;
  --sidebar-bottom: #080a0e;
  --sidebar-text: #f4f0e8;
  --sidebar-muted: #8b93a4;
  --control-bg: #1a1f28;
  --control-text: #d9d3c8;
  --chat-bg: transparent;
  --composer-bg: #151920;
  --welcome-chip-bg: transparent;
  --welcome-chip-text: #c9c3b8;
  --attachment-bg: #1c222c;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 100% -10%, rgba(33, 87, 216, 0.07), transparent 50%),
    var(--bg);
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.25s ease, color 0.25s ease;
}

button,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

button:hover {
  transform: none;
  filter: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

:focus-visible {
  outline: 2px solid rgba(33, 87, 216, 0.45);
  outline-offset: 2px;
}

.app {
  display: flex;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: 268px;
  flex-shrink: 0;
  min-height: 100vh;
  padding: 22px 16px 18px;
  color: var(--sidebar-text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 28%),
    linear-gradient(180deg, var(--sidebar-top), var(--sidebar-bottom));
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  margin: 0 4px 28px;
}

.brand-logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  margin: 0;
  padding: 4px;
  background: #fff;
  border: 0;
  border-radius: 11px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  flex-shrink: 0;
}

.brand-logo {
  display: block;
  width: 30px;
  height: 30px;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
  border: 0;
  background: transparent;
}

.brand-logo-fallback {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  color: #0b1220;
  border: 0;
  border-radius: 11px;
  background: #f4efe6;
  box-shadow: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.brand-text strong {
  color: #f6f1e8;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-text span,
.brand p {
  margin: 0;
  color: var(--sidebar-muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

#new-chat {
  width: 100%;
  margin-bottom: 26px;
  padding: 10px 14px;
  color: #f6f1e8;
  background: transparent;
  border: 1px solid rgba(246, 241, 232, 0.14);
  box-shadow: none;
  font-weight: 500;
  font-size: 13px;
  text-align: left;
}

#new-chat:hover {
  background: rgba(246, 241, 232, 0.06);
  border-color: rgba(246, 241, 232, 0.22);
}

.sidebar-label {
  margin: 0 10px 10px;
  color: rgba(154, 163, 181, 0.8);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
}

#chat-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 2px;
}

#chat-list::-webkit-scrollbar,
#messages::-webkit-scrollbar {
  width: 8px;
}

#chat-list::-webkit-scrollbar-thumb,
#messages::-webkit-scrollbar-thumb {
  background: rgba(154, 163, 181, 0.28);
  border-radius: 99px;
}

.chat-row {
  display: flex;
  gap: 4px;
  align-items: center;
  margin: 1px 0;
  padding: 7px 8px 7px 12px;
  border: 0;
  border-radius: 10px;
}

.chat-row.active {
  background: rgba(246, 241, 232, 0.08);
}

.chat-row:hover {
  background: rgba(246, 241, 232, 0.06);
}

.chat-open {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: 2px 0;
  color: #d8deea;
  border-radius: 0;
  background: transparent;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 500;
}

.chat-remove {
  width: 22px;
  height: 22px;
  padding: 0;
  color: transparent;
  background: transparent;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
}

.chat-row:hover .chat-remove,
.chat-row.active .chat-remove {
  color: #9aa3b5;
  opacity: 1;
}

.chat-remove:hover {
  color: #fff;
  background: rgba(179, 38, 30, 0.72);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 10px 4px;
  color: var(--sidebar-muted);
  font-size: 11px;
  line-height: 1.5;
}

.signed-in {
  overflow: hidden;
  color: #d8deea;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sign-out {
  color: var(--sidebar-muted);
  text-decoration: none;
  font-weight: 500;
}

.sign-out:hover {
  color: #f6f1e8;
}

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 36px 28px 28px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-logo {
  margin: 0 auto 18px;
}

.login-card h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 400;
  letter-spacing: -0.03em;
}

.login-card > p {
  margin: 8px 0 22px;
  color: var(--muted);
  font-size: 14px;
}

.google-box {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.login-form {
  display: grid;
  gap: 8px;
  text-align: left;
}

.login-form[hidden] {
  display: none;
}

.login-form label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.login-form input {
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: var(--surface-soft);
  font: inherit;
}

.login-form button {
  margin-top: 10px;
  height: 42px;
  color: #f7f4ee;
  background: var(--navy);
  font-weight: 600;
}

.login-error {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.login-note {
  margin: 16px 0 0 !important;
  font-size: 12px !important;
}

.main {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: none;
  min-width: 0;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 14px 28px 8px;
}

.header-copy {
  flex: 0 1 240px;
  min-width: 148px;
  max-width: 38%;
  padding-top: 0;
}

.chat-title {
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.03em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 4px;
  justify-content: flex-end;
  align-items: center;
  flex: 1 1 auto;
}

#model {
  min-width: 124px;
  height: 34px;
  padding: 0 12px;
  color: var(--control-text);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
  background: var(--control-bg);
  font-weight: 500;
  font-size: 13px;
}

.button-secondary,
.button-danger {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
}

.button-secondary {
  color: var(--control-text);
  border: 0;
  background: transparent;
}

.button-secondary:hover {
  background: rgba(23, 25, 31, 0.05);
}

body.dark .button-secondary:hover {
  background: rgba(236, 232, 225, 0.06);
}

.button-danger {
  color: var(--danger);
  border: 0;
  background: transparent;
}

.button-danger:hover {
  background: rgba(179, 38, 30, 0.08);
}

.save-toggle {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  color: var(--control-text);
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.save-toggle:hover {
  background: rgba(23, 25, 31, 0.05);
}

.save-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--blue);
  cursor: pointer;
}

.workspace {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: 860px;
  min-height: 0;
  margin: 0 auto;
  padding: 0 28px 22px;
}

.saved-panel {
  margin-bottom: 12px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: none;
}

.saved-panel-header {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  align-items: center;
  margin-bottom: 11px;
}

.saved-panel-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.saved-panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.saved-panel-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.saved-selection-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  padding: 7px 2px;
  color: var(--muted);
  font-size: 12px;
}

.saved-selection-bar label {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.saved-selection-bar input,
.saved-check {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--blue);
  cursor: pointer;
}

#saved-list {
  display: grid;
  gap: 6px;
}

.saved-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 4px 10px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.saved-row:last-child {
  border-bottom: 0;
}

.saved-row-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.saved-row-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.saved-empty {
  padding: 12px 2px;
  color: var(--muted);
  font-size: 13px;
}

#messages {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 8px 4px 28px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.welcome {
  max-width: 520px;
  margin: 20px auto 0;
  padding: 8px 8px 0;
  text-align: center;
}

.welcome-symbol {
  display: grid;
  width: 28px;
  height: 28px;
  margin: 0 auto 14px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 50%;
  place-items: center;
  background: var(--surface);
  box-shadow: none;
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 400;
}

.welcome h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.welcome p {
  max-width: 420px;
  margin: 12px auto 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 28px;
}

.suggestion {
  padding: 9px 14px;
  color: var(--welcome-chip-text);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
}

.suggestion:hover {
  border-color: rgba(33, 87, 216, 0.28);
  background: var(--surface);
}

.message {
  max-width: 100%;
  margin: 22px 0;
  padding: 0;
  border-radius: 0;
  overflow-wrap: anywhere;
  line-height: 1.7;
  font-size: 15px;
}

.message.user {
  max-width: 78%;
  margin-left: auto;
  margin-right: 0;
  padding: 12px 16px;
  color: var(--user-text);
  border: 0;
  border-radius: 18px 18px 6px 18px;
  background: var(--user);
  white-space: pre-wrap;
}

.message.assistant {
  margin-right: auto;
  padding: 0 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  white-space: normal;
}

.message-body p {
  margin: 0 0 0.7em;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body .answer-heading {
  margin: 1.1em 0 0.35em;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.message-body .answer-heading:first-child {
  margin-top: 0;
}

.message-body ul,
.message-body ol {
  margin: 0.15em 0 0.85em;
  padding-left: 1.15em;
}

.message-body li {
  margin: 0.22em 0;
}

.message-body strong {
  font-weight: 600;
}

.message-body em {
  font-style: italic;
}

.message-body code {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
}

.message-role {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message.user .message-role {
  color: rgba(246, 243, 237, 0.55);
}

body.dark .message.user .message-role {
  color: rgba(20, 24, 31, 0.5);
}

.attachment-badge {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-top: 10px;
  padding: 5px 9px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 11px;
}

.composer {
  margin-top: 0;
  padding: 4px 8px 6px 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--composer-bg);
  box-shadow: var(--shadow);
}

#prompt {
  display: block;
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  padding: 8px 6px 2px;
  color: var(--text);
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  line-height: 1.55;
}

#prompt::placeholder {
  color: #9aa1ae;
}

.attachment-area {
  display: none;
  padding: 2px 4px 8px;
}

.attachment-area.visible {
  display: block;
}

#file-input {
  display: none;
}

.attachment-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.attach-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 6px 10px;
  color: var(--control-text);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.attach-help {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1100px) {
  .attach-help {
    display: none;
  }
}

#attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.attachment-chip {
  display: flex;
  gap: 7px;
  align-items: center;
  max-width: 300px;
  padding: 6px 8px 6px 10px;
  color: var(--control-text);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--attachment-bg);
  font-size: 12px;
}

.attachment-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.attachment-remove {
  padding: 0 3px;
  color: var(--danger);
  background: transparent;
  font-size: 16px;
  line-height: 1;
}

.composer-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 4px 2px 2px;
  border-top: 0;
}

.status {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: none;
}

#send {
  min-width: 0;
  height: 36px;
  padding: 0 16px;
  color: #f7f4ee;
  background: var(--navy);
  box-shadow: none;
  font-weight: 600;
  font-size: 13px;
}

#send:hover {
  background: #222837;
}

body.dark #send {
  color: #14181f;
  background: #ece8e1;
}

body.dark #send:hover {
  background: #fff;
}

.app-toast {
  position: fixed;
  top: auto;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  max-width: min(380px, calc(100vw - 32px));
  padding: 12px 16px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
}

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 16, 24, 0.46);
  backdrop-filter: blur(8px);
}

.app-modal-card {
  width: min(400px, 100%);
  padding: 22px 22px 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.app-modal-card p {
  margin: 0 0 16px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

#app-modal-input {
  display: block;
  width: 100%;
  height: 42px;
  margin: 0 0 16px;
  padding: 0 12px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: var(--surface-soft);
  font: inherit;
}

#app-modal-input:focus {
  border-color: rgba(33, 87, 216, 0.45);
}

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

.app-modal-actions .button-secondary,
.app-modal-actions .button-danger {
  min-width: 88px;
}

.app-modal-actions .button-secondary:not(.button-danger) {
  border: 1px solid var(--line);
}

.app-toast[hidden],
.app-modal[hidden],
#app-modal-input[hidden],
#app-modal-cancel[hidden] {
  display: none !important;
}

@media (max-width: 850px) {
  .sidebar {
    width: 220px;
  }

  .header,
  .workspace {
    padding-left: 18px;
    padding-right: 18px;
  }

  .controls {
    max-width: 100%;
  }

  .message.user {
    max-width: 88%;
  }
}

@media (max-width: 630px) {
  .brand-logo-wrap {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .app {
    display: block;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    width: 100%;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  }

  #chat-list {
    max-height: 132px;
  }

  .main {
    height: auto;
    overflow: visible;
  }

  .welcome {
    margin-top: 48px;
  }

  .welcome h3 {
    font-size: 28px;
  }

  #messages {
    min-height: 320px;
    max-height: none;
  }

  .controls {
    width: 100%;
    max-width: 100%;
    justify-content: flex-start;
  }

  .header {
    flex-direction: column;
  }

  #model {
    flex: 1;
    min-width: 120px;
  }

  .composer-footer {
    align-items: center;
    flex-direction: row;
  }
}
