:root {
  color-scheme: light dark;
  --bg: #f8f8f6;
  --fg: #1a1a1a;
  --muted: #666;
  --line: #d8d8d4;
  --head: #ececea;
  --accent: #2f6fab;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111;
    --fg: #ececec;
    --muted: #9a9a9a;
    --line: #333;
    --head: #1a1a1a;
    --accent: #7eb6e8;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 13px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 12px;
}

.meta.error {
  color: #b00020;
}

.controls {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}

button {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}

main {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-head h2 {
  margin: 0 0 2px;
  font-size: 14px;
  font-weight: 600;
}

.section-head p {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  max-height: 420px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--head);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

td {
  max-width: 220px;
}

td.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

td.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

td.expandable {
  cursor: pointer;
  color: var(--accent);
}

td.expandable:hover {
  text-decoration: underline;
}

td.expandable.truncated::after {
  content: ' ↗';
  color: var(--accent);
  font-size: 10px;
}

.empty {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0;
}

#expand-dialog {
  width: min(90vw, 720px);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

#expand-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

#expand-dialog form {
  margin: 0;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.dialog-head button {
  font-size: 18px;
  line-height: 1;
  padding: 0 6px;
}

#expand-body {
  margin: 0;
  padding: 12px;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  user-select: text;
  cursor: text;
}

.dm-input {
  width: 100%;
  min-width: 120px;
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  color: var(--fg);
  box-sizing: border-box;
}

.dm-textarea {
  resize: vertical;
  min-height: 2.5em;
  font-family: inherit;
}

td.editable-cell {
  max-width: 280px;
}

.dm-status-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}

.dm-actions {
  white-space: nowrap;
  vertical-align: middle;
}

.dm-save-btn {
  font-size: 11px;
  padding: 3px 8px;
}

.section-editable .table-wrap {
  max-height: 480px;
}

/* Read-only transcript page */
.transcript-page .transcript-main {
  padding: 14px;
  max-width: 960px;
}

.tx-session {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--head);
}

.tx-turn {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.tx-turn.tx-highlight {
  outline: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.tx-turn-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-bottom: 8px;
}

.tx-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--head);
  border: 1px solid var(--line);
}

.tx-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.tx-empty {
  color: var(--muted);
  font-style: italic;
  padding: 6px 0;
}

.tx-turn h3 {
  margin: 8px 0 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* Login page (Decode Age Debugger) */
body.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-wrap {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.login-subtitle {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.login-form input {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
}

.login-form button {
  margin-top: 4px;
  padding: 8px 12px;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.login-error {
  margin: 0;
  color: #b00020;
  font-size: 12px;
  text-align: center;
}

