:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1d212c;
  --border: #2a2f3a;
  --text: #d7dce5;
  --muted: #8b94a7;
  --accent: #5b9dff;
  --accent-2: #3b7dd8;
  --green: #57d08a;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

body { display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 15px; margin: 0; font-weight: 600; }

header nav { display: flex; gap: 4px; }

header nav button {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
header nav button:hover { color: var(--text); }
header nav button.active {
  color: var(--text);
  background: var(--bg-3);
  border-color: var(--border);
}

main { flex: 1; min-height: 0; }

section { height: 100%; }
section[hidden] { display: none; }

/* Files view */
#files-view { display: flex; height: 100%; }

#sidebar {
  width: 300px;
  min-width: 220px;
  border-right: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#filter {
  margin: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
#filter:focus { outline: none; border-color: var(--accent); }

#tree { flex: 1; overflow: auto; padding: 0 6px 12px; }

.tree-node { user-select: none; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.tree-row:hover { background: var(--bg-3); }
.tree-row.selected { background: var(--bg-3); color: var(--accent); }
.tree-row .twisty { width: 12px; color: var(--muted); display: inline-block; text-align: center; }
.tree-row .ico { width: 16px; text-align: center; opacity: 0.8; }
.tree-row .label { overflow: hidden; text-overflow: ellipsis; }
.tree-children { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 4px; }

#content { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

#breadcrumb {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
#breadcrumb a { color: var(--accent); cursor: pointer; text-decoration: none; }
#breadcrumb a:hover { text-decoration: underline; }
#breadcrumb .sep { color: var(--border); }

#file-view { flex: 1; overflow: auto; padding: 16px; }

/* Directory listing */
.dir-list { list-style: none; margin: 0; padding: 0; }
.dir-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}
.dir-list li:hover { background: var(--bg-2); border-color: var(--border); }
.dir-list .ico { width: 20px; text-align: center; }
.dir-list .name { flex: 1; }
.dir-list .size { color: var(--muted); font-size: 12px; }

/* File content */
.file-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.file-head .meta { color: var(--muted); font-size: 12px; }
.file-head a.live, .btn {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 12px;
  cursor: pointer;
}
.file-head a.live:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }

.code-wrap { display: flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.code-lines {
  padding: 12px 8px;
  text-align: right;
  color: var(--muted);
  background: var(--bg);
  border-right: 1px solid var(--border);
  user-select: none;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
}
.code-body {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  flex: 1;
  color: #e6ebf2;
}
.note { color: var(--muted); margin-top: 12px; font-size: 12px; }
.binary-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  background: var(--bg-2);
  text-align: center;
}
.binary-box .meta { color: var(--muted); margin-bottom: 14px; }

/* Sites grid */
#sites-view { overflow: auto; padding: 20px; }
#sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: 16px;
}
.site-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-2);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.site-card h3 { margin: 0; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.site-card .badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--muted);
  border: 1px solid var(--border);
}
.site-card .badge.live { color: var(--green); border-color: var(--green); }
.site-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.site-card .preview-frame {
  width: 100%;
  height: 240px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  display: none;
}
.site-card .preview-frame.open { display: block; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

/* Mobile-only controls */
.mobile-only { display: none; }

/* Responsive / mobile */
@media (max-width: 760px) {
  header { flex-wrap: wrap; gap: 8px 12px; }
  header h1 { font-size: 14px; flex: 1 1 auto; }
  .mobile-only {
    display: inline-block;
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
  }

  /* Off-canvas drawer for the tree */
  #tree-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    display: none;
  }
  #files-view.menu-open #tree-backdrop { display: block; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 340px);
    max-height: none;
    border-right: 1px solid var(--border);
    border-bottom: none;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 50;
    display: flex;
    flex-direction: column;
  }
  #files-view.menu-open #sidebar { transform: translateX(0); }

  .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
  }
  #tree-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
  }
  #tree-close:hover { color: var(--text); }
  #sidebar #filter { margin: 10px; }
  #tree { flex: 1; }

  #content { min-height: 0; }

  /* Bigger tap targets */
  .tree-row { padding: 9px 6px; }
  .dir-list li { padding: 12px 10px; }
  .file-head a.live, .btn { padding: 9px 12px; }

  /* Sites */
  #sites-view { padding: 14px; }
  .site-card .preview-frame { height: 200px; }

  /* Code view: allow horizontal scroll, smaller padding */
  .code-wrap { font-size: 12px; }
  .code-lines { padding: 10px 6px; }
  .code-body { padding: 10px; }
}

@media (max-width: 420px) {
  header nav button { padding: 6px 9px; font-size: 12px; }
  #content { padding: 10px; }
}
