:root {
  color-scheme: dark;
  --app-height: 100vh;
  --bg: #151718;
  --panel: #202326;
  --panel-2: #282c30;
  --text: #f0eee8;
  --muted: #aaa59a;
  --line: #3b3f43;
  --accent: #74b195;
  --accent-2: #e1b05d;
  --danger: #e07a6f;
}

* {
  box-sizing: border-box;
}

html {
  height: var(--app-height);
  overflow: hidden;
}

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

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

.shell {
  width: min(1120px, 100%);
  height: var(--app-height);
  min-height: 0;
  margin: 0 auto;
  padding: 18px;
  overflow: hidden;
}

.shell.admin-wide {
  width: min(1680px, calc(100vw - 24px));
  padding-left: clamp(8px, 1vw, 18px);
  padding-right: clamp(8px, 1vw, 18px);
}

.panel,
.chat,
.admin {
  height: calc(var(--app-height) - 36px);
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
}

.panel {
  display: grid;
  align-content: center;
  gap: 22px;
  padding: 28px;
}

.brand,
.topbar,
.actions,
.composer {
  display: flex;
  align-items: center;
}

.brand,
.topbar {
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  flex-wrap: wrap;
}

.topbar-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 1 1 220px;
  min-width: 0;
}

.topbar-title h1,
.topbar-title p {
  white-space: nowrap;
}

.topbar-title p {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

#statusText {
  display: inline-flex;
  align-items: center;
  max-width: min(280px, 38vw);
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #151718;
  color: var(--muted);
  font-size: 12px;
}

#statusText.status-ready {
  border-color: rgba(116, 177, 149, 0.55);
  background: rgba(116, 177, 149, 0.12);
  color: var(--accent);
}

#statusText.status-busy {
  border-color: rgba(225, 176, 93, 0.6);
  background: rgba(225, 176, 93, 0.12);
  color: var(--accent-2);
}

#statusText.status-error {
  border-color: rgba(224, 122, 111, 0.65);
  background: rgba(224, 122, 111, 0.12);
  color: var(--danger);
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

p,
.status,
.switch,
.usage {
  color: var(--muted);
}

.status {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.remember-device {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.remember-device input {
  width: auto;
  height: auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #151718;
  color: var(--text);
  outline: none;
}

input {
  height: 42px;
  padding: 0 12px;
}

select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 10px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

button {
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #101513;
  cursor: pointer;
  font-weight: 650;
}

button.secondary,
.actions button {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--text);
}

button.danger {
  border-color: var(--danger);
  background: #33211f;
  color: var(--danger);
}

.chat,
.admin {
  gap: 12px;
  padding: 14px;
  min-height: 0;
}

.chat {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  padding: 0;
  overflow: hidden;
}

.chat-main {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  overflow: hidden;
}

.chat-sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 10px;
  border-right: 1px solid var(--line);
  background: #191b1d;
}

.sidebar-model {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 9px 8px 3px;
  border-top: 1px solid var(--line);
}

.sidebar-model__label {
  color: var(--muted);
  font-size: 11px;
}

.sidebar-model strong {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-model__context {
  color: var(--muted);
  font-size: 11px;
}

.sidebar-search input {
  height: 34px;
  padding: 0 10px;
  background: var(--panel-2);
  font-size: 13px;
}

.sidebar-section {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.chat-section {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.admin {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions button {
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.mode-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.mode-select {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.mode-select select {
  max-width: 140px;
  height: 30px;
  border-color: var(--line);
  background: #151718;
  color: var(--text);
  padding-left: 10px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.sidebar-head p {
  margin-top: 2px;
  font-size: 11px;
}

.sidebar-head button {
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.sidebar-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 0;
  overflow: auto;
}

.project-list {
  display: grid;
  gap: 4px;
}

.project-item {
  justify-content: flex-start;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border-color: var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.project-item:hover,
.project-item.active {
  border-color: var(--accent);
  background: #20302b;
}

.conversation-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 4px;
  width: 100%;
}

.conversation-item {
  display: grid;
  gap: 2px;
  width: 100%;
  height: auto;
  min-height: 42px;
  padding: 7px 8px;
  border-color: var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 500;
  font-size: 13px;
}

.conversation-row:hover .conversation-item,
.conversation-row.active .conversation-item {
  border-color: var(--accent);
  background: #20302b;
}

.conversation-actions {
  display: flex;
  gap: 3px;
}

.conversation-action {
  width: 28px;
  min-width: 28px;
  height: 100%;
  min-height: 42px;
  padding: 0;
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}

.conversation-action.danger {
  color: var(--danger);
}

.conversation-menu {
  grid-column: 1 / -1;
  display: grid;
  gap: 3px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #151718;
}

.conversation-menu-item {
  justify-content: flex-start;
  height: 30px;
  padding: 0 7px;
  border-color: var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-menu-item:hover,
.conversation-menu-item.active {
  border-color: var(--accent);
  background: #20302b;
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-time,
.conversation-empty {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.conversation-empty {
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  font-size: 14px;
}

.mode-controls .switch {
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
}

.switch input {
  width: auto;
  height: auto;
}

.system {
  min-height: 58px;
  background: var(--panel-2);
}

.system-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #191b1d;
}

.system-panel summary {
  min-height: 34px;
  padding: 8px 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.system-panel .system {
  min-height: 74px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 6px 6px;
}

.chat-stage {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.chat-rail {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 0;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px;
}

.message {
  max-width: min(820px, 92%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.45;
}

.message-content {
  white-space: pre-wrap;
}

.message-source-badge {
  width: fit-content;
  max-width: 100%;
  margin-top: 10px;
  padding: 4px 8px;
  border: 1px solid #5d8f86;
  border-radius: 6px;
  background: rgba(46, 112, 99, 0.18);
  color: #9fe0d2;
  font-size: 12px;
  font-weight: 600;
}

.message-tools {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 8px;
}

.message-tools button {
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.message.user {
  align-self: flex-end;
  background: #263434;
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel-2);
}

.message.error {
  border-color: var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(3, 46px);
  gap: 8px;
  align-items: stretch;
}

.attachment-tray {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: min(360px, 100%);
  min-height: 30px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  min-width: 24px;
  width: 24px;
  min-height: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
}

.composer textarea {
  min-height: 50px;
  max-height: min(180px, 32vh);
}

.composer button {
  align-self: end;
  width: 46px;
  min-width: 46px;
  height: 50px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.composer .attachment-chip button {
  align-self: center;
  min-width: 24px;
  width: 24px;
  height: 24px;
  min-height: 24px;
}

.mic-button {
  min-width: 48px;
  width: 48px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.composer .attach-button {
  min-width: 46px;
  width: 46px;
  font-size: 18px;
}

.clear-chat-button {
  min-width: 46px;
}

.mic-button.recording {
  border-color: var(--danger);
  background: var(--danger);
  color: #170b09;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.admin-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
}

.key-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--accent-2);
  border-radius: 8px;
  background: #2e2a20;
}

.key-box code {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--accent-2);
}

.admin-refresh {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.admin-refresh button {
  min-width: 96px;
}

.admin-refresh span {
  color: var(--muted);
  font-size: 13px;
}

.admin-usage {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.api-activity {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}

.api-activity-summary {
  color: var(--text);
  font-weight: 700;
}

.api-activity-list {
  display: grid;
  gap: 6px;
}

.api-activity-item {
  display: grid;
  gap: 3px;
  padding: 8px;
  border: 1px solid #314242;
  border-radius: 8px;
  background: #1f2929;
}

.api-activity-item.active {
  border-color: #2a6f61;
  background: #153832;
}

.api-activity-item strong {
  color: var(--text);
}

.api-activity-empty,
.api-activity-item span {
  color: var(--muted);
}

.user-list {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.user-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 13px;
}

.user-table th,
.user-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.user-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #202727;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

.user-table tr.disabled {
  opacity: 0.62;
}

.user-table tbody tr:hover {
  background: #222c2c;
}

.user-identity {
  display: grid;
  gap: 2px;
}

.user-identity span,
.usage {
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--accent-2);
}

.user-state {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #20352d;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.user-state.disabled {
  background: #33211f;
  color: var(--danger);
}

.work-state {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #314242;
  border-radius: 8px;
  background: #1f2929;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.work-state-generating,
.work-state-api,
.work-state-transcribing {
  border-color: #2a6f61;
  background: #153832;
  color: var(--accent);
}

.work-state-online {
  border-color: #3d5d49;
  background: #20352d;
  color: #9ed7ad;
}

.work-state-disabled {
  border-color: #5b302c;
  background: #33211f;
  color: var(--danger);
}

.work-state-details {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.user-activity-details {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.user-activity-details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 650;
  list-style-position: inside;
}

.user-activity-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 8px 0;
}

.user-activity-stats span {
  padding: 3px 6px;
  border: 1px solid #314242;
  border-radius: 6px;
  background: #1f2929;
}

.user-activity-details .api-activity-list {
  margin-top: 6px;
}

.user-activity-details .api-activity-item {
  padding: 6px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

.row-actions button {
  min-height: 30px;
  height: 30px;
  padding: 0 9px;
  white-space: nowrap;
}

.row-actions .icon-action {
  width: 30px;
  min-width: 30px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.empty {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.hidden {
  display: none;
}

@media (max-width: 680px) {
  .shell {
    padding: 0;
  }

  .shell.admin-wide {
    width: 100%;
    padding: 0;
  }

  .panel,
  .chat,
  .admin {
    height: var(--app-height);
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .login-form,
  .composer,
  .admin-form {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: center;
    gap: 8px;
  }

  .topbar-title {
    flex: 1 1 100%;
    gap: 8px;
  }

  .topbar-title h1 {
    font-size: 20px;
  }

  #statusText {
    max-width: 46vw;
  }

  .chat-stage {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 8px;
  }

  .mic-button {
    min-width: 42px;
    width: 42px;
  }

  .composer {
    grid-template-columns: repeat(3, 46px) minmax(0, 1fr);
  }

  .composer textarea {
    grid-column: 1 / -1;
  }

  .clear-chat-button,
  #stopButton,
  .composer button[type="submit"] {
    min-width: 0;
  }

  .actions {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .actions > * {
    flex: 0 0 auto;
  }

  .mode-controls {
    flex: 1 1 auto;
    justify-content: space-between;
    min-height: 34px;
    min-width: 190px;
  }

  .actions button {
    flex: 0 0 auto;
    height: 34px;
    min-width: 0;
    padding: 0 9px;
  }

  .chat {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .chat-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: 8px;
    max-height: 30vh;
    overflow: hidden;
  }

  .sidebar-section {
    gap: 5px;
  }

  .sidebar-head p {
    display: none;
  }

  .sidebar-head button {
    width: 30px;
    min-width: 30px;
    height: 30px;
  }

  .sidebar-search input {
    height: 32px;
  }

  .project-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .project-item {
    min-width: 132px;
    max-width: 180px;
    height: 30px;
  }

  .conversation-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .conversation-row {
    min-width: 152px;
    max-width: 220px;
  }

  .conversation-item,
  .conversation-action {
    min-height: 38px;
  }
}
