:root {
  color-scheme: dark;
  --bg: #1e1f22;
  --surface: #2b2d31;
  --border: #3f4147;
  --text: #dbdee1;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #ed4245;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.badge {
  background: var(--accent);
  color: white;
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
}

.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: #4e5058;
}

.btn-secondary:hover {
  background: #6d6f78;
}

.btn-discord {
  background: #5865f2;
  width: 100%;
  text-align: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 1rem;
}

.muted {
  color: var(--muted);
}

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

.ticket-list {
  display: grid;
  gap: 0.75rem;
}

.ticket-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  color: inherit;
  text-decoration: none;
}

.ticket-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.ticket-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.ticket-card-name {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}

.ticket-card-meta {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: 1rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.ticket-card-meta-staff {
  grid-template-columns: 5rem minmax(0, 1fr) auto;
}

.ticket-card-meta-type {
  text-transform: lowercase;
}

.ticket-card-meta-opener {
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}

.ticket-card-meta-date {
  text-align: right;
  white-space: nowrap;
}

.pill {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
}

.pill-closed {
  background: #3a4a6b;
}

.pill-open {
  background: #2d6a4f;
}

.pill-deleted {
  background: #6b3a3a;
}

.live-banner,
.archive-banner {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

.live-banner {
  color: #57f287;
}

.warning-banner {
  color: #fee75c;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

.message-unavailable {
  color: var(--muted);
  font-style: italic;
}

.archive-banner {
  color: var(--muted);
}

.ticket-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.back-link {
  margin: 0 0 1rem;
}

.back-link a {
  color: var(--muted);
  text-decoration: none;
}

.back-link a:hover {
  color: var(--text);
  text-decoration: none;
}

.search-form {
  margin-bottom: 1.5rem;
}

.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.search-grid label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.search-grid input {
  background: #1e1f22;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font: inherit;
}

.search-actions {
  display: flex;
  gap: 0.75rem;
}

.transcript {
  display: grid;
  gap: 0;
}

.message {
  border-top: 1px solid var(--border);
  padding: 1rem 0;
}

.message-header {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}

.message-header time {
  color: var(--muted);
  font-size: 0.85rem;
}

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

.message-system .message-content {
  color: var(--muted);
  font-style: italic;
}

.embed {
  border-left: 4px solid var(--accent);
  background: #232428;
  padding: 0.75rem;
  margin-top: 0.5rem;
  border-radius: 4px;
}

.embed-title {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.embed-description {
  white-space: pre-wrap;
}

.embed-fields {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.embed-footer {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.embed-image,
.attachment-image {
  max-width: min(100%, 520px);
  margin-top: 0.5rem;
  border-radius: 4px;
  display: block;
}

.attachment-link {
  display: inline-block;
  margin-top: 0.5rem;
}

@media (max-width: 640px) {
  .ticket-header {
    flex-direction: column;
  }

  .ticket-card-meta,
  .ticket-card-meta-staff {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .ticket-card-meta-opener,
  .ticket-card-meta-date {
    text-align: left;
    white-space: normal;
  }
}
