/* BTG Chat — styled after btg.berlin (Abril Fatface headings, Verdana text, orange-red accent),
   laid out like claude.ai (sidebar + centred chat column). */

:root {
  --accent: #d4471d;
  --accent-hover: #b83c17;
  --accent-soft: #fbece6;
  --accent-text: #ffffff;
  --teal: #99c1c1;
  --bg: #ffffff;
  --sidebar: #f3f3f6;
  --surface: #f9f9fb;
  --hover: #e7e8ee;
  --border: #e1e1e6;
  --text: #333333;
  --muted: #6b6b6b;
  --user-bubble: #e7e8ee;
  --notice-bg: #fff4e5;
  --notice-text: #8a4b00;
  --error: #b42318;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .06);
  --heading: "Abril Fatface", Georgia, serif;
  --font: Verdana, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #e8643c;
    --accent-hover: #f07a55;
    --accent-soft: #3a2219;
    --accent-text: #ffffff;
    --bg: #1c1c1e;
    --sidebar: #161618;
    --surface: #242427;
    --hover: #2e2e32;
    --border: #36363b;
    --text: #e8e8ea;
    --muted: #a0a0a6;
    --user-bubble: #2e2e32;
    --notice-bg: #3a2c17;
    --notice-text: #f2c66d;
    --error: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font: 14px/1.6 var(--font);
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { font-family: var(--heading); font-weight: 400; color: var(--text); line-height: 1.2; }
h1 { font-size: 2rem; margin: 0 0 8px; }
h2 { font-size: 1.35rem; margin: 32px 0 8px; }
h3 { font-size: 1.1rem; margin: 0 0 6px; }

a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.lead { color: var(--muted); max-width: 640px; margin: 0 0 20px; }

.icon { width: 18px; height: 18px; flex: none; }

button, .button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 600 13px/1 var(--font);
  letter-spacing: .5px;
  border: 0;
  border-radius: 4px;
  padding: 11px 18px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button:hover { background: var(--accent-hover); }
button:disabled { opacity: .55; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0;
  padding: 6px 10px;
}
button.ghost:hover { background: var(--hover); color: var(--text); }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.danger { color: var(--error) !important; }

/* ---------- App shell: sidebar + main ---------- */

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

.sidebar {
  width: 272px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo img { width: 32px; height: auto; }
.logo span { font-family: var(--heading); font-size: 1.35rem; white-space: nowrap; }
.close-sidebar { display: none; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  margin-bottom: 6px;
  border-radius: 8px;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}
.new-chat .icon {
  width: 24px;
  height: 24px;
  padding: 3px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
}
.new-chat:hover { background: var(--hover); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  font: 400 14px/1.3 var(--font);
  letter-spacing: 0;
  text-decoration: none;
  text-align: left;
}
.nav-item .icon { color: var(--muted); }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--hover); font-weight: 700; }

.recents { flex: 1; overflow-y: auto; margin: 14px -4px 0; padding: 0 4px; }
.recents h2 {
  font: 700 11px/1 var(--font);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 0 0 8px 10px;
}
.recents ul { list-style: none; margin: 0; padding: 0; }
.recents li { position: relative; display: flex; align-items: center; border-radius: 8px; }
.recents li:hover, .recents li.active { background: var(--hover); }
.recents li a {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.recents li a .icon { width: 14px; height: 14px; color: var(--muted); }
.recents li a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recents li form { margin: 0; }
.delete-chat { width: 28px; height: 28px; opacity: 0; }
.delete-chat .icon { width: 15px; height: 15px; }
.recents li:hover .delete-chat, .delete-chat:focus { opacity: 1; }
.empty-recents { padding: 0 10px; }

.user-menu { border-top: 1px solid var(--border); padding-top: 8px; position: relative; }
.user-menu summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--hover); }
.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--teal);
  color: #1f3b3b;
  font-weight: 700;
  font-size: 13px;
}
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-items {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 6px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.user-menu-items > span { display: block; padding: 4px 10px 8px; overflow: hidden; text-overflow: ellipsis; }
.user-menu-items form { margin: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; }
.mobile-bar { display: none; }
.scrim { display: none; }

/* ---------- Chat ---------- */

.chat-page { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.project-chip {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}
.project-chip .icon { width: 15px; height: 15px; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 32px max(16px, calc((100% - 760px) / 2)) 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.empty { margin: auto 0; text-align: center; padding-bottom: 8vh; }
.empty h1 { font-size: 2.6rem; margin-bottom: 10px; }
.empty p { max-width: 520px; margin: 0 auto; }

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg .body { max-width: 100%; overflow-x: auto; font-size: 15px; line-height: 1.7; }
.msg.user .body {
  background: var(--user-bubble);
  padding: 10px 16px;
  border-radius: 18px;
  max-width: 85%;
  white-space: pre-wrap;
}
/* Which model answered, shown small under the answer */
.msg.assistant { flex-direction: column; }
.msg.assistant[data-model]::after {
  content: attr(data-model);
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font-family: var(--font); font-weight: 700; font-size: 1.05rem; margin: 18px 0 6px; }
.msg.assistant table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg.assistant th { background: var(--surface); }
.msg.assistant code { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; font-size: .9em; }
.msg.assistant pre { background: var(--surface); padding: 12px; border-radius: 8px; overflow-x: auto; }
.msg.assistant pre code { border: 0; padding: 0; }

.thinking::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(.6); opacity: .5; } }

.activity-note {
  align-self: flex-start;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 12px;
}
.notice {
  background: var(--notice-bg);
  color: var(--notice-text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.composer { padding: 0 max(16px, calc((100% - 760px) / 2)) 14px; }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 10px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  font: 15px/1.5 var(--font);
  border: 0;
  outline: 0;
  resize: none;
  padding: 6px 0;
  background: transparent;
  color: var(--text);
  max-height: 240px;
}
.send { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 10px; }
.composer-hint { text-align: center; margin: 8px 0 0; }

/* ---------- Content pages ---------- */

.page { width: 100%; max-width: 920px; margin: 0 auto; padding: 40px 24px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 14px; color: var(--muted); text-decoration: none; font-size: 13px; }
.back:hover { color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin: 12px 0;
}
.page input:not([type=checkbox]):not([type=file]), .page textarea {
  font: 14px/1.5 var(--font);
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.page input:focus, .page textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.page textarea { resize: vertical; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { font-weight: 700; margin-top: 8px; }
.stack p { margin: 0; }
.stack button { align-self: flex-start; margin-top: 8px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input:not([type=checkbox]) { flex: 1; min-width: 200px; width: auto; }
.check { display: flex; gap: 6px; align-items: center; color: var(--muted); }

.flash { background: var(--accent-soft); color: var(--text); padding: 9px 14px; border-radius: 6px; border-left: 3px solid var(--accent); }
.error { color: var(--error); }

/* Applications */
.app-grid, .project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-top: 20px; }
.app-card, .project-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}
.app-card p, .project-card p { margin: 0 0 10px; flex: 1; }
.project-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.badge {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: #1f3b3b;
  background: rgba(153, 193, 193, .45);
  border-radius: 4px;
  padding: 2px 8px;
  margin-bottom: 8px;
}
.soon { font-size: 12px; color: var(--muted); }

/* Projects */
.create-project summary { display: flex; align-items: center; gap: 8px; font-weight: 700; cursor: pointer; color: var(--accent); }
.create-project form { margin-top: 8px; }
.project-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; margin-top: 8px; }
.project-layout h2:first-child { margin-top: 12px; }
.project-layout aside .card { margin-top: 12px; }
.project-chats { list-style: none; padding: 0; margin: 0; }
.project-chats li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.project-chats a { color: var(--text); text-decoration: none; }
.project-chats a:hover { color: var(--accent); }

/* Uploads */
.dropzone {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px;
  margin: 12px 0 20px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone > .icon { width: 28px; height: 28px; color: var(--accent); }
.dropzone-label { flex: 1; min-width: 200px; display: flex; flex-direction: column; cursor: pointer; }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.sync-card {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px;
  margin: 12px 0 8px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
}
.sync-card > .icon { width: 28px; height: 28px; color: var(--accent); }
.sync-text { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 2px; }
.sync-path { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.sync-card form { margin: 0; }
.sync-skipped { margin: 0 0 12px; }
.sync-skipped ul { margin: 6px 0 0; color: var(--muted); }
.file-list { list-style: none; padding: 0; margin: 0; }
.file { display: flex; gap: 12px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--border); }
.file-icon { color: var(--accent); padding-top: 2px; }
.file-main { flex: 1; min-width: 0; }
.file-name { font-weight: 700; color: var(--text); text-decoration: none; word-break: break-word; }
.file-name:hover { color: var(--accent); }
.file-summary { margin: 4px 0; }
.file-main p { margin: 2px 0; }
.empty-list { margin: 8px 0; }

/* Settings */
.memory { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; }
.memory textarea { border-color: transparent !important; background: transparent !important; padding: 4px 6px !important; }
.memory textarea:hover { border-color: var(--border) !important; }
.memory-actions { display: flex; gap: 2px; align-items: center; justify-content: flex-end; }
.memory-actions span { margin-right: auto; }

/* Admin */
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.users th, table.users td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.users th { font-size: 12px; color: var(--muted); font-weight: 700; }
table.users tr.inactive td { color: var(--muted); }
.row-actions form { display: flex; flex-wrap: wrap; gap: 2px; }
.row-actions button { padding: 4px 8px; font-size: 13px; }

/* ---------- Login ---------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
  background: var(--sidebar);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-card h1 { font-size: 1.9rem; margin: 0; }
.login-card p { margin: 0 0 8px; }
.login-card input {
  font: 14px var(--font);
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-card button { justify-content: center; text-transform: uppercase; letter-spacing: 2px; }
.login-card label { font-weight: 700; }

/* ---------- Phones and small tablets ---------- */

@media (max-width: 860px) {
  .project-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .35); }
  .close-sidebar { display: inline-grid; }
  .delete-chat { opacity: 1; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 5;
  }
  .mobile-title { flex: 1; text-align: center; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .page { padding: 24px 16px 48px; }
  .empty h1 { font-size: 2rem; }
  .chat { padding-top: 20px; }

  table.users thead { display: none; }
  table.users, table.users tbody, table.users tr, table.users td { display: block; width: 100%; }
  table.users tr { border-bottom: 1px solid var(--border); padding: 10px 0; }
  table.users td { border: 0; padding: 2px 0; }
  table.users td:nth-child(2), table.users td:nth-child(3), table.users td:nth-child(4) { display: inline; font-size: 12px; color: var(--muted); }
  table.users td:nth-child(3)::before { content: " · "; }
  table.users td:nth-child(4)::before { content: " · last login "; }
  .row-actions form { margin: 6px -8px 0; }
}
