:root {
  --primary: #123b63;
  --secondary: #0b87c9;
  --accent: #e9b949;
  --primary-deep: color-mix(in srgb, var(--primary) 82%, #000);
  --primary-soft: color-mix(in srgb, var(--primary) 10%, #fff);
  --secondary-soft: color-mix(in srgb, var(--secondary) 11%, #fff);
  --accent-soft: color-mix(in srgb, var(--accent) 20%, #fff);
  --surface: #ffffff;
  --canvas: #f4f7fa;
  --text: #17212b;
  --muted: #667484;
  --line: #dce4eb;
  --danger: #b42318;
  --success: #15803d;
  --shadow: 0 18px 50px rgba(25, 43, 61, 0.12);
  --radius-lg: 22px;
  --radius-md: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

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

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  color: #fff;
  background:
    radial-gradient(circle at 72% -80%, color-mix(in srgb, var(--secondary) 75%, transparent) 0 24%, transparent 52%),
    linear-gradient(115deg, var(--primary-deep), var(--primary));
  box-shadow: 0 8px 28px color-mix(in srgb, var(--primary) 24%, transparent);
  z-index: 10;
}

.brand, .topbar-actions, .color-control, .composer-bottom, .drawer-header, .drawer-actions {
  display: flex;
  align-items: center;
}

.brand { gap: 13px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--primary-deep);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: .04em;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 32%, transparent);
}

.eyebrow, .section-label {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.eyebrow { color: color-mix(in srgb, #fff 72%, var(--secondary)); }
.brand h1 { margin: 2px 0 0; font-size: 18px; line-height: 1.1; }
.topbar-actions { gap: 12px; }

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(255,255,255,.09);
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(12px);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); }
.connection-pill.offline .status-dot { background: #ff8a80; box-shadow: 0 0 0 4px rgba(255,138,128,.18); }

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 12px;
  background: rgba(255,255,255,.1);
  color: inherit;
  font-size: 22px;
  transition: transform .2s ease, background .2s ease;
}
.icon-button:hover { transform: translateY(-1px); background: rgba(255,255,255,.18); }

.sidebar {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 32px 24px 24px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.section-label { color: var(--secondary); }
.sidebar h2 { margin: 10px 0 12px; font-size: 22px; line-height: 1.22; color: var(--primary-deep); }
.sidebar-copy > p:last-child, .sidebar-footer p { color: var(--muted); font-size: 13px; line-height: 1.55; }
.quick-section { display: grid; gap: 9px; }
.quick-section .section-label { margin-bottom: 4px; }
.quick-prompt {
  padding: 12px 13px;
  border: 1px solid color-mix(in srgb, var(--secondary) 20%, var(--line));
  border-radius: 12px;
  background: var(--secondary-soft);
  color: var(--primary-deep);
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.quick-prompt:hover { transform: translateX(3px); border-color: var(--secondary); background: color-mix(in srgb, var(--secondary) 16%, #fff); }
.sidebar-footer { margin-top: auto; }
.secondary-button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--line));
  border-radius: 11px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-weight: 800;
}
.sidebar-footer .secondary-button { width: 100%; }

.chat-panel {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  background:
    linear-gradient(color-mix(in srgb, var(--primary) 2%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--primary) 2%, transparent) 1px, transparent 1px),
    var(--canvas);
  background-size: 30px 30px;
}
.messages {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 34px 34px 18px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.message { display: flex; gap: 12px; margin-bottom: 24px; animation: message-in .26s ease both; }
.user-message { justify-content: flex-end; }
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
}
.message-body { max-width: min(680px, 82%); }
.user-message .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.message-meta { margin: 0 4px 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.message-bubble {
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 6px var(--radius-md) var(--radius-md) var(--radius-md);
  background: var(--surface);
  line-height: 1.55;
  font-size: 14px;
  box-shadow: 0 7px 24px rgba(31, 50, 68, .06);
  white-space: pre-wrap;
}
.message-bubble p { margin: 0 0 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.user-message .message-bubble {
  border-color: transparent;
  border-radius: var(--radius-md) 6px var(--radius-md) var(--radius-md);
  background: linear-gradient(135deg, var(--secondary), color-mix(in srgb, var(--secondary) 78%, var(--primary)));
  color: #fff;
}
.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}
.source-chip {
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--primary-deep);
  font-size: 10px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.error-message .message-bubble { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: #fff4f2; color: var(--danger); }

.composer-wrap { padding: 12px 34px 20px; background: linear-gradient(transparent, var(--canvas) 20%); }
.composer { width: min(830px, 100%); margin: 0 auto; padding: 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 18px 50px color-mix(in srgb, var(--primary) 13%, transparent), 0 0 0 3px var(--accent-soft); }
.composer textarea { display: block; width: 100%; max-height: 160px; resize: none; border: 0; outline: 0; padding: 4px 6px 10px; background: transparent; color: var(--text); line-height: 1.5; }
.composer textarea::placeholder { color: #8794a2; }
.composer-bottom { justify-content: space-between; gap: 16px; }
.input-hint { padding-left: 6px; color: var(--muted); font-size: 10px; }
.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 76%, var(--secondary)));
  color: #fff;
  font-weight: 850;
  box-shadow: 0 7px 18px color-mix(in srgb, var(--primary) 25%, transparent);
}
.send-button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.send-button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.disclaimer { width: min(830px, 100%); margin: 8px auto 0; color: var(--muted); font-size: 10px; text-align: center; }

.typing-bubble { display: flex; gap: 5px; align-items: center; min-height: 48px; }
.typing-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--secondary); animation: typing 1.1s infinite ease-in-out; }
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(8, 20, 31, .36); backdrop-filter: blur(3px); }
.theme-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: min(420px, 100%);
  height: 100%;
  padding: 26px;
  background: var(--surface);
  box-shadow: -20px 0 60px rgba(8,20,31,.18);
  transform: translateX(102%);
  transition: transform .26s ease;
  overflow-y: auto;
}
.theme-drawer.open { transform: translateX(0); }
.drawer-header { justify-content: space-between; gap: 20px; }
.drawer-header h2 { margin: 5px 0 0; color: var(--primary-deep); }
.close-button { color: var(--primary); border-color: var(--line); background: var(--primary-soft); }
.drawer-intro { color: var(--muted); line-height: 1.55; font-size: 13px; }
.color-fields { display: grid; gap: 14px; margin: 24px 0; }
.color-field { display: grid; gap: 7px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--canvas); font-size: 13px; font-weight: 800; }
.color-field small { color: var(--muted); font-weight: 500; line-height: 1.4; }
.color-control { gap: 9px; }
.color-control input[type="color"] { width: 45px; height: 39px; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.color-control input[type="text"] { flex: 1; min-width: 0; height: 39px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--text); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.color-control input.invalid { border-color: var(--danger); box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 15%, transparent); }
.theme-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preview-swatch { display: grid; place-items: center; min-height: 64px; border-radius: 12px; color: #fff; font-size: 10px; font-weight: 850; }
.swatch-primary { background: var(--primary); }
.swatch-secondary { background: var(--secondary); }
.swatch-accent { background: var(--accent); color: var(--primary-deep); }
.drawer-actions { justify-content: flex-end; gap: 10px; margin-top: 24px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes message-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 820px) {
  body { overflow: auto; }
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 68px auto minmax(calc(100vh - 68px), auto); }
  .topbar { padding: 0 16px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand h1 { font-size: 16px; }
  .connection-pill { max-width: 130px; }
  #connectionText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar { grid-column: 1; grid-row: 2; display: block; padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .sidebar-copy, .sidebar-footer { display: none; }
  .quick-section { display: flex; overflow-x: auto; gap: 8px; scrollbar-width: none; }
  .quick-section .section-label { display: none; }
  .quick-prompt { flex: 0 0 auto; white-space: nowrap; }
  .chat-panel { grid-column: 1; grid-row: 3; min-height: calc(100vh - 129px); }
  .messages { padding: 24px 16px 12px; }
  .message-body { max-width: 88%; }
  .composer-wrap { padding: 10px 14px 16px; }
  .input-hint { display: none; }
  .composer-bottom { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
