:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #0f766e;
  --accent-hover: #0d5e57;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn-bg: #fef3c7;
  --warn: #b45309;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.mono { font-family: var(--mono); }

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, #dbeafe, #f1f5f9 55%);
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.1);
}
.brand-row { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.brand-logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #0f766e);
  color: #fff; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-row h1 { font-size: 20px; margin: 0 0 2px 0; }
.tab-bar {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px; margin-bottom: 18px;
}
.tab-btn {
  border: 0; background: transparent; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
}
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.alert-error {
  padding: 10px 12px; border-radius: 8px; font-size: 13px;
  background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca;
}
.login-foot { margin-top: 16px; text-align: center; font-size: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-full { width: 100%; padding: 11px; font-size: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost { background: #fff; color: #334155; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: #cbd5e1; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px; justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.brand-pill {
  background: linear-gradient(135deg, #2563eb, #0f766e); color: #fff;
  font-weight: 800; font-size: 13px; padding: 4px 10px; border-radius: 8px;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.role-badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eff6ff; color: var(--primary); font-weight: 600; }
.role-badge.viewer { background: #f0fdf4; color: var(--ok); }
.topbar-search { flex: 1; min-width: 220px; max-width: 420px; }
.topbar-search input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: var(--surface-2);
}
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Layout */
.container { max-width: 1320px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 28px; }
.section-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { margin: 0 0 2px 0; font-size: 18px; }
.stats-pill { font-size: 12px; color: var(--muted); background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; }

/* Latest 5-Card Grid */
.latest-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 14px; }
.latest-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.latest-card.empty { background: var(--surface-2); box-shadow: none; border-style: dashed; }
.latest-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cat-tag {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.cat-frontend { background: #ede9fe; color: #6d28d9; }
.cat-backend { background: #dbeafe; color: #1d4ed8; }
.cat-installer { background: #dcfce7; color: #15803d; }
.cat-sql { background: #fef3c7; color: #b45309; }
.cat-collector { background: #cffafe; color: #0e7490; }

.ver-pill { font-size: 12px; font-weight: 700; color: #0f172a; background: #f1f5f9; border-radius: 6px; padding: 2px 8px; }
.latest-filename { font-weight: 700; font-size: 14px; word-break: break-all; }
.latest-meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.latest-actions { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; padding-top: 6px; }

/* Toolbar */
.view-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.view-tabs { display: inline-flex; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 4px; gap: 4px; }
.view-tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.view-tab.active { background: var(--primary); color: #fff; }
.cat-filter-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filter-pill { border: 1px solid var(--border); background: #fff; color: #334155; padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer; }
.filter-pill.active { background: #0f172a; color: #fff; border-color: #0f172a; }
.toggle-latest { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: #334155; margin-left: 8px; cursor: pointer; }

/* Releases Stack */
.releases-stack { display: flex; flex-direction: column; gap: 16px; }
.release-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.release-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.release-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 4px; }
.release-ver { font-size: 18px; font-weight: 800; color: #0f172a; }
.channel-pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; }
.channel-stable { background: var(--ok-bg); color: var(--ok); }
.channel-beta { background: #ede9fe; color: #6d28d9; }
.channel-patch { background: var(--warn-bg); color: var(--warn); }
.pin-pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #fee2e2; color: #b91c1c; }

.completeness-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.comp-item { font-size: 11px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--muted); }
.comp-item.ok { border-color: #bbf7d0; background: #f0fdf4; color: var(--ok); font-weight: 600; }

/* Table */
.table-wrap { width: 100%; overflow-x: auto; background: #fff; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
th { font-size: 12px; font-weight: 700; color: var(--muted); background: #f8fafc; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.sha-short { font-family: var(--mono); font-size: 12px; color: #475569; background: #f1f5f9; padding: 2px 6px; border-radius: 4px; }
.latest-mini { font-size: 11px; font-weight: 700; color: var(--ok); background: var(--ok-bg); padding: 1px 6px; border-radius: 4px; margin-left: 6px; }
.empty-box { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; background: #fff; border: 1px dashed var(--border); border-radius: var(--radius); }

/* Modal & Upload */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  width: 100%; max-width: 640px; max-height: 90vh; background: #fff; border-radius: 14px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { border: 0; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }

.dropzone {
  border: 2px dashed #cbd5e1; border-radius: 10px; padding: 22px; text-align: center;
  background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--primary); background: #eff6ff; }
.progress-track { width: 100%; height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #2563eb, #0f766e); transition: width .12s; }
.code-pre {
  background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px;
  font-family: var(--mono); font-size: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: 0;
}

.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 90;
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.lock-banner {
  background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #fcd34d;
  padding: 10px 24px; font-size: 13px; font-weight: 600; text-align: center;
}
.ttl-select-wrap {
  display: inline-flex; align-items: center; gap: 6px; background: #fff;
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
}
.ttl-select-wrap select {
  border: 0; background: transparent; font-size: 12px; font-weight: 600; color: var(--text); outline: none; cursor: pointer;
}
