/* Alfred: Claude's layout in black and blue, with Gotham-style titles. */
:root {
  --bg: #07090d;
  --panel: #0d1117;
  --panel-raised: #131a24;
  --hover: #161e2a;
  --selected: #1b2433;
  --text: #e6edf7;
  --text-soft: #c4cdda;
  --muted: #8693a8;
  --border: #1d2633;
  --border-strong: #2a3546;
  --accent: #2b7bff;
  --accent-bright: #5c9dff;
  --accent-text: #ffffff;
  --accent-glow: rgb(43 123 255 / 0.35);
  --user-bubble: #11233f;
  --user-border: #1a3560;
  --warn: #2a2311;
  --danger: #ff6b6b;
  --display: "Bebas Neue", Impact, "Arial Narrow", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --column: 760px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 Inter, system-ui, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-bright); }

.icon { width: 18px; height: 18px; flex-shrink: 0; }
.chev { width: 14px; height: 14px; flex-shrink: 0; }
.meta { color: var(--muted); font-size: 13px; margin: 0; }
.grow { flex: 1; }

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

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 10px 10px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 12px; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 28px;
  letter-spacing: 0.1em;
  line-height: 1;
  text-transform: uppercase;
}
.brand-icon { width: 44px; height: 20px; color: var(--accent); filter: drop-shadow(0 0 8px var(--accent-glow)); }

.mode-switch {
  display: inline-flex;
  align-self: flex-start;
  gap: 2px;
  margin: 0 6px 10px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.mode-switch button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 30px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.active { background: var(--selected); border-color: var(--border-strong); color: var(--text); }

.side-nav { display: flex; flex-direction: column; gap: 1px; margin-bottom: 8px; }
.side-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--text-soft);
  text-align: left;
  cursor: pointer;
}
.side-row:hover { background: var(--hover); color: var(--text); }
.side-row .icon { color: var(--muted); }

.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 8px; }
.side-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.side-empty { margin: 2px 10px 6px; color: var(--muted); font-size: 13px; }

.room-head { display: flex; align-items: center; gap: 2px; border-radius: 8px; }
.room-head:hover { background: var(--hover); }
.room-head .icon-btn { opacity: 0; }
.room-head:hover .icon-btn, .room-head:focus-within .icon-btn { opacity: 1; }
.room-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 6px 4px 6px 8px;
  background: none;
  border: 0;
  color: var(--text-soft);
  text-align: left;
  cursor: pointer;
}
.room-toggle .chev { color: var(--muted); }
.room-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-chats { margin-left: 16px; padding-left: 4px; border-left: 1px solid var(--border); }

.chat-link {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-link:hover { background: var(--hover); color: var(--text); }
.chat-link.active { background: var(--selected); color: var(--text); }
.show-more {
  margin: 2px 0 0;
  padding: 6px 10px;
  background: none;
  border: 0;
  color: var(--accent-bright);
  font-size: 13px;
  cursor: pointer;
}

.side-bottom { padding-top: 8px; border-top: 1px solid var(--border); }
.warning { margin-bottom: 8px; padding: 10px; background: var(--warn); border-radius: 8px; font-size: 13px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn.small .icon { width: 16px; height: 16px; }
.icon-btn.copied, .code-copy.copied { color: var(--accent-bright); }
.mobile-only { display: none; }

/* ---------- Main column ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 8px 16px; }
.title-picker { min-width: 0; }
.title-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(60vw, 560px);
  padding: 6px 10px;
  background: none;
  border: 0;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
}
.title-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-btn:hover, .title-btn[aria-expanded="true"] { background: var(--hover); }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 24px 24px;
}
.messages > * { width: 100%; max-width: var(--column); margin-left: auto; margin-right: auto; }

.greeting { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 18vh; text-align: center; }
.greeting-icon { width: 84px; height: 84px; color: var(--accent); filter: drop-shadow(0 0 14px var(--accent-glow)); }
.greeting h1 {
  margin: 8px 0 0;
  font-family: var(--display);
  font-size: 46px;
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1;
}
.greeting .meta { font-size: 16px; }

.msg { margin-bottom: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble {
  max-width: 85%;
  padding: 10px 16px;
  background: var(--user-bubble);
  border: 1px solid var(--user-border);
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sender {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.1em;
  color: var(--accent-bright);
}
.sender .icon { width: 22px; height: 22px; }
.status { color: var(--muted); font-size: 14px; }
.msg.streaming .status::after { content: ""; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.msg.error .markdown { color: var(--danger); }
.msg-actions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg.streaming .msg-actions { display: none; }

.thinking { margin-bottom: 8px; color: var(--muted); font-size: 14px; }
.thinking summary { cursor: pointer; }
.thinking-body { margin-top: 6px; padding-left: 12px; border-left: 2px solid var(--accent); white-space: pre-wrap; }

.sources { margin-top: 6px; font-size: 13px; }
.sources summary { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.sources summary .icon { width: 15px; height: 15px; }
.sources ul { margin: 6px 0 0; padding-left: 18px; }

/* Formatted replies */
.markdown { overflow-wrap: anywhere; }
.markdown.plain { white-space: pre-wrap; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol, .markdown blockquote, .markdown table { margin: 0 0 14px; }
.markdown ul, .markdown ol { padding-left: 24px; }
.markdown li { margin: 4px 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 22px 0 10px; line-height: 1.3; font-weight: 600; }
.markdown h1 { font-size: 22px; }
.markdown h2 { font-size: 19px; }
.markdown h3 { font-size: 17px; }
.markdown blockquote { padding-left: 14px; border-left: 3px solid var(--border-strong); color: var(--text-soft); }
.markdown hr { margin: 20px 0; border: 0; border-top: 1px solid var(--border); }
.markdown :not(pre) > code {
  padding: 1px 6px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.88em;
}
.markdown table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 14px; }
.markdown th, .markdown td { padding: 6px 12px; border: 1px solid var(--border); text-align: left; }
.markdown th { background: var(--panel-raised); }

.code-block { margin: 0 0 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 4px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.code-copy:hover { background: var(--hover); color: var(--text); }
.code-copy .icon { width: 14px; height: 14px; }
.code-block pre { margin: 0; padding: 14px; overflow-x: auto; }
.code-block code { font-family: var(--mono); font-size: 13px; line-height: 1.55; background: none; }
.code-block code.hljs { padding: 0; background: none; }

/* ---------- Composer ---------- */
.composer { padding: 0 24px 20px; }
.composer-box {
  max-width: var(--column);
  margin: 0 auto;
  padding: 12px 12px 10px 16px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.35);
}
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea {
  display: block;
  width: 100%;
  max-height: 260px;
  padding: 2px 0 10px;
  background: none;
  border: 0;
  outline: none;
  resize: none;
  line-height: 1.5;
}
.composer textarea::placeholder { color: #6b778a; }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 5px 10px;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 13px;
  cursor: pointer;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .icon { width: 15px; height: 15px; color: var(--muted); }
.chip:hover, .chip[aria-expanded="true"] { border-color: var(--accent); color: var(--text); }
.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 0 14px var(--accent-glow);
}
.send-btn:hover { background: var(--accent-bright); }
.send-btn.stop { background: #3a4558; box-shadow: none; }

/* ---------- Attachments ---------- */
.attach-tray { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 10px; }
.attach-item {
  position: relative;
  width: 64px;
  height: 64px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
}
.attach-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-item.uploading img, .attach-item.uploading .attach-file { opacity: 0.45; }
.attach-item.error { border-color: var(--danger); }
.attach-file {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 100%;
  padding: 4px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}
.attach-file span { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.attach-error {
  position: absolute;
  inset: auto 0 0;
  padding: 1px 0;
  background: var(--danger);
  color: #ffffff;
  font-size: 10px;
  text-align: center;
}
.attach-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: rgb(0 0 0 / 0.7);
  border: 0;
  border-radius: 50%;
  color: #ffffff;
  cursor: pointer;
}
.attach-remove .icon { width: 12px; height: 12px; }

.user-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 85%; }
.user-stack .bubble { max-width: 100%; }
.attachments { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.thumb {
  display: block;
  width: 140px;
  height: 140px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 13px;
}
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { position: relative; }
.drop-hint {
  position: absolute;
  inset: 12px;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  background: rgb(7 9 13 / 0.85);
  color: var(--accent-bright);
  font-family: var(--display);
  font-size: 30px;
  letter-spacing: 0.06em;
  pointer-events: none;
}
.main.dragging .drop-hint { display: flex; }

/* ---------- Menus ---------- */
.picker { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: 300px;
  max-width: calc(100vw - 24px);
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 6px;
  background: var(--panel-raised);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.6);
}
.menu-up { top: auto; bottom: calc(100% + 8px); }
.menu-align-end { left: auto; right: 0; }
.side-bottom .menu { width: 100%; }
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 0;
  border-radius: 9px;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--selected); outline: none; }
.menu-item:disabled { cursor: not-allowed; }
.menu-item:disabled .menu-label { color: var(--muted); }
.menu-item.danger-text { color: var(--danger); }
.menu-text { display: flex; flex-direction: column; min-width: 0; }
.menu-label { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.menu-note { padding: 1px 8px; border: 1px solid var(--border-strong); border-radius: 999px; color: var(--muted); font-size: 11px; }
.menu-sub { margin-top: 2px; color: var(--muted); font-size: 12px; }
.menu-right { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; color: var(--muted); font-size: 13px; }
.menu-check { width: 18px; height: 18px; color: var(--accent-bright); }
.menu-divider { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-section { padding: 6px 12px 2px; color: var(--muted); font-size: 12px; }
.submenu .chev { transition: transform 0.15s; }
.submenu.open > .menu-item .chev { transform: rotate(90deg); }
.submenu-list { display: none; margin-left: 12px; padding-left: 4px; border-left: 1px solid var(--border); }
.submenu.open .submenu-list { display: block; }

.switch { position: relative; width: 34px; height: 20px; border-radius: 999px; background: #2a3342; transition: background 0.15s; }
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(14px); }
.menu-item:disabled .switch { opacity: 0.4; }

/* ---------- Buttons and dialogs ---------- */
button.primary, button.ghost, button.danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-text); border: 0; }
button.primary:hover { background: var(--accent-bright); }
button.ghost { background: transparent; border: 1px solid var(--border-strong); }
button.ghost:hover { border-color: var(--accent); }
button.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
button.small { padding: 4px 10px; font-size: 13px; }

dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 20px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.7); }
dialog h2 { margin: 0 0 14px; font-family: var(--display); font-size: 28px; font-weight: 400; letter-spacing: 0.06em; }
.stack label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.stack input:not([type="checkbox"]), .stack textarea, .stack select {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stack input:focus, .stack textarea:focus, .stack select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.stack input[type="checkbox"] { accent-color: var(--accent); }
.stack textarea { resize: vertical; }
.stack label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; }
.dialog-actions .right { display: flex; gap: 8px; margin-left: auto; }

.memory-list { max-height: 300px; margin: 0 0 12px; padding: 0; overflow-y: auto; list-style: none; }
.memory-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.memory-form { display: flex; gap: 8px; }
.memory-form input { flex: 1; min-width: 0; }

.search-dialog { width: min(620px, calc(100vw - 32px)); margin-top: 12vh; padding: 0; }
.search-box { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.search-box input { flex: 1; background: none; border: 0; outline: none; color: var(--text); font-size: 16px; }
.search-results { max-height: 55vh; overflow-y: auto; padding: 6px; }
.search-label { margin: 6px 10px; color: var(--muted); font-size: 12px; }
.search-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: 0;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}
.search-result:hover, .search-result:focus-visible { background: var(--selected); outline: none; }
.result-title { font-weight: 500; }
.result-meta { color: var(--muted); font-size: 12px; }
.result-snippet { color: var(--text-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scrim { display: none; }

/* ---------- Login page ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 14px;
  text-align: center;
}
.login-card label { text-align: left; }
.login-card button { width: 100%; }
.login-logo { width: 96px; height: 44px; color: var(--accent); filter: drop-shadow(0 0 12px var(--accent-glow)); }
.login-card h1 {
  margin: 6px 0 18px;
  font-family: var(--display);
  font-size: 44px;
  font-weight: 400;
  letter-spacing: 0.1em;
  line-height: 1;
}
.login-error { margin: -4px 0 12px; color: var(--danger); font-size: 14px; }

/* ---------- Phones and narrow windows ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgb(0 0 0 / 0.6); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgb(0 0 0 / 0.55); }
  .room-head .icon-btn { opacity: 1; }
  .msg-actions { opacity: 1; }
  .topbar { padding: 8px 10px; }
  .messages { padding: 8px 16px 16px; }
  .composer { padding: 0 12px 12px; }
  .bubble { max-width: 92%; }
  .greeting { margin-top: 10vh; }
  .greeting h1 { font-size: 38px; }
  .chip { max-width: 140px; }
  .row { grid-template-columns: 1fr; }
}

/* Notes on replies that didn't finish normally */
.reply-note { margin: 10px 0 0; color: var(--muted); font-size: 13px; font-style: italic; }
.reply-note.error-note { color: var(--danger); font-style: normal; }
