/* TG-PubBot - Dark Tech Theme */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-hover: #21262d;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-orange: #d29922;
  --accent-red: #f85149;
  --accent-purple: #bc8cff;
  --accent-cyan: #39d353;
  --gradient-blue: linear-gradient(135deg, #1a3a5c, #0d2137);
  --gradient-green: linear-gradient(135deg, #1a3a2a, #0d2118);
  --gradient-orange: linear-gradient(135deg, #3a2a1a, #211808);
  --gradient-purple: linear-gradient(135deg, #2a1a3a, #180d21);
  --sidebar-width: 230px;
  --topbar-height: 60px;
  --radius: 8px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

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

/* ===== Layout ===== */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.logo-icon { font-size: 22px; }
.logo-text { font-size: 18px; font-weight: 700; color: var(--accent-blue); letter-spacing: 0.5px; }

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: var(--text-secondary);
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--bg-hover);
  color: var(--accent-blue);
  border-left-color: var(--accent-blue);
}

.nav-item i { width: 18px; text-align: center; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.role-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-hover);
  color: var(--text-muted);
}

.role-badge.admin { background: rgba(88, 166, 255, 0.2); color: var(--accent-blue); }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-hover);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 13px;
  transition: all 0.2s;
  border: 1px solid var(--border);
}

.logout-btn:hover { color: var(--accent-red); text-decoration: none; border-color: var(--accent-red); }

/* ===== Main content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.page-title { font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 16px; color: var(--text-muted); font-size: 13px; }

.content { flex: 1; overflow-y: auto; padding: 24px; min-height: 0; -webkit-overflow-scrolling: touch; }

/* ===== Flash messages ===== */
.flash-container { margin-bottom: 16px; }

.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  border-left: 4px solid;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.flash-success { background: rgba(63, 185, 80, 0.1); border-color: var(--accent-green); color: var(--accent-green); }
.flash-danger { background: rgba(248, 81, 73, 0.1); border-color: var(--accent-red); color: var(--accent-red); }
.flash-warning { background: rgba(210, 153, 34, 0.1); border-color: var(--accent-orange); color: var(--accent-orange); }
.flash-info { background: rgba(88, 166, 255, 0.1); border-color: var(--accent-blue); color: var(--accent-blue); }

.flash-close { background: none; border: none; cursor: pointer; font-size: 18px; line-height: 1; color: inherit; margin-left: 8px; }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.card-header h3, .card-header h4 { margin: 0; font-size: 15px; font-weight: 600; }
.card-header-actions { display: flex; align-items: center; gap: 8px; }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }

.guide-page .card { margin-bottom: 20px; }
.guide-hero .card-body { display: grid; gap: 14px; }
.guide-lead { font-size: 15px; line-height: 1.7; margin: 0; }
.guide-feature-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.guide-feature-list span {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(88, 166, 255, 0.28);
  background: rgba(88, 166, 255, 0.08);
  color: var(--text-primary);
  font-size: 13px;
}
.guide-section .card-body { display: grid; gap: 14px; }
.guide-section h4 { margin: 0; }
.guide-note { margin: 0; }
.guide-table { margin-bottom: 0; }

/* ===== Stats grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat-card {
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(88,166,255,0.3), transparent);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.gradient-blue { background: var(--gradient-blue); }
.gradient-green { background: var(--gradient-green); }
.gradient-orange { background: var(--gradient-orange); }
.gradient-purple { background: var(--gradient-purple); }

.stat-icon { font-size: 28px; opacity: 0.8; }
.gradient-blue .stat-icon { color: var(--accent-blue); }
.gradient-green .stat-icon { color: var(--accent-green); }
.gradient-orange .stat-icon { color: var(--accent-orange); }
.gradient-purple .stat-icon { color: var(--accent-purple); }

.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-total { font-size: 16px; color: var(--text-muted); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== Tables ===== */
.table-responsive { overflow-x: auto; }

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

.table th {
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table-hover tbody tr:hover { background: var(--bg-hover); }
.table-sm th, .table-sm td { padding: 7px 12px; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-success { background: rgba(63, 185, 80, 0.2); color: var(--accent-green); }
.badge-danger { background: rgba(248, 81, 73, 0.2); color: var(--accent-red); }
.badge-warning { background: rgba(210, 153, 34, 0.2); color: var(--accent-orange); }
.badge-info, .badge-primary { background: rgba(88, 166, 255, 0.2); color: var(--accent-blue); }
.badge-secondary { background: var(--bg-hover); color: var(--text-muted); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-primary:hover { background: #79b8ff; color: #fff; }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text-primary); }
.btn-success { background: var(--accent-green); color: #fff; }
.btn-success:hover { background: #56d364; color: #fff; }
.btn-danger { background: rgba(248, 81, 73, 0.2); color: var(--accent-red); border-color: var(--accent-red); }
.btn-danger:hover { background: var(--accent-red); color: #fff; }
.btn-warning { background: rgba(210, 153, 34, 0.2); color: var(--accent-orange); border-color: var(--accent-orange); }
.btn-info { background: rgba(88, 166, 255, 0.2); color: var(--accent-blue); border-color: var(--accent-blue); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-block { width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 4px; flex-wrap: wrap; }
.btn-group-row { display: flex; gap: 8px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 5px; font-size: 13px; color: var(--text-secondary); }

.form-control {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color 0.2s;
  outline: none;
}

.form-control:focus { border-color: var(--accent-blue); }
.form-control::placeholder { color: var(--text-muted); }

select.form-control option { background: var(--bg-secondary); }

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

.form-control-sm { padding: 5px 10px; font-size: 12px; }
.form-check label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ===== Upload area ===== */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--accent-blue);
  background: rgba(88, 166, 255, 0.05);
  color: var(--accent-blue);
}

.upload-area p { margin: 8px 0; }

/* ===== Progress bar ===== */
.progress-bar-wrap {
  width: 80px;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  margin-right: 4px;
}

.progress-bar {
  height: 100%;
  background: var(--accent-blue);
  border-radius: 3px;
  transition: width 0.3s;
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state i { display: block; margin-bottom: 12px; }
.empty-state p { margin-top: 8px; }

/* ===== Quick actions ===== */
.quick-actions { display: flex; flex-wrap: wrap; gap: 12px; }

.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 20px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: all 0.2s;
  min-width: 90px;
}

.quick-btn:hover {
  background: rgba(88, 166, 255, 0.1);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  text-decoration: none;
}

.quick-btn i { font-size: 22px; }
.quick-btn span { font-size: 12px; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

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

.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: auto;
  z-index: 1001;
}

.modal-lg { max-width: 800px; }

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

.modal-header h4 { margin: 0; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 18px; }

/* ===== Log lines ===== */
.log-line { margin-bottom: 2px; }
.log-info { color: var(--text-secondary); }
.log-success { color: var(--accent-green); }
.log-warning { color: var(--accent-orange); }
.log-error { color: var(--accent-red); }

/* ===== Auth pages ===== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo .logo-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.auth-logo h1 { font-size: 24px; font-weight: 700; color: var(--accent-blue); margin-bottom: 4px; }
.auth-logo p { color: var(--text-muted); font-size: 14px; }

.auth-links {
  text-align: center;
  margin-top: 20px;
  display: flex;
  justify-content: space-around;
  font-size: 13px;
}

/* ===== Tool descriptions ===== */
.tool-desc div { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.tool-desc div:last-child { border-bottom: none; }

/* ===== Command list ===== */
.cmd-list .cmd-item { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.cmd-list .cmd-item:last-child { border-bottom: none; }
.cmd-list code { background: var(--bg-hover); padding: 2px 6px; border-radius: 4px; }

/* ===== Help list ===== */
.help-list { padding-left: 20px; color: var(--text-secondary); }
.help-list li { padding: 4px 0; font-size: 13px; }

/* ===== Row layout ===== */
.row { display: flex; flex-wrap: wrap; gap: 16px; }
.col-md-3 { flex: 0 0 calc(25% - 12px); min-width: 200px; }
.col-md-4 { flex: 0 0 calc(33.333% - 12px); min-width: 260px; }
.col-md-5 { flex: 0 0 calc(41.667% - 12px); min-width: 300px; }
.col-md-6 { flex: 0 0 calc(50% - 8px); min-width: 240px; }
.col-md-7 { flex: 0 0 calc(58.333% - 12px); min-width: 300px; }
.col-md-8 { flex: 0 0 calc(66.667% - 12px); min-width: 300px; }

/* ===== Utilities ===== */
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-success { color: var(--accent-green); }
.text-danger { color: var(--accent-red); }
.text-info { color: var(--accent-blue); }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  color: var(--accent-cyan);
}

pre {
  background: var(--bg-primary);
  padding: 14px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: monospace;
  line-height: 1.6;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .logo-text, .nav-item span, .sidebar-footer .user-info span, .role-badge { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8 { flex: 0 0 100%; min-width: 0; }
  .dm-account-list { max-height: none; overflow-y: visible; }
  .tab-link { padding: 6px 12px; font-size: 13px; }
  .content { padding: 16px; }
}

/* ===== Admin nav ===== */
.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 12px;
}
.nav-admin {
  color: #ffd700 !important;
}
.nav-admin:hover, .nav-admin.active {
  background: rgba(255, 215, 0, 0.1) !important;
  color: #ffd700 !important;
}
.nav-admin i {
  color: #ffd700;
}

/* ===== Badge extras ===== */
.badge-orange { background: rgba(251,140,0,0.2); color: #fb8c00; }
.badge-purple { background: rgba(171,71,188,0.2); color: #ab47bc; }

/* ===== Pagination ===== */
.pagination {
  border-top: 1px solid var(--border);
}

/* ===== Log levels ===== */
.log-info { color: var(--text-secondary); }
.log-success { color: var(--accent-green); }
.log-warning { color: var(--accent-orange); }
.log-error { color: var(--accent-red); }

/* ===== Tool page tabs ===== */
.nav-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
  margin-bottom: 0;
  list-style: none;
  padding-left: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-tabs li { margin: 0; flex-shrink: 0; }
.tab-link {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 6px 6px 0 0;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  text-decoration: none;
  border: 1px solid var(--border);
  border-bottom: none;
  font-size: 14px;
  transition: background 0.2s;
  white-space: nowrap;
}
.tab-link:hover { background: var(--bg-primary); color: var(--text-primary); }
.tab-link.active { background: var(--bg-primary); color: var(--accent-blue); font-weight: 600; border-bottom: 1px solid var(--bg-primary); }
.tab-pane { display: block; }

/* ===== DM broadcast account checkbox list ===== */
.dm-account-list {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  background: var(--bg-primary);
}
.dm-account-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  margin: 0;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.dm-account-item:hover { background: var(--bg-secondary); }
.dm-account-item.is-checked {
  background: rgba(39, 174, 96, 0.12);
  border-left-color: var(--accent-green);
}
.dm-account-item input[type="checkbox"] {
  accent-color: var(--accent-green);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ===== Proxy status in accounts table ===== */
.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  padding: 1px 5px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}
.btn-outline-danger:hover { background: rgba(239,68,68,0.15); }
.ml-1 { margin-left: 4px; }

/* ===== DM Broadcast Tab (Private Mass Send) ===== */
.tool-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 7px;
  display: block;
}

/* Type selection chips */
.dm-type-grid {
  margin-top: 4px;
}
.dm-type-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.dm-type-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
.dm-type-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 13px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}
.dm-type-chip:hover {
  border-color: var(--accent-blue);
  background: rgba(56,139,253,.06);
}
.dm-type-chip.sel {
  border-color: var(--accent-blue);
  background: rgba(56,139,253,.12);
}
.dm-tc-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.dm-type-chip.sel .dm-tc-label { color: #58a6ff; }
.dm-tc-desc {
  font-size: 10px;
  color: var(--text-secondary);
}

/* File upload label */
.dm-file-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: rgba(56,139,253,.08);
  border: 1px dashed rgba(56,139,253,.35);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #58a6ff;
  transition: background 0.15s;
}
.dm-file-label:hover { background: rgba(56,139,253,.15); }
