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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222535;
  --border: #2e3247;
  --accent: #6c63ff;
  --accent-hover: #574fd6;
  --text: #e2e4f0;
  --muted: #7b809a;
  --success: #4caf82;
  --error: #e05c6d;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 16px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 32px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 440px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 28px;
}

.tab-btn {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
}

/* Form */
.form-panel { display: none; }
.form-panel.active { display: block; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus {
  border-color: var(--accent);
}

select option { background: var(--surface2); }

.btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  margin-top: 4px;
}

.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Alert */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: none;
}

.alert.error { background: rgba(224,92,109,0.12); border: 1px solid var(--error); color: var(--error); }
.alert.success { background: rgba(76,175,130,0.12); border: 1px solid var(--success); color: var(--success); }
.alert.show { display: block; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ── Profile card ── */
#profile-section { display: none; width: 100%; max-width: 560px; }

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

.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.profile-name { font-size: 1.2rem; font-weight: 700; }
.profile-email { color: var(--muted); font-size: 0.875rem; margin-top: 2px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
}

.badge.admin { background: rgba(239,68,68,0.15); color: #ef4444; }
.badge.publisher { background: rgba(234,179,8,0.15); color: #d97706; }
.badge.client { background: rgba(108,99,255,0.15); color: #a78bfa; }

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.profile-grid.full { grid-template-columns: 1fr; }

.info-item { display: flex; flex-direction: column; gap: 4px; }
.info-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.info-value { font-size: 0.9rem; word-break: break-all; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--error); }

.token-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
  font-family: monospace;
  max-height: 64px;
  overflow: auto;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin: 20px 0 12px;
}

.logout-btn {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  cursor: pointer;
  margin-top: 24px;
  transition: border-color 0.2s, color 0.2s;
}

.logout-btn:hover { border-color: var(--error); color: var(--error); }

/* ── System Status ── */
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.status-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-actions {
  display: flex;
  gap: 8px;
}

.mini-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.8rem;
}

.mini-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface);
}

.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.show { display: flex; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

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

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

/* ── Channels panel ── */
.channels-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.channels-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.channels-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.channel-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.channel-item:hover {
  border-color: var(--accent);
}

.channel-item.selected {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.12);
}

.channel-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.channel-slug {
  font-size: 0.78rem;
  color: var(--muted);
}

.channel-meta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.contents-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.content-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.content-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.content-meta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.content-preview {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  max-width: 360px;
}

.content-preview img,
.content-preview video,
.content-preview audio {
  display: block;
  width: 100%;
  background: var(--surface);
}

.content-preview video {
  max-height: 240px;
}

.content-preview-audio {
  padding: 8px;
}

.content-preview-fallback {
  display: none;
  margin: 8px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: rgba(224, 92, 109, 0.08);
  color: #ffb3bf;
  font-size: 0.78rem;
}

.content-preview-link {
  display: inline-block;
  margin-top: 8px;
  color: #7bb4ff;
  text-decoration: none;
  font-size: 0.8rem;
}

.content-preview-link:hover {
  text-decoration: underline;
}

.content-preview-meta {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 0.75rem;
  color: var(--muted);
}

.content-preview-meta span b {
  color: var(--text);
}

/* ── Profile nav ── */
.profile-nav {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 24px;
}

.profile-nav-btn {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.profile-nav-btn.active {
  background: var(--accent);
  color: #fff;
}

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

.edit-alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: none;
}

.edit-alert.error  { background: rgba(224,92,109,0.12); border: 1px solid var(--error);   color: var(--error); }
.edit-alert.success{ background: rgba(76,175,130,0.12);  border: 1px solid var(--success); color: var(--success); }
.edit-alert.show   { display: block; }

.me-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 4px;
  transition: border-color 0.2s, color 0.2s;
}

.me-btn:hover { border-color: var(--accent); color: var(--accent); }

.raw-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

details summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
  user-select: none;
  margin-bottom: 8px;
}

pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 0.78rem;
  overflow: auto;
  max-height: 240px;
  color: #a8b0cc;
  line-height: 1.5;
}

/* ── JWT config ── */
.jwt-panel {
  width: 100%;
  max-width: 440px;
  margin-bottom: 16px;
}

.jwt-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.jwt-toggle:hover { border-color: var(--accent); color: var(--text); }
.jwt-toggle[aria-expanded="true"] { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-color: var(--accent); color: var(--text); }

.jwt-toggle .chevron { transition: transform 0.2s; }
.jwt-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.jwt-body {
  display: none;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-top: none;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  padding: 20px;
}

.jwt-body.open { display: block; }

.jwt-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  margin-top: 12px;
  color: var(--muted);
}

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

.jwt-status.ok .dot { background: var(--success); }
.jwt-status.ok { color: var(--success); }

.jwt-preview {
  margin-top: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.72rem;
  font-family: monospace;
  color: var(--muted);
  word-break: break-all;
  max-height: 52px;
  overflow: auto;
  display: none;
}
