/* ── Reset & variables ──────────────────────────────────────────────────── */

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

:root {
  --bg:        #0d0e11;
  --surface:   #161719;
  --surface2:  #1e1f23;
  --surface3:  #26272c;
  --border:    #2a2c31;
  --text:      #e1e1e3;
  --muted:     #6b6d72;
  --accent:    #4A154B;
  --accent-h:  #6e2173;
  --accent-l:  #9b59b6;
  --green:     #2bac76;
  --red:       #e01e5a;
  --yellow:    #ecb22e;
  --radius:    8px;
  --sidebar-w: 310px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Views ──────────────────────────────────────────────────────────────── */

.view { min-height: 100vh; }
.hidden { display: none !important; }

/* ── Setup ──────────────────────────────────────────────────────────────── */

#view-setup {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1b0a1c 0%, var(--bg) 60%);
}

.setup-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setup-brand { text-align: center; }

.brand-icon {
  font-size: 40px;
  color: var(--accent-l);
  margin-bottom: 12px;
}

.setup-brand h1 { font-size: 22px; font-weight: 700; color: #fff; }
.setup-brand .brand-sub { font-size: 13px; color: var(--muted); margin-top: 6px; }

.setup-form { display: flex; flex-direction: column; gap: 10px; }

.token-row {
  display: flex;
  gap: 6px;
}

.token-row input { flex: 1; }

.instructions {
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.instructions summary {
  cursor: pointer;
  color: var(--accent-l);
  font-weight: 600;
  user-select: none;
}

.instructions ol {
  margin-top: 12px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1.6;
}

.instructions a { color: var(--accent-l); }
.instructions a:hover { text-decoration: underline; }

.scopes-section {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scopes-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-top: 4px;
}

.scopes-list {
  list-style: none;
  padding-left: 0 !important;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.reinstall-note {
  background: rgba(236, 178, 46, 0.1);
  border-left: 3px solid var(--yellow);
  border-radius: 4px;
  padding: 8px 10px !important;
  color: var(--text) !important;
  line-height: 1.6;
}

.reinstall-note small {
  color: var(--muted);
  font-size: 11px;
}

/* ── App layout ─────────────────────────────────────────────────────────── */

#view-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-top {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.user-name { font-weight: 600; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-team { font-size: 11px; color: var(--muted); }

/* ── Channel area ───────────────────────────────────────────────────────── */

.sidebar-channels {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px 0;
}

.channel-search-wrap { padding: 0 10px 8px; }

.channel-search {
  width: 100%;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}

.channel-search::placeholder { color: var(--muted); }
.channel-search:focus { outline: none; border-color: var(--accent-h); }

.channel-filters {
  display: flex;
  gap: 2px;
  padding: 0 10px 8px;
}

.filter {
  flex: 1;
  padding: 5px 4px;
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  transition: color 0.15s, background 0.15s;
}

.filter:hover { color: var(--text); background: var(--surface2); }
.filter.active { color: #fff; background: var(--accent); border-color: transparent; }

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.channel-list::-webkit-scrollbar { width: 4px; }
.channel-list::-webkit-scrollbar-track { background: transparent; }
.channel-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.list-placeholder { padding: 20px; text-align: center; color: var(--muted); font-size: 13px; }

.channel-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 10px 8px 4px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}

.channel-item:hover { background: var(--surface2); }
.channel-item.selected { background: rgba(110, 33, 115, 0.25); }

.channel-item input[type="checkbox"] {
  accent-color: var(--accent-l);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
}

.channel-icon { font-size: 13px; color: var(--muted); flex-shrink: 0; }
.channel-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.channel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 0;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.selected-count { font-size: 12px; color: var(--muted); }

/* ── Sidebar bottom ─────────────────────────────────────────────────────── */

.sidebar-bottom {
  padding: 12px 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.toggle-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
  padding: 2px 0;
}
.toggle-wrap { flex-shrink: 0; }
.toggle-wrap input[type="checkbox"] { display: none; }
.toggle-track {
  display: flex; align-items: center;
  width: 36px; height: 20px; border-radius: 10px;
  background: var(--surface3); border: 1px solid var(--border);
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-wrap input:checked + .toggle-track { background: var(--accent-h); border-color: var(--accent-h); }
.toggle-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); margin-left: 2px;
  transition: transform 0.2s, background 0.2s;
}
.toggle-wrap input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px); background: #fff;
}

/* ── Main area ──────────────────────────────────────────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Stats bar ──────────────────────────────────────────────────────────── */

.stats-bar {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  background: var(--surface);
  gap: 4px;
}

.stat-num {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.stat-status {
  flex-direction: row;
  gap: 10px;
  justify-content: center;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.running { background: var(--green); animation: blink 1.4s ease-in-out infinite; }
.status-dot.done    { background: var(--green); }
.status-dot.error   { background: var(--red); }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }

/* ── Queue bar ──────────────────────────────────────────────────────────── */

.queue-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.queue-bar::-webkit-scrollbar { display: none; }

.queue-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); flex-shrink: 0; }

.queue-items { display: flex; gap: 6px; align-items: center; }

.queue-chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

.queue-chip.pending  { background: var(--surface3); color: var(--muted); }
.queue-chip.active   { background: var(--accent); color: #fff; }
.queue-chip.done     { background: transparent; color: var(--green); border: 1px solid var(--green); }

/* ── Log ────────────────────────────────────────────────────────────────── */

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  flex-shrink: 0;
}

.log-header h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }

.log-header-actions { display: flex; align-items: center; gap: 14px; }

.toggle-label-inline {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
}
.toggle-label-inline .toggle-track { width: 30px; height: 16px; border-radius: 8px; }
.toggle-label-inline .toggle-thumb { width: 10px; height: 10px; }
.toggle-label-inline input:checked + .toggle-track .toggle-thumb { transform: translateX(14px); }

.log-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.log-container::-webkit-scrollbar { width: 4px; }
.log-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.log-empty { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; }

/* ── Log entries ────────────────────────────────────────────────────────── */

.log-entry {
  display: grid;
  grid-template-columns: 6px 1fr;
  gap: 10px;
  padding: 9px 10px 9px 0;
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.18s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-bar {
  width: 3px;
  border-radius: 3px;
  align-self: stretch;
  min-height: 20px;
  flex-shrink: 0;
}

.log-bar.deleted  { background: var(--green); }
.log-bar.error    { background: var(--red); }
.log-bar.info     { background: var(--border); }

.log-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.log-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.log-time     { font-size: 12px; font-weight: 600; color: #fff; font-variant-numeric: tabular-nums; }
.log-channel  { font-size: 12px; color: var(--accent-l); }
.log-origdate { font-size: 11px; color: var(--muted); }

.log-text {
  font-size: 12px;
  color: var(--text);
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-text.error-text { color: var(--red); opacity: 1; }
.log-text.info-text  { color: var(--muted); font-style: italic; }

#logContainer.no-preview .log-text:not(.error-text):not(.info-text) { display: none; }

/* ── Shared components ──────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.w-full { width: 100%; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }

.btn-slack { background: #fff; color: #1d1c1d; border: 1px solid #ddd; font-weight: 700; }
.btn-slack:hover:not(:disabled) { background: #f8f8f8; }
.btn-slack svg { flex-shrink: 0; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled)  { background: #b21647; }

.icon-btn {
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

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

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px;
  text-decoration: none;
}

.link-btn:hover { color: var(--text); text-decoration: underline; }

/* ── Form elements ──────────────────────────────────────────────────────── */

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="password"]:focus { outline: none; border-color: var(--accent-h); }

input::placeholder { color: var(--muted); }

.field-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); display: block; }

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

.field-error { font-size: 13px; color: var(--red); padding: 8px 12px; background: rgba(224,30,90,.12); border-radius: 6px; border-left: 3px solid var(--red); }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.checkbox-label input { accent-color: var(--accent-l); cursor: pointer; }

code {
  background: var(--surface3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
  font-size: 12px;
  color: var(--accent-l);
}

/* ── Color utilities ────────────────────────────────────────────────────── */

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