:root {
  color-scheme: light;
  --red: #d00018;
  --red-dark: #aa0014;
  --navy: #242424;
  --navy-soft: #3a3a3a;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e8e9eb;
  --surface: #ffffff;
  --canvas: #f4f4f3;
  --soft-red: #fff1f2;
  --shadow: 0 18px 55px rgba(20, 30, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 24px 18px 18px;
  color: #fff;
  background:
    radial-gradient(circle at 20% 0%, rgba(208, 0, 24, 0.16), transparent 31%),
    linear-gradient(165deg, #252525 0%, #111111 78%);
  border-right: 1px solid rgba(255,255,255,.06);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 3px 6px 24px; }
.brand img { width: 142px; padding: 7px 9px; background: #fff; border-radius: 9px; }
.brand span { padding-left: 10px; border-left: 1px solid rgba(255,255,255,.3); color: #b8c3c8; font-size: 12px; line-height: 1.2; }

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  padding: 12px 14px;
  color: #fff;
  background: var(--red);
  border: 0;
  border-radius: 10px;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(227,30,36,.22);
}
.new-chat:hover { background: var(--red-dark); }

.history-label { margin: 28px 8px 10px; color: #7f929b; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.history { display: grid; gap: 5px; overflow: auto; }
.history button {
  width: 100%;
  padding: 10px 12px;
  overflow: hidden;
  color: #c7d0d4;
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history button:hover, .history button.active { color: #fff; background: rgba(255,255,255,.08); }

.profile { display: flex; align-items: center; gap: 11px; margin-top: auto; padding: 16px 8px 4px; border-top: 1px solid rgba(255,255,255,.09); }
.profile .avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--red), #ff6064); font-size: 12px; font-weight: 800; }
.profile strong, .profile span { display: block; }
.profile strong { font-size: 13px; }
.profile span { margin-top: 2px; color: #8699a2; font-size: 11px; }

.workspace { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 13px 28px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.topbar strong, .topbar span { display: block; }
.topbar strong { font-size: 15px; }
.topbar span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.status { display: flex; align-items: center; gap: 7px; margin-left: auto; color: #48705b; font-size: 12px; font-weight: 650; }
.status i { width: 8px; height: 8px; background: #35ad67; border-radius: 50%; box-shadow: 0 0 0 4px #e8f6ed; }
.menu-button { display: none; background: transparent; border: 0; font-size: 22px; }

.conversation { width: min(900px, 100%); margin: 0 auto; padding: 38px 28px 180px; }
.welcome { display: grid; justify-items: center; margin-top: clamp(35px, 9vh, 100px); text-align: center; }
.spark { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 20px; color: #fff; background: var(--red); border-radius: 17px 17px 17px 5px; box-shadow: 0 16px 35px rgba(227,30,36,.25); font-size: 24px; font-weight: 900; }
.welcome h1 { margin: 0; font-size: clamp(27px, 4vw, 40px); letter-spacing: -.04em; }
.welcome p { max-width: 620px; margin: 13px 0 22px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.requirements { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.requirements span { padding: 7px 11px; color: #6b5556; background: var(--soft-red); border: 1px solid #f6d7da; border-radius: 999px; font-size: 12px; }

.message { display: flex; gap: 11px; margin: 20px 0; }
.user-message { justify-content: flex-end; }
.bubble { max-width: min(680px, 88%); padding: 14px 16px; border-radius: 16px; line-height: 1.55; box-shadow: 0 5px 18px rgba(30,40,50,.04); }
.user-message .bubble { color: #fff; background: var(--navy); border-bottom-right-radius: 4px; }
.assistant-message .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.assistant-avatar { flex: 0 0 auto; display: grid; place-items: center; width: 34px; height: 34px; color: #fff; background: var(--red); border-radius: 10px 10px 10px 3px; font-size: 13px; font-weight: 900; }
.message-image { display: block; width: min(420px, 100%); max-height: 240px; margin-bottom: 10px; object-fit: cover; object-position: top; border-radius: 10px; }
.summary { display: grid; gap: 12px; min-width: min(590px, 76vw); }
.summary h2 { margin: 0; font-size: 18px; }
.summary-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.summary-row small { display: block; margin-top: 3px; color: var(--muted); }
.totals { margin-top: 2px; padding: 12px 14px; background: var(--soft-red); border-radius: 10px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.download-button { width: 100%; padding: 12px 15px; color: #fff; background: var(--red); border: 0; border-radius: 9px; font-weight: 800; }
.download-button:hover { background: var(--red-dark); }
.warning { color: #8b5b0c; background: #fff8e7; border: 1px solid #f1dfad; }
.error { color: #8f2428; background: #fff0f1; border: 1px solid #f3c9cc; }

.loading-message .bubble span { display: inline-block; width: 6px; height: 6px; margin-right: 3px; background: #9ba3a8; border-radius: 50%; animation: blink 1.1s infinite ease-in-out; }
.loading-message .bubble span:nth-child(2) { animation-delay: .15s; }
.loading-message .bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 70%, 100% { opacity: .3; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.composer-wrap {
  position: fixed;
  z-index: 6;
  right: 0;
  bottom: 0;
  left: 286px;
  padding: 13px max(22px, calc((100vw - 286px - 900px) / 2));
  background: linear-gradient(to top, #f7f7f8 72%, rgba(247,247,248,0));
}
.composer { display: flex; align-items: flex-end; gap: 9px; padding: 9px; background: #fff; border: 1px solid #dfe1e4; border-radius: 15px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: #bfc4c9; box-shadow: 0 18px 55px rgba(20,30,40,.11); }
.composer textarea { flex: 1; max-height: 140px; padding: 10px 5px; resize: none; color: var(--ink); background: transparent; border: 0; outline: 0; line-height: 1.45; }
.composer textarea::placeholder { color: #9ba1a7; }
.attach-button, .send-button { flex: 0 0 auto; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; }
.attach-button { color: #526069; background: #f0f2f3; border: 0; font-size: 25px; transform: rotate(-45deg); }
.attach-button:hover { background: #e7e9eb; }
.send-button { color: #fff; background: var(--red); border: 0; font-size: 17px; }
.send-button:disabled { cursor: not-allowed; opacity: .45; }
.composer-note { margin: 8px 0 0; color: #8a9095; font-size: 11px; text-align: center; }

.attachment-preview { display: flex; align-items: center; gap: 11px; width: min(900px, 100%); margin: 0 auto 8px; padding: 9px 12px; background: #fff; border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 8px 30px rgba(30,40,50,.05); }
.attachment-preview img { width: 48px; height: 42px; object-fit: cover; object-position: top; border-radius: 6px; }
.attachment-preview strong, .attachment-preview span { display: block; }
.attachment-preview strong { max-width: 480px; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.attachment-preview span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.attachment-preview button { margin-left: auto; color: #7e858b; background: transparent; border: 0; font-size: 22px; }

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; width: 286px; transform: translateX(-101%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: block; }
  .composer-wrap { left: 0; padding-inline: 14px; }
  .conversation { padding-inline: 16px; }
  .status { display: none; }
  .topbar { padding-inline: 15px; }
  .summary { min-width: 0; }
}
body.auth-pending .app-shell {
  visibility: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 8%, #4a4a4a 0, #202020 45%, #0e0e0e 100%);
}

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

.login-card {
  width: min(100%, 390px);
  padding: 38px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.login-logo { display: block; width: 230px; max-width: 100%; margin-bottom: 24px; }

.login-card h1 {
  margin: 0;
  color: #1d1d1f;
}

.login-card > p:not(.login-kicker) {
  margin: 8px 0 26px;
  color: #667085;
}

.login-card label {
  display: block;
  margin: 14px 0 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.login-card input {
  box-sizing: border-box;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  font: inherit;
}

.login-card button {
  width: 100%;
  margin-top: 22px;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--red);
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.login-error {
  display: block;
  min-height: 20px;
  margin-top: 12px;
  color: #b42318;
  font-size: 13px;
}

.logout-button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.7;
}
