:root {
  --bg: #0a0e17;
  --surface: #121826;
  --surface2: #1a2132;
  --border: #232b3d;
  --accent: #4d9fff;
  --accent2: #3b82f6;
  --green: #34d399;
  --text: #e7ebf4;
  --text-muted: #8b93a7;
  --muted: #8b93a7;
  --success: #34d399;
  --error: #f26d6d;
  --warn: #e5c07b;
  --radius: 12px;
  --font: "Inter", "Segoe UI", system-ui, sans-serif;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(59,130,246,.06), transparent 60%),
    var(--bg);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon {
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
nav { display: flex; gap: 18px; align-items: center; }
nav a { color: var(--text-muted); font-size: 13px; transition: color .2s; }
nav a:hover { color: var(--text); }

/* Layout */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  flex: 1;
  width: 100%;
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 72px;
  align-self: start;
}

.search-box {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
}
.search-box input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}
.search-box button:hover { opacity: .85; }

.filter-group {
  margin-bottom: 20px;
}
.filter-group h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.filter-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  transition: color .15s;
}
.filter-group label:hover { color: var(--text); }
.filter-group input[type=radio]:checked + label,
.filter-group label:has(input:checked) { color: var(--accent); }

/* Content */
.content-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.content-header h2 {
  font-size: 18px;
  font-weight: 600;
}
.count {
  background: var(--surface2);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
  margin-left: 10px;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .2s, transform .15s;
  color: var(--text);
}
.card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.card-thumb {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface2);
  overflow: hidden;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-muted);
  background: linear-gradient(135deg, var(--surface2) 0%, #1e2235 100%);
}
.thumb-placeholder.large { font-size: 52px; }

.badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: .05em;
}
.badge-stl  { background: #1a4a8a; color: #7fb3ff; }
.badge-3mf  { background: #2a3a1a; color: #a3d46e; }
.badge-obj  { background: #3a2a1a; color: #f0b46e; }
.badge-zip  { background: #2a1a3a; color: #c46ef0; }
.badge-rar  { background: #3a1a24; color: #f06e9c; }
.badge-7z   { background: #1a2a3a; color: #6ec4f0; }

.status-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.status-dot.status-processed { background: var(--success); }
.status-dot.status-pending   { background: var(--warn); }
.status-dot.status-error     { background: var(--error); }
.status-dot.status-processing { background: var(--accent); animation: pulse 1s infinite; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.drive-badge {
  position: absolute;
  top: 6px;
  right: 24px;
  font-size: 15px;
  line-height: 1;
  color: var(--success);
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.drive-badge.pending { color: var(--warn); animation: pulse 1.2s infinite; }

/* Accordion category / subcategory filter */
.cat-all {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text, #ddd);
  text-decoration: none;
  font-size: 14px;
}
.cat-all:hover { background: rgba(255,255,255,.06); }
.cat-all.active { background: var(--accent, #3b82f6); color: #fff; font-weight: 600; }

.cat-block { margin: 1px 0; }
.cat-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: var(--text, #ddd);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
}
.cat-toggle:hover { background: rgba(255,255,255,.06); }
.cat-toggle.active { color: #fff; font-weight: 600; }
.cat-toggle .cat-name { flex: 1; }
.caret { display: inline-block; transition: transform .15s; opacity: .7; font-size: 11px; }
.cat-block.open .caret { transform: rotate(90deg); }

.subcat-list {
  display: none;
  margin: 2px 0 6px 12px;
  padding-left: 8px;
  border-left: 1px solid rgba(255,255,255,.12);
}
.cat-block.open .subcat-list { display: block; }
.subcat-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--muted, #9aa);
  text-decoration: none;
  font-size: 13px;
}
.subcat-link:hover { background: rgba(255,255,255,.06); color: var(--text, #ddd); }
.subcat-link.active { background: var(--accent, #3b82f6); color: #fff; font-weight: 600; }
.cat-count {
  font-size: 11px;
  opacity: .6;
  background: rgba(255,255,255,.08);
  padding: 1px 6px;
  border-radius: 10px;
}

/* Nav user + auth pages */
.nav-user { color: var(--muted, #9aa); font-size: 14px; margin-left: 8px; }
.admin-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  background: var(--accent, #3b82f6); color: #fff; padding: 1px 6px; border-radius: 8px;
}
.auth-wrap { display: flex; justify-content: center; align-items: flex-start; padding: 56px 16px; }
.auth-card {
  position: relative;
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.015));
  border: 1px solid var(--border);
  border-radius: 16px; padding: 30px 28px 26px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.6);
  overflow: hidden;
}
.auth-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--green));
}
.auth-brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.auth-brand .logo-icon {
  font-size: 24px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-brand b { font-size: 17px; letter-spacing: .01em; }
.auth-card h1 { margin: 2px 0 0; font-size: 20px; font-weight: 700; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin: -6px 0 6px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.auth-card input {
  padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.28); color: var(--text); font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.auth-card input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,159,255,.15);
}
.auth-error {
  background: rgba(242,109,109,.12); border: 1px solid rgba(242,109,109,.4);
  color: #ff9b8f; padding: 9px 12px; border-radius: 10px; font-size: 13px;
}
.auth-alt { text-align: center; font-size: 13px; color: var(--text-muted); margin: 6px 0 0; }
.btn-block { display: block; width: 100%; text-align: center; padding: 11px; font-size: 14px; margin-top: 4px; }

/* Sources (monitored chats) page */
.sources-wrap { max-width: 820px; margin: 0 auto; }
.sources-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.sources-head h1 { font-size: 22px; margin-bottom: 4px; }
.sources-bulk { display: flex; gap: 8px; }
.sources-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.source-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
}
.source-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.source-title { font-size: 14px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-id { font-size: 11px; color: var(--text-muted); font-family: monospace; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 24px; transition: background .2s;
}
.slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 2px; top: 2px;
  background: #cfd6e6; border-radius: 50%; transition: transform .2s, background .2s;
}
.switch input:checked + .slider { background: linear-gradient(135deg, var(--accent), var(--green)); border-color: transparent; }
.switch input:checked + .slider::before { transform: translateX(20px); background: #fff; }
.switch input:disabled + .slider { opacity: .5; }

/* Photo gallery on detail page */
.photo-strip {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.photo-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  opacity: .7;
  transition: opacity .15s, border-color .15s;
}
.photo-thumb:hover { opacity: 1; }
.photo-thumb.active { border-color: var(--accent); opacity: 1; }

.btn-danger { background: var(--error, #c0392b); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.card-body { padding: 10px 12px 12px; flex: 1; }
.card-body h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.category { font-size: 11px; color: var(--accent); margin-bottom: 2px; }
.source { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }

.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--text-muted);
  transition: color .15s, border-color .15s;
}
a.tag:hover { color: var(--accent); border-color: var(--accent); }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 32px;
  padding: 12px;
}
.pagination a {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  color: var(--text);
  transition: border-color .2s;
}
.pagination a:hover { border-color: var(--accent); }
.pagination span { color: var(--text-muted); font-size: 13px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 8px; }
.empty-state .hint { font-size: 13px; }

/* Detail page */
.detail-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 32px;
  align-items: start;
}

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--text-muted);
  font-size: 13px;
}
.back-link:hover { color: var(--text); }

.detail-thumb {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  aspect-ratio: 1;
}
.detail-thumb img { width: 100%; height: 100%; object-fit: contain; }

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .2s;
}
.btn:hover { opacity: .9; filter: brightness(1.05); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 6px 16px -8px rgba(77,159,255,.7); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

.detail-header { margin-bottom: 24px; }
.detail-header h1 { font-size: 24px; margin-bottom: 10px; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.status-pill, .category-pill {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.status-pill.status-processed { background: #0f3a28; color: var(--success); }
.status-pill.status-pending   { background: #3a2e0f; color: var(--warn); }
.status-pill.status-error     { background: #3a1212; color: var(--error); }
.status-pill.status-processing { background: #0f1e3a; color: var(--accent); }
.category-pill { background: var(--surface2); color: var(--text-muted); }

.section { margin-bottom: 28px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: 10px; }
.section p { color: var(--text); line-height: 1.6; }

.info-table { width: 100%; border-collapse: collapse; }
.info-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.info-table td:first-child { color: var(--text-muted); width: 40%; }
code { background: var(--surface2); border-radius: 4px; padding: 1px 5px; font-size: 12px; }

.error-box { background: #1e0a0a; border: 1px solid #5a1e1e; border-radius: var(--radius); padding: 16px; }
.error-box pre { color: var(--error); font-size: 12px; white-space: pre-wrap; }

.admin-box {
  margin-top: 16px;
  padding: 12px;
  background: #1a1200;
  border: 1px solid #3a2e00;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #a07800;
  background: #2a2000;
  padding: 2px 7px;
  border-radius: 4px;
}
.btn-telegram {
  background: #2a6ca8;
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .2s;
}
.btn-telegram:hover { opacity: .85; color: white; }

footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .detail-layout { grid-template-columns: 1fr; }
}

/* ── Varredura de histórico ────────────────────────────────────────────── */

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.scan-panel {
  margin-top: 36px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.scan-panel h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.scan-panel .auth-sub {
  margin-bottom: 18px;
  max-width: 62ch;
}

.scan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.scan-table td {
  padding: 11px 12px 11px 0;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.scan-table tr:first-child td {
  border-top: none;
}

.scan-chat {
  font-weight: 600;
  max-width: 230px;
}

.scan-nums {
  color: var(--text-muted);
  white-space: nowrap;
}

.scan-nums strong {
  color: var(--green);
}

.scan-msg {
  color: var(--text-muted);
  font-size: 0.82rem;
  max-width: 280px;
}

.scan-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: lowercase;
  border: 1px solid transparent;
}

.scan-badge.running,
.scan-badge.pending {
  color: var(--accent);
  background: rgba(77, 159, 255, 0.12);
  border-color: rgba(77, 159, 255, 0.3);
}

.scan-badge.running {
  animation: scan-pulse 1.6s ease-in-out infinite;
}

.scan-badge.paused {
  color: var(--warn);
  background: rgba(229, 192, 123, 0.12);
  border-color: rgba(229, 192, 123, 0.3);
}

.scan-badge.done {
  color: var(--green);
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.3);
}

.scan-badge.error,
.scan-badge.canceled {
  color: var(--error);
  background: rgba(242, 109, 109, 0.12);
  border-color: rgba(242, 109, 109, 0.3);
}

@keyframes scan-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

@media (max-width: 720px) {
  .scan-table, .scan-table tbody, .scan-table tr, .scan-table td {
    display: block;
    width: 100%;
  }
  .scan-table td { padding: 4px 0; border-top: none; }
  .scan-table tr { padding: 12px 0; border-top: 1px solid var(--border); }
  .scan-chat { max-width: none; }
}
