:root {
  --bg: #0b0c0d;
  --panel: #151719;
  --panel-2: #1c1f22;
  --line: #2a2e33;
  --text: #e8eaed;
  --muted: #8b939c;
  --accent: #3ddc84;
  --accent-dim: #1f6b43;
  --danger: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.9em; color: var(--muted); }
h1 { font-size: 1.25rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.inline { display: inline; margin: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #000;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; flex-direction: column; }
.logo { font-weight: 700; letter-spacing: 0.08em; color: var(--accent); }
.sub { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }

.viewer { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent-dim); }
.btn.ghost { background: transparent; }

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

main.centered {
  text-align: center;
  padding-top: 15vh;
}

.ticket-info {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}

.info-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.info-row:last-child { border-bottom: none; }
.info-row dt { color: var(--muted); font-size: 0.85rem; }
.info-row dd { margin: 0; }

.messages { display: flex; flex-direction: column; gap: 12px; }

.message {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.message.role-customer { border-left: 3px solid #4aa3ff; }
.message.role-staff { border-left: 3px solid var(--accent); }
.message.role-ai { border-left: 3px solid #b48cff; }

.avatar {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.avatar.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
}

.message-main { min-width: 0; flex: 1; }

.message-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
}
.author { font-weight: 600; overflow-wrap: anywhere; }
.badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.role-staff .badge { color: var(--accent); border-color: var(--accent-dim); }
.ts { font-size: 0.8rem; color: var(--muted); }

.content { white-space: normal; overflow-wrap: anywhere; }

.embed {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--panel-2);
  border-left: 3px solid var(--accent-dim);
  border-radius: 6px;
  overflow-wrap: anywhere;
}
.embed-author, .embed-footer { font-size: 0.8rem; color: var(--muted); }
.embed-title { font-weight: 600; }
.embed-field { margin-top: 6px; }
.embed-field-name { font-size: 0.85rem; color: var(--muted); }

.attachment { margin-top: 8px; }
.attachment img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.attachment.missing { color: var(--muted); font-size: 0.9rem; }

/* Discord formatting: mentions, emoji, code */
.mention {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  font-weight: 500;
  line-height: 1.5;
  background: rgba(61, 220, 132, 0.12);
  color: #9be9bd;
}
.mention-role { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.mention-channel { background: rgba(255, 255, 255, 0.06); color: var(--muted); }
.emoji { width: 22px; height: 22px; vertical-align: -5px; }
.inline-code, .code-block {
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.inline-code { padding: 0 5px; border-radius: 4px; overflow-wrap: anywhere; }
.code-block {
  display: block;
  margin: 6px 0;
  padding: 10px 12px;
  border-radius: 6px;
  white-space: pre;
  overflow-x: auto;
  max-width: 100%;
}
.code-block code { font: inherit; }

/* Identifiers stay available but visually secondary */
.id {
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 0.72rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.person-name { font-weight: 600; overflow-wrap: anywhere; }
.page-nav { margin-bottom: 12px; }
.btn.back { display: inline-block; }

@media (max-width: 560px) {
  .info-row { grid-template-columns: 1fr; gap: 0; }
  .message { padding: 10px; gap: 10px; }
  .avatar { flex-basis: 32px; width: 32px; height: 32px; }
}

/* Staff dashboard */
main.dashboard { max-width: 1100px; }
.dash-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.dash-head h1 { margin: 0; }
.summary { margin: 0; font-size: 0.9rem; }

.filters {
  display: grid;
  grid-template-columns: 2fr 1.4fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); min-width: 0; }
.filters input, .filters select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 0.9rem;
  color-scheme: dark;
}
.filters input:focus, .filters select:focus { outline: none; border-color: var(--accent-dim); }
.filter-actions { display: flex; gap: 8px; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
table.tickets { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.tickets th, table.tickets td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tickets th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; background: var(--panel-2); }
table.tickets tbody tr:last-child td { border-bottom: none; }
table.tickets tbody tr:hover { background: var(--panel-2); }
.ticket-link { font-weight: 700; color: var(--accent); text-decoration: none; }
.ticket-link:hover { text-decoration: underline; }
.customer-name { display: block; overflow-wrap: anywhere; }
table.tickets code { display: block; font-size: 0.75rem; overflow-wrap: anywhere; }
.open-cell { text-align: right; }
.status { color: var(--accent); font-size: 0.85rem; }

.pagination { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }
.btn.disabled { opacity: 0.4; cursor: default; }

.empty-state {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
}
.empty-state h2 { font-size: 1.05rem; margin: 0 0 6px; }
.empty-state p { margin: 0 0 12px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 900px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filter-actions { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  table.tickets thead { display: none; }
  table.tickets, table.tickets tbody, table.tickets tr, table.tickets td { display: block; width: 100%; }
  table.tickets tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.tickets tbody tr:last-child { border-bottom: none; }
  table.tickets td { border: none; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; align-items: baseline; }
  table.tickets td::before { content: attr(data-label); color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; flex: 0 0 auto; }
  table.tickets td > * { text-align: right; }
  table.tickets td.open-cell { justify-content: flex-end; }
  table.tickets td.open-cell::before { content: none; }
  table.tickets code { display: inline; }
  .customer-name { display: inline; }
  .filters { grid-template-columns: 1fr; }
}
