:root {
  --bg: #060912;
  --card: rgba(14, 20, 36, 0.94);
  --border: rgba(148, 163, 184, 0.14);
  --border-focus: rgba(56, 189, 248, 0.45);
  --text: #e8eef8;
  --muted: #8b9bb4;
  --accent: #38bdf8;
  --ok: #34d399;
  --input: #080e1a;
  --radius: 14px;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 0% -10%, rgba(14, 165, 233, 0.16), transparent 55%),
    radial-gradient(700px 480px at 100% 0%, rgba(99, 102, 241, 0.12), transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

.shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 0 calc(28px + var(--safe-bottom));
  position: relative;
  z-index: 1;
}

/* Topbar — sticky, always above content */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: rgba(10, 14, 26, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 800; font-size: 1rem;
  background: linear-gradient(135deg, #0ea5e9, #6366f1); color: #fff;
}
.brand h1 { margin: 0; font-size: 1.05rem; font-weight: 800; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.75rem; }
.nav-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-tab {
  height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-weight: 700; font-size: 0.8rem; cursor: pointer;
}
.nav-tab.active {
  color: #fff; border-color: rgba(56, 189, 248, 0.35);
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.25), rgba(99, 102, 241, 0.25));
}
.ver {
  font-family: "JetBrains Mono", monospace; font-size: 0.68rem;
  padding: 5px 9px; border-radius: 999px; border: 1px solid var(--border);
  color: #7dd3fc; background: rgba(56, 189, 248, 0.08);
}

.view { display: none; }
.view.active { display: block; position: relative; z-index: 1; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
input[type="url"], input[type="text"], .filter-input {
  flex: 1; min-width: 0; height: 42px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--input); color: var(--text);
  padding: 0 12px; font-size: 0.88rem; font-family: "JetBrains Mono", monospace; outline: none;
}
input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12); }

.btn {
  height: 42px; border: none; border-radius: 11px; padding: 0 14px;
  font-weight: 700; font-size: 0.84rem; cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #6366f1); color: #fff;
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.28);
}
.btn-ghost {
  background: rgba(148, 163, 184, 0.08); color: var(--text); border: 1px solid var(--border);
}
.btn-mini {
  height: 28px; padding: 0 9px; font-size: 0.7rem; border-radius: 8px;
  background: rgba(148, 163, 184, 0.08); color: var(--text); border: 1px solid var(--border);
}
.btn-block { width: 100%; }

.opt-row {
  display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px;
  color: var(--muted); font-size: 0.8rem;
}
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.chk input { accent-color: #0ea5e9; }

.progress {
  height: 6px; border-radius: 999px; background: rgba(148, 163, 184, 0.12);
  overflow: hidden; margin-top: 12px;
}
.progress > i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #0ea5e9, #818cf8, #34d399);
  transition: width 0.3s ease;
}

.stat-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px;
}
.stat {
  background: rgba(2, 6, 23, 0.45); border: 1px solid var(--border);
  border-radius: 11px; padding: 10px; min-width: 0;
}
.stat .k {
  display: block; color: var(--muted); font-size: 0.65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.stat .v {
  display: block; margin-top: 4px; font-family: "JetBrains Mono", monospace;
  font-weight: 800; font-size: 0.86rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.split {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}
.side-panel, .main-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100vh - 200px);
  overflow: hidden;
}
.side-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 8px; flex-shrink: 0;
}
.mini-actions { display: flex; gap: 6px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; flex-shrink: 0; }
.chip {
  height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 0.7rem; font-weight: 600; cursor: pointer;
}
.chip.active {
  color: #7dd3fc; border-color: rgba(56, 189, 248, 0.35); background: rgba(56, 189, 248, 0.1);
}

.file-list {
  flex: 1 1 auto;
  min-height: 120px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(2, 6, 23, 0.4);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.file-item {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 10px; border-bottom: 1px solid rgba(148, 163, 184, 0.07); cursor: pointer;
}
.file-item:hover, .file-item.active { background: rgba(56, 189, 248, 0.07); }
.file-item .name {
  font-family: "JetBrains Mono", monospace; font-size: 0.72rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-item .tag { font-size: 0.64rem; color: var(--muted); text-transform: uppercase; }
.side-foot { display: grid; gap: 8px; margin-top: 10px; flex-shrink: 0; }

.viewer-tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-shrink: 0; }
.tab {
  height: 32px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-weight: 700; font-size: 0.78rem; cursor: pointer;
}
.tab.active {
  color: #fff; background: rgba(56, 189, 248, 0.15); border-color: rgba(56, 189, 248, 0.35);
}
.viewer-meta {
  color: var(--muted); font-size: 0.72rem; font-family: "JetBrains Mono", monospace;
  margin-bottom: 8px; word-break: break-all; flex-shrink: 0;
}

/* Code area: scroll INSIDE box, never under topbar */
.code-view {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: #070b14;
  color: #dbe7f5;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.5;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
  max-height: 100%;
}
.preview-frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #fff;
  max-height: 100%;
}
.empty { padding: 24px 12px; text-align: center; color: var(--muted); font-size: 0.86rem; }
.empty.tall { margin: auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; min-height: 26px; }
.chip-src {
  font-family: "JetBrains Mono", monospace; font-size: 0.66rem; padding: 4px 8px;
  border-radius: 999px; border: 1px solid rgba(52, 211, 153, 0.3);
  color: #6ee7b7; background: rgba(16, 185, 129, 0.08);
}
.log {
  margin-top: 10px; max-height: 110px; overflow: auto; overscroll-behavior: contain;
  font-family: "JetBrains Mono", monospace; font-size: 0.7rem; color: var(--muted);
  background: rgba(2, 6, 23, 0.5); border: 1px solid var(--border); border-radius: 11px;
  padding: 10px 12px; line-height: 1.5;
}
.log .ok { color: var(--ok); }
.log .info { color: #7dd3fc; }
.sub-list {
  margin-top: 8px; max-height: min(48vh, 420px); overflow: auto; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: 11px; background: rgba(2, 6, 23, 0.4);
  -webkit-overflow-scrolling: touch;
}
.sub-item {
  padding: 10px 12px; border-bottom: 1px solid rgba(148, 163, 184, 0.07);
  font-family: "JetBrains Mono", monospace; font-size: 0.78rem; cursor: pointer;
}
.sub-item:hover { background: rgba(56, 189, 248, 0.07); }
.filter-input { max-width: 200px; height: 34px; font-size: 0.8rem; }

.foot {
  margin-top: 16px; text-align: center; color: var(--muted); font-size: 0.72rem; line-height: 1.5;
  position: relative; z-index: 0;
}

/* Mobile */
@media (max-width: 860px) {
  .shell { width: calc(100% - 16px); padding-top: calc(8px + var(--safe-top)); }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 10px 12px;
  }
  .brand h1 { font-size: 0.98rem; }
  .brand p { display: none; }
  .nav-tabs { width: 100%; order: 3; }
  .nav-tab { flex: 1; text-align: center; }
  .ver { margin-left: auto; }

  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .side-panel, .main-panel {
    max-height: none;
    overflow: visible;
  }
  .file-list {
    max-height: 220px;
    flex: none;
  }
  .code-view {
    min-height: 260px;
    max-height: min(55vh, 480px);
    flex: none;
  }
  .preview-frame {
    min-height: 260px;
    max-height: min(55vh, 480px);
    flex: none;
  }
  .form-row .btn { flex: 1; }
  input[type="url"], input[type="text"] { min-width: 100%; flex: 1 1 100%; }
  .filter-input { max-width: none; width: 100%; }
}

@media (max-width: 420px) {
  .opt-row { gap: 8px 10px; font-size: 0.76rem; }
  .btn { padding: 0 10px; font-size: 0.8rem; }
}
