:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e3e7ee;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --code-bg: #f1f3f7;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

.topbar {
  background: #0f172a; color: #fff; padding: 12px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.topbar .container { display: flex; align-items: center; justify-content: space-between; }
.brand { color: #fff; font-weight: 600; font-size: 18px; text-decoration: none; }
.topbar nav a { color: #cbd5e1; text-decoration: none; margin-left: 18px; }
.topbar nav a:hover { color: #fff; }

/* New top navigation: 5 category tabs + management dropdown */
.topnav {
  display: flex; align-items: center; flex: 1; margin-left: 24px;
}
.topnav-item {
  color: #cbd5e1; text-decoration: none; padding: 10px 14px;
  border-radius: 6px; font-size: 14px; margin: 0 2px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s;
}
.topnav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.topnav-item.active {
  background: var(--primary); color: #fff;
}
.topnav-count {
  background: rgba(0,0,0,.25); padding: 1px 6px; border-radius: 999px;
  font-size: 11px;
}
.topnav-item.active .topnav-count { background: rgba(255,255,255,.25); }
.topnav-spacer { flex: 1; }

.dropdown { position: relative; margin-left: 8px; }
.dropdown-toggle {
  background: transparent; color: #cbd5e1; border: 1px solid rgba(255,255,255,.15);
  padding: 7px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.dropdown-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.dropdown-menu {
  position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: #ffffff; border: 1px solid var(--border); border-radius: 6px;
  min-width: 200px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
  display: none; z-index: 10;
}
.dropdown:hover .dropdown-menu, .dropdown:focus-within .dropdown-menu { display: block; }
.dropdown-menu a {
  display: block; padding: 8px 14px; font-size: 13px;
  color: var(--text); text-decoration: none; margin: 0;
}
.dropdown-menu a:hover { background: #f7f9fc; color: var(--primary); }

/* Browse layout: sidebar + main */
.browse-layout {
  display: grid; grid-template-columns: 220px 1fr; gap: 18px;
}
@media (max-width: 720px) {
  .browse-layout { grid-template-columns: 1fr; }
}
.browse-sidebar {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; align-self: start; position: sticky; top: 12px;
  max-height: calc(100vh - 24px); overflow-y: auto;
}
.browse-sidebar h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 500; }
.sub-list { list-style: none; padding: 0; margin: 0; }
.sub-list li { margin: 0; }
.sub-list a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; color: var(--text); text-decoration: none;
  border-radius: 4px; font-size: 13px;
}
.sub-list a:hover { background: #f7f9fc; }
.sub-list a.active { background: var(--primary); color: #fff; }
.sub-count {
  background: #e5e7eb; color: #374151; padding: 0 6px;
  border-radius: 999px; font-size: 11px;
}
.sub-list a.active .sub-count { background: rgba(255,255,255,.25); color: #fff; }

.browse-main { min-width: 0; }
.browse-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px; gap: 16px; flex-wrap: wrap;
}
.browse-header h2 { margin: 0; font-size: 18px; }
.browse-header h2 small { font-size: 13px; font-weight: normal; margin-left: 8px; }

.empty-block {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 40px 20px; text-align: center;
}

.post-source-pill {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 6px; border-radius: 4px; font-size: 11px;
  background: rgba(0,0,0,.55); color: #fff;
}
.post-dur-pill {
  position: absolute; bottom: 8px; left: 8px;
  padding: 2px 6px; border-radius: 4px; font-size: 11px;
  background: rgba(0,0,0,.65); color: #fff; font-variant-numeric: tabular-nums;
}
a.post-card { color: inherit; text-decoration: none; }

main.container { padding-top: 24px; padding-bottom: 60px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 18px 20px; margin-bottom: 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 18px; }

.btn {
  display: inline-block; padding: 7px 14px; font-size: 14px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 6px; cursor: pointer; text-decoration: none;
  transition: all .12s ease;
}
.btn:hover { background: #f7f9fc; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-small { padding: 4px 10px; font-size: 12px; }

label { display: block; font-size: 14px; margin-bottom: 14px; }
label.narrow { max-width: 160px; }
label .hint { color: var(--muted); font-size: 12px; font-weight: normal; margin-left: 6px; }
input[type=text], input[type=url], input[type=number], textarea {
  width: 100%; padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
  margin-top: 4px; font-family: inherit;
}
input:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.fields-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.fields-table th, .fields-table td { padding: 6px 4px; text-align: left; }
.fields-table th { font-size: 13px; color: var(--muted); font-weight: 500; }
.fields-table input { margin-top: 0; }

.actions { display: flex; gap: 10px; margin-top: 18px; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  text-align: left; vertical-align: top;
}
.data-table th {
  background: #f8fafc; font-size: 13px; font-weight: 600; color: #374151;
}
.data-table.small th, .data-table.small td { padding: 6px 8px; font-size: 13px; }
.table-scroll { overflow-x: auto; }

.cell { max-width: 320px; word-break: break-word; }
.truncate {
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

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

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.badge-running { background: #fef3c7; color: #92400e; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-failed  { background: #fee2e2; color: #991b1b; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }

code {
  background: var(--code-bg); padding: 2px 6px; border-radius: 4px;
  font-size: 12.5px; font-family: "JetBrains Mono", Consolas, monospace;
}

.flashes { margin-bottom: 14px; }
.flash { padding: 9px 14px; border-radius: 6px; margin-bottom: 6px; font-size: 14px; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

.preview-box {
  margin-top: 16px; padding: 12px 14px;
  background: #fafbfc; border: 1px solid var(--border); border-radius: 6px;
  max-height: 420px; overflow: auto; font-size: 13px;
}
.preview-box pre {
  background: transparent; margin: 8px 0 0; white-space: pre-wrap; word-break: break-word;
}
.hidden { display: none; }

.footer { padding: 18px 0; color: var(--muted); font-size: 12px; text-align: center; }

textarea {
  width: 100%; padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
  margin-top: 4px; font-family: "JetBrains Mono", Consolas, monospace;
  resize: vertical;
}

.card.warn {
  background: #fffbeb; border-color: #fde68a; color: #92400e;
}

.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat {
  flex: 1 1 140px; min-width: 140px;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 4px;
}
.stat-num { font-size: 20px; font-weight: 600; color: var(--text); }
.stat-label { font-size: 12px; color: var(--muted); line-height: 1.35; }

.filter-bar {
  display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
  align-items: center;
}
.filter-bar input[type=search] {
  flex: 1; min-width: 200px; padding: 7px 10px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 6px;
}
.filter-bar select {
  padding: 7px 10px; font-size: 14px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff;
}

.avatar {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); background: #f1f5f9;
}

.badge-status-CONTINUE { background: #dcfce7; color: #166534; }
.badge-status-CANCEL   { background: #fee2e2; color: #991b1b; }
.badge-status-EXPIRED  { background: #f1f5f9; color: #475569; }

.pager {
  display: flex; justify-content: center; align-items: center; gap: 14px;
  padding: 14px 0 4px;
}

button[disabled] { opacity: .5; cursor: not-allowed; }

.tabs {
  display: flex; gap: 2px; margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
}
.tab {
  padding: 10px 18px; font-size: 14px; color: var(--muted);
  text-decoration: none; border-bottom: 2px solid transparent;
  margin-bottom: -2px; display: inline-flex; align-items: center; gap: 8px;
  transition: color .12s ease, border-color .12s ease;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary); border-bottom-color: var(--primary); font-weight: 500;
}
.tab-count {
  background: #e5e7eb; color: #374151;
  padding: 1px 8px; border-radius: 999px; font-size: 12px;
}
.tab.active .tab-count { background: #dbeafe; color: var(--primary); }

.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.post-card {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; transition: box-shadow .15s ease, transform .15s ease;
}
.post-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); transform: translateY(-1px); }
.post-thumb {
  position: relative; width: 100%; padding-top: 56.25%;
  background: #f1f5f9; overflow: hidden;
}
.post-thumb img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.post-type-pill, .post-perm-pill {
  position: absolute; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 500; backdrop-filter: blur(4px);
}
.post-type-pill { top: 8px; left: 8px; background: rgba(0,0,0,.65); color: #fff; }
.post-perm-pill { top: 8px; right: 8px; background: rgba(220,38,38,.85); color: #fff; }
.post-body { padding: 10px 12px; }
.post-title {
  font-size: 14px; font-weight: 500; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word; min-height: 2.8em;
}
.post-meta { font-size: 12px; margin-top: 6px; }
.post-meta a { color: var(--muted); text-decoration: none; }
.post-meta a:hover { color: var(--primary); }
.post-stats { font-size: 12px; margin-top: 4px; }

/* Auth pages */
.auth-body {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  min-height: 100vh; margin: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.auth-card {
  background: #fff; border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  padding: 32px 36px; width: 100%; max-width: 420px;
}
.auth-brand { text-align: center; margin: 0 0 18px; font-size: 22px; color: var(--primary); }
.auth-card h2 { margin: 0 0 10px; font-size: 18px; }
.auth-card form label { display: block; font-size: 13px; margin-bottom: 14px; }
.auth-card .btn { padding: 10px 14px; font-size: 14px; }
.qr-wrap { display: flex; justify-content: center; margin: 18px 0 8px; }
.qr { width: 220px; height: 220px; border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: #fff; }
.totp-secret {
  display: inline-block; margin-top: 4px; font-size: 13px; padding: 4px 8px;
  background: #f1f3f7; border-radius: 4px; user-select: all; word-break: break-all;
}

.user-chip {
  background: rgba(255,255,255,.08); color: #cbd5e1;
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
  margin-left: 10px;
}
.btn-link {
  background: transparent; border: none; color: #cbd5e1;
  cursor: pointer; padding: 0; font-size: 14px; margin-left: 14px;
  text-decoration: none;
}
.btn-link:hover { color: #fff; text-decoration: underline; }

.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.paid-pill {
  display: inline-block; padding: 1px 8px; border-radius: 4px;
  background: #fef3c7; color: #92400e; font-weight: 500;
  text-decoration: none; font-size: 12px;
}
.paid-pill:hover { background: #fde68a; }

.cat-select {
  font-size: 12px; padding: 3px 6px; border: 1px solid var(--border);
  border-radius: 4px; background: #fff; max-width: 180px;
  transition: background .2s;
}
.cat-select:disabled { opacity: .6; }

.post-actions { margin-top: 8px; display: flex; gap: 8px; align-items: center; }

.post-dl-pill {
  position: absolute; bottom: 8px; right: 8px;
  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500;
  backdrop-filter: blur(4px);
}
.post-dl-pill.dl-done        { background: rgba(34,197,94,.85);  color: #fff; }
.post-dl-pill.dl-downloading { background: rgba(59,130,246,.85); color: #fff; }
.post-dl-pill.dl-pending     { background: rgba(217,119,6,.85);  color: #fff; }
.post-dl-pill.dl-failed      { background: rgba(220,38,38,.85);  color: #fff; }

.select-bar {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 100%);
  background: #0f172a; color: #fff;
  padding: 10px 18px; border-radius: 10px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 50; opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
  font-size: 14px;
}
.select-bar.visible { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.select-bar .btn { padding: 6px 12px; font-size: 13px; }
.select-bar .btn-primary { background: var(--primary); border-color: var(--primary); }
.select-bar #sel-count { color: #fbbf24; font-size: 16px; }

input[type=checkbox] { cursor: pointer; width: 16px; height: 16px; }
.row-select { margin: 0; }

.dl-current {
  background: linear-gradient(90deg, #eff6ff 0%, #ffffff 100%);
  border: 1px solid #bfdbfe; border-radius: 8px;
  padding: 14px 16px; margin-bottom: 14px;
}
.dl-current .dl-current-row { display: flex; align-items: center; gap: 12px; }
.dl-spinner {
  width: 14px; height: 14px; border: 2px solid #bfdbfe;
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
