:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --surface: #fbfcfe;
  --text: #172033;
  --muted: #667085;
  --accent: #b42318;
  --accent-2: #f2b705;
  --gold: #ffd21f;
  --border: #d9dee7;
  --assistant: #fff7dc;
  --user: #b42318;
  --shadow: 0 18px 60px rgba(23, 32, 51, 0.12);
}

body.dark {
  color-scheme: dark;
  --bg: #101418;
  --panel: #181f27;
  --surface: #121820;
  --text: #edf2f7;
  --muted: #a8b3c3;
  --border: #2c3542;
  --assistant: #272314;
  --user: #c7362a;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

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

.shell {
  min-height: 100vh;
  width: min(1280px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 24px;
}

.chat-sidebar {
  height: min(820px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.conversation-list {
  overflow: auto;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.conversation-item {
  position: relative;
  width: 100%;
  min-height: 54px;
  display: grid;
  gap: 4px;
  padding: 10px 34px 10px 12px;
  text-align: left;
  background: var(--surface);
}

.conversation-item.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-2) 14%, var(--panel));
}

.conversation-item span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.conversation-item small {
  color: var(--muted);
}

.conversation-delete {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border-radius: 4px;
}

.conversation-delete:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.sidebar-empty {
  margin: 8px;
}

.chat {
  width: 100%;
  height: min(820px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(90deg, var(--gold) 0 38%, var(--accent) 38% 44%, transparent 44%),
    var(--panel);
  background-size: 100% 4px, auto;
  background-repeat: no-repeat;
  background-position: top left;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.brand-copy {
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.idora-avatar {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: end center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(180deg, #ffffff 0 72%, color-mix(in srgb, var(--gold) 14%, #ffffff) 72%),
    #ffffff;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.1);
}

.idora-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  user-select: none;
  pointer-events: none;
}

.idora-avatar.speaking {
  border-color: color-mix(in srgb, var(--accent) 54%, var(--border));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--gold) 28%, transparent),
    0 12px 28px rgba(180, 35, 24, 0.16);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
  line-height: 1.15;
}

button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}

button[type="submit"] {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  padding: 0;
  font-weight: 700;
}

.icon-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.messages {
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--gold) 5%, transparent), transparent 180px),
    var(--surface);
}

.message {
  max-width: min(680px, 78%);
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.48;
  font-size: 15px;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.06);
}

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

.message-audio {
  display: block;
  width: min(320px, 100%);
  margin-top: 8px;
}

.message.user {
  align-self: flex-end;
  background: var(--user);
  color: white;
  border-bottom-right-radius: 5px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.message-label {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.message-action {
  padding: 5px 9px;
  font-size: 12px;
  color: var(--muted);
  background: color-mix(in srgb, white 48%, var(--panel));
}

.message-sources {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.message-sources span {
  overflow-wrap: anywhere;
}

.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.quick-actions button {
  background: var(--surface);
  color: var(--muted);
}

.attachment-tray {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px 0;
  border-top: 1px solid var(--border);
}

.attachment-tray.visible {
  display: flex;
}

.attachment-chip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--gold) 12%, var(--panel));
  font-size: 13px;
}

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

.attachment-chip button {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  padding: 0;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 18px;
  background: var(--panel);
}

.voice-recorder {
  min-width: 0;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: 0 18px 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.voice-recorder[hidden] {
  display: none;
}

.record-button {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  font-family: "Segoe UI Emoji", "Segoe UI", sans-serif;
  font-size: 34px;
  line-height: 1;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 30%, transparent);
}

.mic-trigger {
  font-family: "Segoe UI Emoji", "Segoe UI", sans-serif;
  font-size: 24px;
  line-height: 1;
}

.record-button.recording {
  animation: pulse-recording 1.1s infinite;
}

.voice-panel {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.voice-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.voice-panel-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#recorderTimer {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 750;
}

#transcriptPreview {
  width: 100%;
  min-height: 44px;
  max-height: 82px;
  margin: 0;
  padding: 0;
  resize: vertical;
  border: 0;
  outline: 0;
  overflow: auto;
  background: transparent;
  color: var(--muted);
  font: inherit;
  line-height: 1.35;
}

#transcriptPreview:focus {
  color: var(--text);
}

.voice-preview {
  display: grid;
  gap: 4px;
  margin-top: 4px;
}

.voice-preview[hidden] {
  display: none;
}

.voice-preview audio {
  width: min(360px, 100%);
  height: 34px;
}

.voice-preview span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.voice-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#sendVoiceButton:disabled,
#cancelVoiceButton:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.message-action.active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}

@keyframes pulse-recording {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 38%, transparent);
  }
  70% {
    box-shadow: 0 0 0 13px color-mix(in srgb, var(--accent) 0%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent);
  }
}

.voice-status {
  display: none;
  padding: 0 18px 14px;
  color: var(--muted);
  background: var(--panel);
  font-size: 13px;
}

.voice-status.visible {
  display: block;
}

input {
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 12px 14px;
  font: inherit;
  background: var(--surface);
}

.admin-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.admin-panel {
  min-width: 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.admin-panel.wide {
  grid-column: 1 / -1;
}

.admin-panel h2 {
  margin: 0 0 12px;
  font-size: 16px;
  letter-spacing: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stack {
  display: grid;
  gap: 8px;
}

.metric {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.metric span,
.metric strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric span,
.muted {
  color: var(--muted);
}

@media (max-width: 640px) {
  .shell {
    padding: 0;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 0;
  }

  .chat-sidebar {
    height: auto;
    max-height: 168px;
    border-radius: 0;
    border-width: 0 0 1px;
    box-shadow: none;
  }

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

  .conversation-item {
    width: 220px;
    flex: 0 0 220px;
  }

  .chat {
    height: calc(100vh - 168px);
    border-radius: 0;
    border: 0;
  }

  .topbar {
    padding: 14px 14px 12px;
    gap: 10px;
  }

  .brand {
    gap: 10px;
  }

  .brand-logo {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .idora-avatar {
    width: 58px;
    height: 58px;
  }

  .eyebrow {
    font-size: 12px;
  }

  h1 {
    font-size: 18px;
  }

  .message {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: auto 1fr;
    padding: 12px 14px 16px;
  }

  .voice-recorder {
    grid-column: 1 / -1;
    grid-template-columns: 58px minmax(0, 1fr);
    margin: 0 14px 12px;
  }

  .record-button {
    width: 58px;
    height: 58px;
    font-size: 31px;
  }

  #cancelVoiceButton,
  #sendVoiceButton {
    width: 100%;
  }

  .voice-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .quick-actions,
  .attachment-tray {
    padding-left: 14px;
    padding-right: 14px;
  }

  .admin-shell {
    padding: 12px;
  }

  .admin-header,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
