:root {
  color-scheme: dark;
  --bg: #101010;
  --sidebar: #171717;
  --surface: #212121;
  --surface-hover: #292929;
  --surface-active: #303030;
  --line: #353535;
  --text: #f3f3f3;
  --muted: #a0a0a0;
  --accent: #f3f3f3;
  --danger: #ff6b72;
  --working: #d8a84e;
  --shadow: 0 16px 44px rgba(0, 0, 0, .34);
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button { color: inherit; }

.hidden { display: none !important; }

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

.sidebar {
  grid-row: 1;
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 10px;
  border-right: 1px solid #242424;
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 7px 9px 10px;
}

.brand-mark,
.mascot,
.message-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid #414141;
  background: linear-gradient(145deg, #313131, #1c1c1c);
  font-weight: 700;
}

.brand-mark { width: 32px; height: 32px; border-radius: 10px; }
.brand b { display: block; font-size: 14px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 4px 0 14px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.new-chat:hover { background: var(--surface-hover); }
.new-chat span { font-size: 18px; line-height: 1; }

.sidebar-label {
  padding: 0 10px 7px;
  color: #777;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.room-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.room {
  display: block;
  width: 100%;
  margin: 2px 0;
  padding: 9px 10px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.room:hover { background: var(--surface-hover); }
.room.active { background: var(--surface-active); }
.room b,
.room small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room b { font-size: 13px; font-weight: 500; }
.room small { margin-top: 3px; color: #858585; font-size: 11px; }

.sidebar-actions {
  display: grid;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px solid #292929;
}

.ghost {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.ghost:hover { background: var(--surface-hover); color: var(--text); }
.danger:hover { color: var(--danger); }

.chat {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100%;
  background: var(--bg);
}

.chat-header {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 9px 20px;
  border-bottom: 1px solid #242424;
  background: rgba(16, 16, 16, .94);
  backdrop-filter: blur(10px);
}

.chat-header h1 { margin: 0; font-size: 15px; font-weight: 600; }
.chat-header p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.menu-button { display: none; padding: 3px; border: 0; background: transparent; font-size: 21px; cursor: pointer; }

.job-badge {
  margin-left: auto;
  padding: 6px 9px;
  border: 1px solid #5a4b2e;
  border-radius: 999px;
  background: #2a2419;
  color: #e9c16f;
  font-size: 11px;
  font-weight: 600;
}

.job-panel {
  grid-row: 2;
  width: min(calc(100% - 40px), 760px);
  margin: 12px auto 0;
  padding: 12px 14px;
  border: 1px solid #4e432f;
  border-radius: 12px;
  background: #211e18;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
}

.job-panel-head { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.job-panel-head b { color: #f1d393; font-weight: 600; }
.job-panel-head span { color: #9e9178; font-variant-numeric: tabular-nums; }
.job-progress { margin-top: 7px; color: #d7d0c1; font-size: 12px; line-height: 1.5; white-space: pre-wrap; }

.messages {
  grid-row: 3;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 0;
  padding: 30px max(20px, calc((100% - 760px) / 2)) 54px;
  overflow: auto;
  scroll-behavior: smooth;
}

.empty { margin: auto; color: #727272; font-size: 14px; }

.message {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-self: stretch;
  gap: 12px;
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
}

.message-avatar {
  width: 28px;
  height: 28px;
  margin-top: 1px;
  border-radius: 8px;
  font-size: 12px;
}

.message.user .message-avatar { background: #e8e8e8; color: #171717; }
.message.system { grid-template-columns: 1fr; color: var(--muted); font-size: 12px; text-align: center; }
.message.system .message-avatar,
.message.system .message-meta { display: none; }
.message.system .message-content { padding: 8px 12px; border: 1px solid #292929; border-radius: 9px; }
.message-body { min-width: 0; }
.message-meta { display: flex; align-items: baseline; gap: 8px; margin: 0 0 7px; color: #727272; font-size: 11px; }
.message-meta b { color: #d8d8d8; font-size: 12px; font-weight: 600; }
.message-content { color: #ededed; font-size: 14px; line-height: 1.62; overflow-wrap: anywhere; white-space: pre-wrap; }
.message.user .message-content { display: inline-block; padding: 10px 13px; border-radius: 16px 16px 4px 16px; background: var(--surface); }
.message.user .message-body { text-align: left; }
.message.working { opacity: .82; }
.message.working .message-content::after { content: ""; display: inline-block; width: 5px; height: 5px; margin-left: 7px; border-radius: 50%; background: var(--working); animation: pulse 1.2s infinite; vertical-align: middle; }
.message.failed .message-content { color: #ffb7ba; }

@keyframes pulse { 50% { opacity: .25; transform: scale(.75); } }

.message-content a { color: #a9c7ff; }
.message-content code { padding: 2px 5px; border-radius: 5px; background: #272727; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.message-content pre { margin: 10px 0; padding: 12px; overflow: auto; border: 1px solid #343434; border-radius: 9px; background: #181818; white-space: pre; }

.attachments { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin-top: 10px; }
.attachment-box { display: grid; min-width: 0; gap: 6px; }
.attachment { display: block; min-width: 0; padding: 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #1a1a1a; color: #c6d5f0; font-size: 12px; text-decoration: none; text-overflow: ellipsis; }
.attachment:hover { border-color: #505050; }
.attachment img { display: block; width: 100%; max-height: 360px; margin-bottom: 7px; border-radius: 7px; object-fit: contain; background: #0d0d0d; }
.annotate-button { width: 100%; padding: 7px 9px; border: 1px solid #3f4d64; border-radius: 8px; background: #1d2430; color: #bcd0ef; font-size: 11px; cursor: pointer; }
.annotate-button:hover { background: #263246; }

.composer-shell {
  grid-row: 4;
  padding: 10px 20px 14px;
  background: linear-gradient(180deg, rgba(16, 16, 16, 0), var(--bg) 18%);
}

.composer {
  width: min(100%, 800px);
  margin: 0 auto;
  padding: 8px 10px 8px 14px;
  border: 1px solid #3b3b3b;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 9px 28px rgba(0, 0, 0, .22);
}

.composer:focus-within { border-color: #535353; }
.composer textarea { display: block; width: 100%; min-height: 46px; max-height: 180px; padding: 8px 2px; resize: none; border: 0; outline: none; background: transparent; color: var(--text); line-height: 1.45; }
.composer textarea::placeholder { color: #828282; }
.composer-actions { display: flex; align-items: center; gap: 9px; min-height: 32px; }
.attach { display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid #4b4b4b; border-radius: 50%; color: #d3d3d3; font-size: 19px; line-height: 1; cursor: pointer; }
.attach:hover { background: #303030; }
.attach input { display: none; }
.composer-note { color: #777; font-size: 10px; }
.composer button,
.login-card button { border: 0; cursor: pointer; }
.composer #send { display: grid; width: 32px; height: 32px; margin-left: auto; padding: 0; place-items: center; border-radius: 50%; background: var(--accent); color: #111; font-size: 18px; font-weight: 800; }
.composer #send:disabled { opacity: .35; cursor: default; }
.stop { padding: 7px 10px; border: 1px solid #674044 !important; border-radius: 8px; background: #3a2225 !important; color: #ffb8bc; font-size: 11px; }
.file-list { color: #b8b8b8; font-size: 11px; overflow-wrap: anywhere; }
.composer-disclaimer { width: min(100%, 800px); margin: 6px auto 0; color: #6e6e6e; font-size: 10px; text-align: center; }

.login-body { display: grid; place-items: center; min-height: 100%; padding: 20px; background: radial-gradient(circle at 50% 20%, #292929, #101010 58%); }
.login-card { width: min(92vw, 390px); padding: 32px; border: 1px solid var(--line); border-radius: 20px; background: #181818; box-shadow: var(--shadow); }
.login-card .mascot { width: 42px; height: 42px; margin-bottom: 20px; border-radius: 13px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 7px 0 24px; color: var(--muted); }
.login-card label,
.dialog-form label { display: grid; gap: 7px; margin: 13px 0; color: var(--muted); font-size: 12px; }
.login-card input,
.dialog-form input,
.dialog-form textarea,
.dialog-form select { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 9px; outline: none; background: var(--surface); color: var(--text); }
.login-card input:focus,
.dialog-form input:focus,
.dialog-form textarea:focus { border-color: #5e5e5e; }
.login-card button,
.dialog-form button { width: 100%; margin-top: 9px; padding: 10px 14px; border-radius: 9px; background: #ededed; color: #111; font-weight: 650; }
.error { min-height: 18px; color: var(--danger); font-size: 12px; }

dialog { width: min(92vw, 560px); padding: 24px; border: 1px solid var(--line); border-radius: 17px; background: #181818; color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .68); }
.dialog-close { position: absolute; top: 10px; right: 13px; border: 0; background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; }
.dialog-form { display: grid; gap: 4px; }
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.check-grid label { display: flex; align-items: center; gap: 7px; margin: 0; }
.check-grid input { width: auto; }
.user-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row small { display: block; margin-top: 4px; color: var(--muted); }
.dialog-help { color: var(--muted); font-size: 13px; line-height: 1.5; }
.dialog-form small { color: #777; font-size: 10px; }
.access-box { margin: 8px 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.access-box legend { padding: 0 5px; color: var(--muted); font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.setting-card { padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-align: left; cursor: pointer; }
.setting-card:hover { border-color: #565656; }
.setting-card b,
.setting-card span { display: block; }
.setting-card span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.status-list { display: grid; gap: 7px; }
.status-list > div { display: flex; justify-content: space-between; gap: 15px; padding: 10px 0; border-bottom: 1px solid #292929; font-size: 12px; }
.status-list span { color: var(--muted); text-align: right; }

.admin-view {
  display: grid;
  grid-column: 2;
  grid-row: 1;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  height: 100%;
  background: var(--bg);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 14px 24px;
  border-bottom: 1px solid #282828;
}
.admin-header h1 { margin: 0; font-size: 18px; }
.admin-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.admin-header button { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.admin-header button:hover { background: var(--surface-hover); }

.admin-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 0; }
.admin-nav { display: flex; flex-direction: column; gap: 3px; padding: 16px 10px; overflow: auto; border-right: 1px solid #282828; background: #141414; }
.admin-nav button { padding: 10px 11px; border: 0; border-radius: 8px; background: transparent; color: #b9b9b9; text-align: left; cursor: pointer; }
.admin-nav button:hover { background: #252525; color: var(--text); }
.admin-nav button.active { background: #303030; color: #fff; }
.admin-content { padding: 28px max(24px, calc((100% - 920px) / 2)); overflow: auto; }
.admin-content h2 { margin: 0 0 7px; font-size: 22px; }
.admin-content h3 { margin: 28px 0 10px; font-size: 15px; }
.admin-content > p,
.section-intro { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.admin-loading { color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: #191919; }
.metric b { display: block; font-size: 23px; }
.metric span { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
.admin-card { margin: 10px 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #191919; }
.admin-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.admin-card b { font-size: 13px; }
.admin-card p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.admin-card code { color: #c9d9f5; font-size: 11px; }
.status-pill { flex: 0 0 auto; padding: 5px 8px; border: 1px solid #3c5548; border-radius: 999px; background: #1a2a21; color: #7bd49b; font-size: 10px; }
.status-pill.off { border-color: #554438; background: #2a211b; color: #d9a875; }
.status-pill.locked { border-color: #414141; background: #242424; color: #aaa; }
.admin-form { display: grid; gap: 13px; max-width: 720px; }
.admin-form label { display: grid; gap: 7px; color: #dadada; font-size: 12px; }
.admin-form label > span { color: var(--muted); font-size: 10px; line-height: 1.45; }
.admin-form select,
.admin-form input,
.admin-form textarea { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 9px; outline: none; background: var(--surface); color: var(--text); }
.admin-form select:focus,
.admin-form input:focus,
.admin-form textarea:focus { border-color: #5c5c5c; }
.admin-form button,
.admin-primary { width: fit-content; padding: 9px 14px; border: 0; border-radius: 8px; background: #ededed; color: #111; font-weight: 650; cursor: pointer; }
.admin-secondary { width: fit-content; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #252525; color: var(--text); cursor: pointer; }
.admin-secondary:hover { background: #303030; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid #292929; }
.toggle-row p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.toggle { min-width: 54px; padding: 6px 9px; border: 1px solid #4a4a4a; border-radius: 999px; background: #252525; font-size: 10px; cursor: pointer; }
.toggle.on { border-color: #447154; background: #1f402b; color: #8ee3aa; }
.toggle:disabled { opacity: .45; cursor: not-allowed; }
.admin-notice { margin: 14px 0; padding: 11px 13px; border-left: 3px solid #c49c54; border-radius: 7px; background: #211e18; color: #d4c6aa; font-size: 11px; line-height: 1.5; }
.help-steps { display: grid; gap: 10px; padding: 0; list-style: none; counter-reset: steps; }
.help-steps li { position: relative; min-height: 38px; padding: 3px 0 3px 46px; color: #d8d8d8; font-size: 13px; line-height: 1.5; }
.help-steps li::before { counter-increment: steps; content: counter(steps); position: absolute; left: 0; top: 0; display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: #242424; }
.room-admin-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 9px; }
.room-admin { padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #191919; cursor: pointer; }
.room-admin:hover { border-color: #555; }
.room-admin b,
.room-admin span { display: block; }
.room-admin span { margin-top: 5px; color: var(--muted); font-size: 11px; }

dialog.annotation-dialog { width: min(96vw, 1180px); max-height: 94vh; padding: 20px; overflow: auto; }
.annotation-picker { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr); gap: 10px; margin: 12px 0; }
.annotation-picker label { display: grid; gap: 6px; color: #ddd; font-size: 11px; }
.annotation-picker select,
.annotation-picker input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; outline: none; background: #222; color: var(--text); }
.annotation-picker select:focus,
.annotation-picker input:focus { border-color: #66758a; }
.annotation-tools { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.annotation-tools button { display: flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #222; color: #ccc; font-size: 11px; cursor: pointer; }
.annotation-tools button.active { border-color: #7c8da8; background: #2b3442; color: #fff; }
.annotation-tools i { width: 10px; height: 10px; border-radius: 50%; background: var(--marker); }
.annotation-zoom { display: flex; align-items: center; gap: 10px; margin: 9px 0; color: var(--muted); font-size: 11px; }
.annotation-zoom input { flex: 1; }
.annotation-zoom output { width: 42px; color: #ddd; text-align: right; }
.annotation-viewport { width: 100%; height: min(58vh, 680px); overflow: auto; border: 1px solid var(--line); border-radius: 11px; background: #0b0b0b; }
.annotation-stage { position: relative; width: 100%; min-width: 100%; cursor: crosshair; }
.annotation-stage.zoom-125 { width: 125%; }
.annotation-stage.zoom-150 { width: 150%; }
.annotation-stage.zoom-175 { width: 175%; }
.annotation-stage.zoom-200 { width: 200%; }
.annotation-stage.zoom-225 { width: 225%; }
.annotation-stage.zoom-250 { width: 250%; }
.annotation-stage.zoom-275 { width: 275%; }
.annotation-stage.zoom-300 { width: 300%; }
.annotation-stage img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
#annotation-markers { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.annotation-summary { display: flex; gap: 12px; margin: 10px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.annotation-summary b { flex: 0 0 auto; color: #ddd; }
.annotation-instruction { display: grid; gap: 6px; color: #ddd; font-size: 12px; }
.annotation-instruction textarea { padding: 10px; resize: vertical; border: 1px solid var(--line); border-radius: 9px; background: #222; color: var(--text); }
.annotation-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 11px; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; inset: 0 auto 0 0; width: min(86vw, 320px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: block; }
  .chat-header { min-height: 54px; padding: 8px 12px; }
  .chat-header p { display: none; }
  .job-badge { max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .job-panel { width: calc(100% - 20px); margin-top: 8px; }
  .messages { gap: 21px; padding: 22px 12px 34px; }
  .message { grid-template-columns: 26px minmax(0, 1fr); gap: 9px; }
  .message-avatar { width: 26px; height: 26px; }
  .message-content { font-size: 13px; }
  .attachments { grid-template-columns: 1fr; }
  .composer-shell { padding: 8px 9px 10px; }
  .composer { border-radius: 16px; }
  .composer-note { display: none; }
  .composer-disclaimer { font-size: 9px; }
  .admin-view { grid-column: 1; }
  .admin-header { padding: 11px 12px; }
  .admin-header p { display: none; }
  .admin-header button { padding: 7px 9px; font-size: 11px; }
  .admin-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .admin-nav { flex-direction: row; padding: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid #282828; }
  .admin-nav button { flex: 0 0 auto; padding: 8px 10px; font-size: 11px; }
  .admin-content { padding: 20px 13px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  dialog.annotation-dialog { width: 100vw; max-width: none; height: 100vh; max-height: none; padding: 14px; border: 0; border-radius: 0; }
  .annotation-picker { grid-template-columns: 1fr; }
  .annotation-viewport { height: 50vh; }
  .annotation-tools button { padding: 7px 8px; }
  .annotation-actions { position: sticky; bottom: 0; padding: 9px 0; background: #181818; }
  .annotation-actions button { font-size: 10px; }
}
