:root {
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #f5f7fb;
  background: #0a0b0d;
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(circle at 20% -10%, rgba(63, 111, 255, .2), transparent 38%),
    radial-gradient(circle at 90% 15%, rgba(130, 75, 255, .16), transparent 34%),
    #0a0b0d;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

main { min-height: 100%; }

.login-card {
  width: min(92vw, 420px);
  margin: 0 auto;
  padding: max(14vh, 72px) 0 32px;
  text-align: center;
}

.logo {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0 auto 20px;
  border-radius: 20px;
  background: linear-gradient(140deg, #5a7cff, #8a5cff);
  box-shadow: 0 18px 50px rgba(85, 103, 255, .35);
  font-weight: 800;
  font-size: 28px;
}

h1 { margin: 0; font-size: 25px; }
.login-card p { color: #9ba2b0; margin: 10px 0 28px; }

#login-form { display: grid; gap: 12px; }
input, textarea {
  width: 100%;
  color: #f7f8fb;
  background: rgba(255,255,255,.075);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  outline: none;
}
input { padding: 16px; }
textarea { padding: 13px 15px; resize: none; max-height: 180px; }
input:focus, textarea:focus { border-color: #6e86ff; box-shadow: 0 0 0 3px rgba(79, 105, 255, .16); }

button {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  color: white;
  background: linear-gradient(135deg, #546fff, #7955ee);
  font-weight: 700;
}
button:disabled { opacity: .55; cursor: default; }
.error { min-height: 24px; margin-top: 14px; color: #ff8181; }

.app-shell {
  height: 100dvh;
  max-width: 1220px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  background: rgba(7, 8, 10, .6);
}

.chat-shell { height: 100dvh; min-width: 0; display: grid; grid-template-rows: auto 1fr auto; }

.history-panel {
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid rgba(255,255,255,.08);
  background: rgba(15,16,20,.9);
}
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(18px + env(safe-area-inset-top)) 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.history-head button { padding: 8px 11px; font-size: 13px; }
.conversation-list { height: calc(100dvh - 72px); overflow-y: auto; padding: 10px; }
.conversation-item {
  display: grid;
  width: 100%;
  gap: 5px;
  margin-bottom: 7px;
  padding: 11px 12px;
  text-align: left;
  color: #dfe3ea;
  background: transparent;
  border: 1px solid transparent;
}
.conversation-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item small { color: #7f8796; font-weight: 400; }
.conversation-item:hover { background: rgba(255,255,255,.055); }
.conversation-item.active { background: rgba(81,105,232,.18); border-color: rgba(104,126,255,.34); }
.history-backdrop, .mobile-only { display: none; }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(10,11,13,.78);
  backdrop-filter: blur(18px);
}
header h1 { font-size: 18px; }
#model-label { color: #8f98aa; font-size: 12px; }
.header-actions { display: flex; gap: 8px; }
.secondary { padding: 8px 11px; background: rgba(255,255,255,.08); color: #dce0e8; font-size: 13px; }

.messages { overflow-y: auto; padding: 22px 14px 30px; scroll-behavior: smooth; }
.welcome { color: #8e96a5; text-align: center; margin: 28vh 0 20px; }
.message { display: flex; margin: 12px 0; }
.message.user { justify-content: flex-end; }
.bubble {
  max-width: min(84%, 720px);
  padding: 12px 15px;
  border-radius: 18px;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(255,255,255,.075);
  border: 1px solid rgba(255,255,255,.07);
}
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 7px 0; padding-left: 22px; }
.bubble a { color: #9fb0ff; text-decoration: underline; }
.bubble code { padding: 2px 5px; border-radius: 5px; background: rgba(255,255,255,.1); font-family: Consolas, monospace; }
.code-block { margin: 10px 0; overflow: hidden; border: 1px solid rgba(255,255,255,.1); border-radius: 11px; background: #090a0c; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; color: #8f98aa; background: rgba(255,255,255,.055); font-size: 12px; }
.code-head button { padding: 4px 8px; color: #cfd5df; background: rgba(255,255,255,.08); font-size: 12px; }
.code-block pre { margin: 0; padding: 13px; overflow-x: auto; }
.code-block pre code { padding: 0; background: transparent; white-space: pre; }
.message-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.message-files span { padding: 5px 8px; border-radius: 8px; background: rgba(0,0,0,.16); font-size: 12px; }
.user .bubble { background: #5169e8; border-color: transparent; border-bottom-right-radius: 5px; }
.assistant .bubble { border-bottom-left-radius: 5px; }
.bubble.failed { color: #ff9d9d; }

.composer {
  display: block;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(10,11,13,.86);
  backdrop-filter: blur(18px);
}
.composer-row { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 9px; }
.composer-row > button { min-width: 72px; }
.composer-tools { display: flex; align-items: center; gap: 7px; min-height: 34px; margin-bottom: 8px; }
.tool-button, .attachment-chip {
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  color: #cdd3de;
  background: rgba(255,255,255,.06);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.tool-button.active { color: white; border-color: #7086ff; background: rgba(81,105,232,.28); }
.attachment-list { display: flex; gap: 6px; min-width: 0; overflow-x: auto; }
.attachment-chip { flex: 0 0 auto; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

[hidden] { display: none !important; }

@media (min-width: 700px) {
  .messages { padding-left: 32px; padding-right: 32px; }
  .composer { padding-left: 28px; padding-right: 28px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .history-panel {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(84vw, 330px);
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: 18px 0 48px rgba(0,0,0,.38);
  }
  .history-panel.open { transform: translateX(0); }
  .history-panel.open + .history-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    padding: 0;
    border-radius: 0;
    background: rgba(0,0,0,.5);
  }
  .mobile-only { display: inline-block; }
  header { padding-left: 12px; padding-right: 10px; }
  .header-actions { gap: 5px; }
  .secondary { padding: 8px 7px; font-size: 12px; }
}
