/* DiscordActivator control panel — minimal, theme-aware. */

:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --surface-2: #f2f2f5;
  --border: #e3e3e9;
  --text: #16161a;
  --muted: #6c6c78;
  --accent: #5865f2;
  --accent-text: #ffffff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 16, 24, 0.06),
    0 8px 24px rgba(16, 16, 24, 0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e12;
    --surface: #16161c;
    --surface-2: #1d1d25;
    --border: #2a2a34;
    --text: #ececf2;
    --muted: #9a9aa8;
    --accent: #7079f5;
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

/* The screens below set an explicit `display`, which would otherwise beat the
   user-agent rule for the `hidden` attribute and render every screen at once.
   Author styles win over the UA sheet, so restate it here. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 20px;
}
h2 {
  font-size: 16px;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}

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

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

/* ---------- boot + login ---------- */

.boot,
.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  gap: 12px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.login-card {
  width: min(420px, calc(100vw - 40px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
  text-align: center;
}

.login-mark {
  font-size: 34px;
}

.login-card h1 {
  margin: 10px 0 6px;
}

.login-card p {
  margin: 0 0 20px;
}

.discord-mark {
  width: 18px;
  height: 14px;
}

/* ---------- shell ---------- */

.shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
}

.brand-mark {
  font-size: 22px;
}

.brand strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

.brand small {
  font-size: 12px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.nav-item span {
  width: 16px;
  text-align: center;
  opacity: 0.8;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.is-active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 550;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

/* Sized in CSS as well as in the attributes: an avatar that fails to load
   must not be able to change the layout of the sidebar foot. */
.me-avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: cover;
}

/* Shown until the avatar actually loads, and left in place if it never
   does — a blocked CDN request should read as an initial, not a broken
   image icon. */
.me-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.me-text strong {
  display: block;
  font-size: 13px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me-text small {
  font-size: 11px;
}

/* ---------- content ---------- */

.content {
  padding: 22px 26px 60px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar p {
  margin: 2px 0 0;
  font-size: 13px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- cards + grid ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.card-body {
  padding: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.stat .value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.stat .label {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- tables ---------- */

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
  position: sticky;
  top: 0;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

td.wrap {
  white-space: normal;
}

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

/* App-ID assignments in the account dialog. An account can hold dozens, so
   these wrap instead of forcing the modal wider. */
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chips .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.empty {
  padding: 34px 16px;
  text-align: center;
  color: var(--muted);
}

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 550;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.badge.hot {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
}

.badge.donator {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.badge.ok {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
  background: color-mix(in srgb, var(--success) 12%, transparent);
}

.badge.off {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, black);
}

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  width: 100%;
  padding: 11px 16px;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ---------- forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.field > label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.field .hint {
  font-size: 11px;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="file"],
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus,
.btn:focus-visible,
.nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 2px 16px;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar .grow {
  flex: 1;
  min-width: 160px;
}

/* ---------- modal ---------- */

.modal-host {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 12, 0.55);
  backdrop-filter: blur(2px);
}

.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 380px;
  animation: rise 0.16s ease-out;
}

.toast.ok {
  border-left: 3px solid var(--success);
}

.toast.err {
  border-left: 3px solid var(--danger);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav-item {
    width: auto;
  }

  .content {
    padding: 18px 16px 50px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- global search ---------- */

.topbar-tools {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* The field is a shell around the input so the icon and the shortcut hint
   sit inside it rather than beside it. */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 220px;
  max-width: 420px;
  width: 32vw;
}

.search-icon {
  position: absolute;
  left: 11px;
  font-size: 15px;
  color: var(--muted);
  pointer-events: none;
}

.search {
  width: 100%;
  padding: 8px 40px 8px 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background 0.15s ease;
}

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

.search:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.search::-webkit-search-cancel-button {
  cursor: pointer;
}

.search-kbd {
  position: absolute;
  right: 10px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--muted);
  font: 500 11px/1.6 var(--mono);
  pointer-events: none;
}

/* Once you are typing, the hint has done its job. */
.search:focus ~ .search-kbd,
.search:not(:placeholder-shown) ~ .search-kbd {
  opacity: 0;
}

/* Anchored under the top bar rather than inline, so results never push the
   view around while typing. */
.search-results {
  position: absolute;
  right: 26px;
  z-index: 30;
  width: min(460px, calc(100vw - 52px));
  margin: 4px 0 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 60vh;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.search-group {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.search-group:last-child {
  border-bottom: 0;
}

.search-group-title {
  padding: 4px 14px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.search-hit {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 8px 14px;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.search-hit:hover,
.search-hit:focus-visible {
  background: var(--surface-2);
}

.search-more {
  padding: 4px 14px 8px;
  font-size: 13px;
}

/* ---------- transcript viewer ---------- */

.transcript-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 12px 2px;
}

.msg {
  border-left: 2px solid var(--border);
  padding: 4px 0 4px 10px;
}

/* Bot messages carry the activation steps, so they get the accent edge. */
.msg-bot {
  border-left-color: var(--accent);
}

.msg-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 2px;
}

.msg-embed {
  margin-top: 4px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(127, 127, 127, 0.10);
}

@media (max-width: 720px) {
  .topbar-tools {
    width: 100%;
  }

  .search {
    width: 100%;
    max-width: none;
  }
}

/* ---------- live tickets ---------- */

.ticket-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  padding: 14px;
}

.ticket-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.ticket-card:hover,
.ticket-card:focus-visible {
  border-color: var(--accent);
  transform: translateY(-1px);
}

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

.ticket-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}

.ticket-card-foot {
  font-size: 12px;
}

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  /* Bounded so the composer stays reachable without scrolling the page. */
  height: min(52vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-msg {
  border-left: 2px solid var(--border);
  padding: 2px 0 2px 10px;
}

.chat-msg.is-bot {
  border-left-color: var(--accent);
}

.chat-msg-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 2px;
}

.chat-compose {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.chat-input {
  width: 100%;
  resize: vertical;
  min-height: 62px;
  font: inherit;
}

.chat-send {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.hidden-file {
  display: none;
}

.nav-toggle {
  display: none;
}

/* ---------- phone ---------- */

@media (max-width: 860px) {
  /* The sidebar becomes a drawer: eleven nav entries wrapped across the top
     pushed the actual work off the first screen. */
  .nav-toggle {
    display: inline-flex;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 60;
    background: var(--surface);
    border: 1px solid var(--border);
  }

  .sidebar {
    display: none;
    padding-top: 58px;
  }

  body.nav-open .sidebar {
    display: flex;
  }

  .nav {
    flex-direction: column;
  }

  .content {
    padding-top: 58px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-tools {
    width: 100%;
  }

  .search-box {
    width: 100%;
    max-width: none;
  }

  .search-results {
    right: 16px;
    width: calc(100vw - 32px);
  }

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

  .chat-log {
    /* Leaves room for the on-screen keyboard while replying. */
    height: min(46vh, 420px);
  }

  .chat-send .btn {
    flex: 1;
  }

  /* Tables do not fit a phone; each row becomes a stacked block. */
  .card table,
  .card thead,
  .card tbody,
  .card tr,
  .card td {
    display: block;
    width: 100%;
  }

  .card thead {
    display: none;
  }

  .card tr {
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
  }

  .card td {
    border: 0;
    padding: 3px 14px;
  }

  .row-actions {
    justify-content: flex-start;
  }
}
