:root {
  --brand: #1f6feb;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #646b78;
  --border: #e2e5ea;
  --danger: #c93c37;
  --ok: #1a7f37;
  --radius: 12px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2a2f38;
    --danger: #f06c66;
    --ok: #4cc26a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Classes below set display, which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

button, input, textarea, select { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- buttons & fields ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 13px; }
.field input, .field textarea, .field select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--brand); }
.check small { display: block; color: var(--muted); }

.error { color: var(--danger); font-size: 14px; min-height: 1.2em; }

/* ---------- brand ---------- */

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-logo { height: 28px; width: auto; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--brand);
  display: grid; place-items: center; color: #fff; font-size: 14px;
}

/* ---------- centered card (login / guest join) ---------- */

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 400px;
}
.card .brand { margin-bottom: 20px; }
.card h1 { font-size: 20px; margin: 0 0 6px; }
.card p { margin: 0 0 18px; }

/* ---------- owner layout ---------- */

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

.sidebar, .panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}
.panel { border-right: none; border-left: 1px solid var(--border); }
.panel h3 { margin: 0; font-size: 16px; }
.panel p { margin: 0; }

.chat-list { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.chat-row { display: flex; align-items: center; border-radius: 8px; flex: none; }
.chat-row:hover { background: var(--surface-2); }
.chat-row.active { background: color-mix(in srgb, var(--brand) 14%, transparent); }
.chat-row.active .chat-item { font-weight: 600; }
.chat-item {
  flex: 1; min-width: 0; text-align: left; border: none; background: transparent; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-rename {
  flex: none; border: none; background: transparent; color: var(--muted); cursor: pointer;
  width: 28px; height: 28px; margin-right: 4px; border-radius: 6px; opacity: 0;
}
.chat-row:hover .chat-rename, .chat-rename:focus-visible { opacity: 1; }
.chat-rename:hover { color: var(--brand); background: var(--surface); }
@media (hover: none) { .chat-rename { opacity: 1; } }
.chat-rename-input {
  flex: 1; min-width: 0; border: 1px solid var(--brand); background: var(--surface);
  border-radius: 8px; padding: 7px 9px;
}
.sidebar-foot { display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--border); padding-top: 12px; }

/* ---------- chat column ---------- */

.chat { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.chat-head .brand { font-size: 16px; }
.title-input {
  flex: 1; border: 1px solid transparent; background: transparent; font-weight: 600;
  font-size: 17px; padding: 6px 8px; border-radius: 8px; min-width: 0;
}
.title-input:hover { border-color: var(--border); }

.messages { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 760px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.msg .who { font-size: 12px; font-weight: 600; color: var(--muted); }
.msg .body {
  padding: 12px 16px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); overflow-wrap: anywhere;
}
.msg.user .body { background: color-mix(in srgb, var(--brand) 10%, var(--surface)); border-color: transparent; }
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body table { border-collapse: collapse; display: block; overflow-x: auto; }
.msg .body th, .msg .body td { border: 1px solid var(--border); padding: 4px 8px; }
.msg .body pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg.thinking .body { color: var(--muted); font-style: italic; }
.dots::after { content: ""; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75%, 100% { content: "..."; }
}
.msg.streaming .body > :last-child::after {
  content: "▍"; margin-left: 2px; color: var(--brand); animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.msg.error .body { color: var(--danger); border-color: var(--danger); }

.empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 24px; }
.empty h2 { margin: 0 0 8px; }
.empty p { max-width: 420px; margin: 0 auto 16px; }

.file-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px; max-width: 800px; width: 100%; margin: 0 auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 4px 3px 10px;
}
.chip a { color: inherit; text-decoration: none; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip a:hover { text-decoration: underline; }
.chip .x { border: none; background: transparent; cursor: pointer; color: var(--muted); padding: 0 6px; border-radius: 999px; }
.chip .x:hover { color: var(--danger); }

.action-bar {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 20px 0; max-width: 800px; width: 100%; margin: 0 auto;
}
.action-bar .btn { border-radius: 999px; font-size: 13px; padding: 5px 12px; flex: none; }
.action-bar .btn:hover { border-color: var(--brand); color: var(--brand); background: var(--surface); }

.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 12px 20px 20px;
  max-width: 800px; width: 100%; margin: 0 auto;
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius); padding: 11px 14px; max-height: 200px; min-height: 46px;
}
.composer .btn { height: 46px; }

.dropzone {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 4px 8px;
  max-width: 760px; width: calc(100% - 40px); margin: 0 auto 8px; padding: 12px 16px;
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--surface);
  cursor: pointer; text-align: center; font-size: 14px;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--brand); outline: none; }
.dropzone:hover strong { color: var(--brand); }

.chat { position: relative; }
.drop-overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  border: 2px dashed var(--brand); border-radius: var(--radius);
}
.drop-overlay div {
  background: var(--surface); color: var(--brand); font-weight: 600;
  padding: 14px 22px; border-radius: var(--radius); box-shadow: 0 6px 24px rgb(0 0 0 / 0.15);
}

.actions-list { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; }
.action-row {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--bg);
}
.action-row .action-text { min-width: 0; overflow-wrap: anywhere; }
.action-row .actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; flex: none; max-width: 50%; }

/* ---------- share cards ---------- */

.share-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; gap: 8px; background: var(--bg);
}
.share-card .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.share-card .label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-card .actions { display: flex; flex-wrap: wrap; gap: 4px; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.pill.on { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.off { background: var(--surface-2); color: var(--muted); }

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog form, dialog .dialog-body { padding: 22px; }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.file-picks { border: 1px solid var(--border); border-radius: 8px; padding: 10px; max-height: 180px; overflow-y: auto; }
.notice {
  font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px;
}

.activity-guest { border-top: 1px solid var(--border); padding: 14px 0; }
.activity-guest:first-child { border-top: none; padding-top: 0; }
.activity-guest .msg { margin: 8px 0 0; }

/* ---------- guest page ---------- */

.guest { display: flex; flex-direction: column; height: 100vh; }
.guest-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.guest-head .label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shared-analysis { max-width: 760px; width: 100%; margin: 0 auto; }
.shared-analysis summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
.shared-analysis .msg { margin-top: 12px; }
.divider { max-width: 760px; width: 100%; margin: 0 auto; border-top: 1px dashed var(--border); }

/* ---------- small screens ---------- */

@media (max-width: 1100px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .panel { grid-column: 1 / -1; border-left: none; border-top: 1px solid var(--border); }
  .app { height: auto; }
  .chat { height: 80vh; }
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .chat { height: 85vh; }
  .messages, .composer, .file-bar, .action-bar, .chat-head { padding-left: 16px; padding-right: 16px; }
  .dropzone { width: calc(100% - 32px); }
}
