:root {
  --bg: #0f0f10;
  --surface: #1a1a1d;
  --surface-2: #242428;
  --border: #2e2e35;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #53fc18;
  --accent-dim: #3db812;
  --danger: #ef4444;
  --radius: 12px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- Header --- */

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

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: #000;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: -0.02em;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.subtitle { color: var(--muted); font-size: 0.9rem; }

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.admin-header-btn {
  border-color: var(--border);
  color: var(--muted);
}

.admin-header-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* --- Admin drawer --- */

body.admin-open { overflow: hidden; }

.admin-drawer {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  justify-content: flex-end;
}

.admin-drawer.hidden { display: none; }

.admin-drawer-inner {
  width: min(480px, 100%);
  height: 100%;
  overflow-y: auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.admin-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.admin-drawer-header h2 {
  margin-bottom: 0.25rem;
}

.admin-warning {
  color: #fde68a;
  font-size: 0.82rem;
}

.admin-auth-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.admin-section h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.admin-hint {
  margin-top: 0.5rem;
  margin-bottom: 0;
}

.admin-sensitive-row {
  align-items: flex-start;
}

.admin-sensitive {
  color: #fde68a;
  font-size: 0.78rem;
  word-break: break-all;
  text-align: right;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* --- Status bar (top right) --- */

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.status-pill.ok { border-color: #166534; color: #bbf7d0; }
.status-pill.warn { border-color: #713f12; color: #fde68a; }
.status-pill.err { border-color: #7f1d1d; color: #fecaca; }
.status-pill.neutral { color: var(--muted); }

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

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

.icon-btn-sm {
  width: 28px;
  height: 28px;
  font-size: 1.1rem;
  line-height: 1;
}

/* --- Home panel --- */

.home-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.home-connected {
  font-size: 0.95rem;
  color: var(--muted);
}

.home-connected strong {
  color: var(--accent);
  font-weight: 700;
}

.home-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.home-stream-info {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem 1rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.home-stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.home-stat-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.home-stat-value {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Join layout (3 columns) --- */

.join-layout-panel {
  padding: 0;
  background: transparent;
  border: none;
}

.join-layout {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(280px, 1.3fr) minmax(220px, 1fr);
  gap: 1rem;
  min-height: 560px;
}

.join-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem;
}

.join-col-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
}

.join-settings-hint {
  margin-top: auto;
  padding-top: 0.75rem;
}

.block-btn {
  width: 100%;
}

.participants-list {
  flex: 1;
  min-height: 320px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.participants-list.empty {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.participants-empty {
  text-align: center;
}

.participant-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.participant-row:last-child {
  border-bottom: none;
}

.participant-remove {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}

.participant-remove:hover {
  color: #fecaca;
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
}

.winners-list {
  flex: 1;
  min-height: 280px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
}

.winners-list.empty {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.winners-empty {
  text-align: center;
}

.winner-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.winner-item:last-child {
  border-bottom: none;
}

.winner-name {
  font-weight: 600;
  color: var(--accent);
}

.winner-time {
  font-size: 0.78rem;
  color: var(--muted);
}

.giveaway-message-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.join-reset-btn {
  margin-top: 0.75rem;
}

.participant-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.participant-item:last-child {
  border-bottom: none;
}

.participant-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.participant-item.selected {
  background: rgba(83, 252, 24, 0.08);
  box-shadow: inset 3px 0 0 var(--accent);
}

.participant-name {
  font-weight: 600;
}

.participant-time {
  font-size: 0.78rem;
  color: var(--muted);
  flex-shrink: 0;
}

.selected-participant {
  flex: 1;
  min-height: 120px;
  margin-bottom: 0.75rem;
}

.selected-participant-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.selected-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.selected-time {
  font-size: 0.8rem;
  color: var(--muted);
}

/* --- Broadcast bar --- */

.broadcast-bar {
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
}

.broadcast-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.broadcast-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.broadcast-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.broadcast-value {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-badge {
  display: inline-block;
  background: #dc2626;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

/* --- Tabs --- */

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.65rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panels { display: block; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-save { margin-top: 1rem; }

/* --- Cards & forms --- */

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

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.log-hint { margin-bottom: 0; }

code {
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
  text-decoration: none;
  display: inline-block;
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }

.btn:hover { background: var(--border); }
.btn.primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-dim); }
.btn.danger { color: var(--danger); border-color: var(--danger); }

.form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input, textarea, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font: inherit;
}

textarea { resize: vertical; min-height: 80px; }

.toggle {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  color: var(--text) !important;
}

.toggle input { width: auto; }

.inline-form {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: end;
  margin-top: 1rem;
}

.inline-form input, .inline-form select { flex: 1; min-width: 120px; }

/* --- Status list (info panel) --- */

.status-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.status-row span:first-child { color: var(--muted); flex-shrink: 0; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge.ok { background: #166534; color: #bbf7d0; }
.badge.warn { background: #713f12; color: #fde68a; }
.badge.err { background: #7f1d1d; color: #fecaca; }

/* --- Commands & joiners --- */

.command-block {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.command-block:last-child { border-bottom: none; }

.command-block-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.command-block-header strong {
  min-width: 4rem;
  font-size: 0.95rem;
}

.command-reply-field,
.command-join-fields label,
.command-response-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.command-response-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.command-response-label {
  color: var(--text);
  font-weight: 500;
}

.toggle-sm {
  font-size: 0.78rem;
  gap: 0.35rem;
}

.command-response-field.response-disabled .command-response-label {
  color: var(--muted);
}

.command-response-field.response-disabled input[type="text"] {
  opacity: 0.55;
}

.command-join-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: 0.25rem;
}

.command-row {
  display: grid;
  grid-template-columns: 100px 90px 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.joins-list table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.joins-list th, .joins-list td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.joins-list th { color: var(--muted); font-weight: 500; }

/* --- Join session --- */

.join-session-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.join-session-status.open {
  border-color: #166534;
  background: rgba(22, 101, 52, 0.15);
}

.join-session-status.closed {
  color: var(--muted);
}

.join-session-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.join-session-status.open .join-session-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.join-session-timer {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  color: var(--accent);
}

.join-session-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
}

.join-start-form {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.join-form-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.75rem;
}

.join-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.join-announce-label { min-width: 0; }

/* --- Modal --- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-card h3 {
  margin-bottom: 0.5rem;
  font-size: 1.15rem;
}

.modal-card .hint {
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

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

.pin-modal {
  z-index: 250;
}

.pin-card {
  text-align: center;
}

.pin-hint {
  margin-bottom: 1.5rem;
}

.pin-entry {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.pin-digit {
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0;
  -webkit-text-security: disc;
  text-security: disc;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.pin-digit:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(83, 252, 24, 0.15);
  background: var(--bg);
}

.pin-digit.filled {
  border-color: var(--accent-dim);
}

.pin-digit.error {
  border-color: var(--danger);
  animation: pin-digit-shake 0.35s ease;
}

.pin-error {
  min-height: 1.25rem;
  margin-bottom: 0.75rem;
  color: #fca5a5;
  font-size: 0.85rem;
}

.pin-error.hidden {
  visibility: hidden;
}

.pin-actions {
  justify-content: center;
}

.pin-card.pin-shake {
  animation: pin-shake 0.4s ease;
}

@keyframes pin-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes pin-digit-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* --- Alert & misc --- */

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert.ok { background: #14532d; color: #bbf7d0; }
.alert.err { background: #7f1d1d; color: #fecaca; }
.alert.hidden { display: none; }

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

.mono {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  word-break: break-all;
  text-align: right;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.activity-log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 480px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}

.log-entry {
  padding: 0.35rem 0.65rem;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 72px 72px 1fr;
  gap: 0.5rem;
  align-items: start;
}

.log-entry:last-child { border-bottom: none; }

.log-time { color: var(--muted); }
.log-cat { font-weight: 600; }
.log-cat.AUTH { color: #60a5fa; }
.log-cat.WEBHOOK { color: #a78bfa; }
.log-cat.COMMAND { color: var(--accent); }
.log-cat.CHAT { color: #34d399; }
.log-cat.SCHEDULER { color: #fbbf24; }
.log-cat.CONFIG { color: #f472b6; }
.log-cat.JOIN { color: #fb923c; }
.log-cat.HTTP { color: #94a3b8; }
.log-cat.LISTEN { color: #38bdf8; }

.log-entry.warn .log-msg { color: #fde68a; }
.log-entry.error .log-msg { color: #fca5a5; }

.log-meta {
  grid-column: 3;
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 0.15rem;
}

/* --- Responsive --- */

.test-form {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .join-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .participants-list {
    min-height: 240px;
  }

  .home-stream-info {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 800px) {
  .broadcast-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .status-bar {
    width: 100%;
    justify-content: flex-start;
    margin-top: 0.5rem;
  }

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

@media (max-width: 700px) {
  .command-row { grid-template-columns: 1fr; }
  .log-entry { grid-template-columns: 1fr; }
  .log-meta { grid-column: 1; }

  .broadcast-stats {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 480px) {
  .broadcast-stats {
    grid-template-columns: 1fr;
  }
}

/* --- Login page --- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
}

.login-brand {
  margin-bottom: 1.5rem;
}

.login-submit {
  width: 100%;
  margin-top: 0.5rem;
}
