:root {
  --bg: #0f1419;
  --panel: #171d25;
  --line: #2a3441;
  --text: #e7eef7;
  --muted: #93a1b3;
  --accent: #3dd6c6;
  --accent-2: #f0b429;
  --danger: #ff6b6b;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 10% -10%, #1d3a3a 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #3a2d14 0%, transparent 45%),
    var(--bg);
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.header h1 {
  margin: 0 0 6px;
  font-size: 1.8rem;
  letter-spacing: -0.02em;
}
.header p {
  margin: 0;
  color: var(--muted);
  max-width: 70ch;
}
.site-blurb {
  margin-top: 4px !important;
  margin-bottom: 14px !important;
  line-height: 1.45;
}

.stats-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(160px, 0.8fr);
  gap: 12px;
  max-width: 720px;
}
.stat-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(61,214,198,0.08), rgba(255,255,255,0.02));
}
.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  word-break: break-word;
}
.stat-value.accent {
  font-size: 2rem;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.badge {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}
.badge.running { color: var(--accent-2); border-color: #6a5418; }
.badge.finished { color: var(--accent); border-color: #1f6a61; }
.badge.error { color: var(--danger); border-color: #7a3030; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.tab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}
.tab.active {
  color: var(--text);
  border-color: #3b8f86;
  background: linear-gradient(180deg, rgba(61,214,198,0.14), rgba(61,214,198,0.04));
}

.panel {
  display: none;
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel.active { display: block; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.files-toolbar { align-items: center; }
input[type="text"] {
  flex: 1;
  min-width: 220px;
  background: #0c1117;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
}
.btn {
  border: 1px solid var(--line);
  background: #222a35;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary {
  background: linear-gradient(180deg, #2bb9ab, #1e8f84);
  border-color: #1e8f84;
  color: #041311;
  font-weight: 650;
}
.btn.danger {
  background: transparent;
  border-color: #7a3030;
  color: #ffb4b4;
}
.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.sort-btn #sortArrow {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 700;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
}

.hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.log-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0c1117;
  overflow: hidden;
}
.log-title {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.log-list {
  max-height: 320px;
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}
.log-empty { padding: 12px; }
.log-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.025);
  border: 1px solid transparent;
  font-size: 0.98rem;
  line-height: 1.4;
}
.log-item .t {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.86rem;
  padding-top: 2px;
}
.log-item .m { color: var(--text); font-weight: 500; }
.log-item.start, .log-item.info, .log-item.search { border-color: rgba(147,161,179,0.2); }
.log-item.download, .log-item.prepare, .log-item.analyze {
  border-color: rgba(240,180,41,0.28);
  background: rgba(240,180,41,0.06);
}
.log-item.ok, .log-item.done {
  border-color: rgba(61,214,198,0.3);
  background: rgba(61,214,198,0.07);
}
.log-item.error {
  border-color: rgba(255,107,107,0.35);
  background: rgba(255,107,107,0.08);
}
.log-item.warn, .log-item.skip {
  border-color: rgba(240,180,41,0.2);
}

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

.url-block { display: grid; gap: 10px; margin-bottom: 10px; }
#urlInput {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: inherit;
}
#urlInput:focus {
  outline: none;
  border-color: #3b8f86;
}
.url-actions { justify-content: flex-start; }
.warn-inline { color: #f0b429; }

.url-preview {
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
}

.files-list { display: grid; gap: 10px; }
.empty-files { padding: 12px 4px; }

.app-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
  overflow: hidden;
}
.app-card[open] {
  border-color: #3b8f86;
  background: linear-gradient(180deg, rgba(61,214,198,0.06), rgba(255,255,255,0.02));
}
.app-summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  grid-template-columns: 56px minmax(160px, 1.1fr) minmax(280px, 2fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
}
.app-summary::-webkit-details-marker { display: none; }
.card-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  justify-self: end;
}
.clo-badge {
  min-width: 52px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 750;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
}
.clo-badge.clo-yes {
  color: #041311;
  background: linear-gradient(180deg, #ff8f8f, #e85d5d);
  border-color: #c44;
}
.clo-badge.clo-no {
  color: #041311;
  background: linear-gradient(180deg, #2bb9ab, #1e8f84);
  border-color: #1e8f84;
}
.clo-badge.clo-unk {
  color: var(--muted);
}
.btn-delete-app {
  padding: 7px 12px;
  font-size: 0.86rem;
  white-space: nowrap;
}
.app-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  background: #0c1117;
  border: 1px solid var(--line);
}
.app-icon.placeholder {
  background: linear-gradient(135deg, rgba(61,214,198,0.2), rgba(240,180,41,0.12));
}
.app-title { font-weight: 650; margin-bottom: 4px; }
.app-pkg { font-size: 0.88rem; }
.pkg-link, .report-link {
  color: var(--accent);
  text-decoration: none;
}
.pkg-link:hover, .report-link:hover { text-decoration: underline; }
.app-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  font-size: 0.86rem;
}
.app-meta-grid .lbl {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 2px;
}
.app-files {
  border-top: 1px solid var(--line);
  padding: 12px;
}
.files-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}
.file-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip {
  display: inline-block;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--accent);
  text-decoration: none;
  background: #0c1117;
  font-size: 0.86rem;
}
.file-chip:hover { border-color: #3b8f86; }

.report-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-2);
  font-size: 0.92rem;
}
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(240, 180, 41, 0.25);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 980px) {
  .app-summary { grid-template-columns: 48px 1fr auto; }
  .app-meta-grid {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stats-row { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .header { flex-direction: column; }
  .sort-btn { margin-left: 0; }
}
