:root {
  --bg: #f5f7fb;
  --card: #fff;
  --ink: #0f172a;
  --muted: #6b7a90;
  --line: #e6ebf3;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --ok: #16a34a;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", sans-serif;
}

.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }

.layout { display: flex; min-height: 100vh; }

/* ---------------------------------------------------------------- 侧栏 */

.side {
  width: 216px; flex: 0 0 216px; padding: 18px 14px;
  background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-brand {
  display: flex; align-items: center; gap: 9px; font-weight: 700; color: #fff;
  padding: 4px 8px 18px; font-size: 15px;
}
.side-brand span {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6); font-size: 13px;
}
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.tab {
  text-align: left; border: none; background: none; color: #cbd5e1; font: inherit;
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
}
.tab:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.tab.active { background: rgba(59, 130, 246, .22); color: #fff; font-weight: 600; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px; }
.side-link {
  border: none; background: none; color: #94a3b8; font: inherit; text-align: left;
  padding: 6px 4px; cursor: pointer;
}
.side-link:hover { color: #fff; }

/* ---------------------------------------------------------------- 主区 */

.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 21px; letter-spacing: -.3px; }
.sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #cfdcef; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #4f7cf7); color: #fff; border: none;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: #dc2626; border-color: #fecdd3; background: #fff; }
.btn.danger:hover { background: #fff1f2; border-color: #fda4af; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f5f9; color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }

/* ---------------------------------------------------------------- 卡片 */

.cards {
  display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-bottom: 18px;
}
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px;
}
.kpi span { display: block; font-size: 12.5px; color: var(--muted); }
.kpi b { display: block; font-size: 24px; letter-spacing: -.6px; line-height: 1.3; }
.kpi i { display: block; font-style: normal; font-size: 12px; color: var(--muted); }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 14px; font-weight: 700; letter-spacing: .2px; }

.cols { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* ---------------------------------------------------------------- 条形图 */

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .k { flex: 0 0 96px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; border-radius: 999px; background: #eef2f8; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #3b82f6, #8b5cf6); }
.bar-row .n { flex: 0 0 54px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 表格 */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line);
  vertical-align: top; white-space: nowrap;
}
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafcff; }
td.wrap-cell { white-space: normal; word-break: break-word; overflow-wrap: anywhere; min-width: 260px; max-width: 520px; width: 42%; }
tr:hover td { background: #fbfdff; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
  background: #eef2f8; color: #475569;
}
.tag.ok { background: #e9f8ef; color: var(--ok); }
.tag.fail { background: #fdecec; color: var(--danger); }
.thumb-mini {
  width: 40px; height: 40px; border-radius: 7px; object-fit: cover; background: #eef2f8;
}

/* ---------------------------------------------------------------- 过滤/分页 */

.filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px;
}
.filters input, .filters select {
  padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; font: inherit; font-size: 13px; outline: none;
}
.filters input:focus, .filters select:focus { border-color: var(--accent); }
.filters input { min-width: 240px; }
.count { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 14px; }
.pager span { font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------------- 内容库 */

.gallery {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
}
.gitem {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; position: relative;
}
.gitem.picked { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37, 99, 235, .18); }
.gitem .gpick {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  width: 18px; height: 18px; accent-color: #2563eb; cursor: pointer;
}
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #475569; cursor: pointer; }
.chk input { width: 15px; height: 15px; accent-color: #2563eb; }
.gitem img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; background: #eef2f8; }
.gitem .gbody { padding: 8px 10px 10px; }
.gitem .gtitle {
  font-size: 12.5px; font-weight: 600; line-height: 1.35; margin: 0 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.gitem .gmeta { font-size: 11.5px; color: var(--muted); }

/* ---------------------------------------------------------------- 登录 */

.gate {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(15, 23, 42, .6); backdrop-filter: blur(6px); padding: 20px;
}
.gate-box {
  width: min(340px, 100%); background: #fff; border-radius: 18px; padding: 24px;
  text-align: center; box-shadow: 0 30px 80px rgba(15, 23, 42, .35);
}
.gate-box h2 { margin: 0 0 6px; font-size: 19px; }
.gate-box p { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }
.gate-box input {
  width: 100%; padding: 11px 13px; border-radius: 11px; border: 1px solid var(--line);
  font: inherit; text-align: center; outline: none;
}
.gate-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, .1); }
.gate-box .btn { width: 100%; margin-top: 12px; }
.err { color: var(--danger); font-size: 12.5px; margin: 8px 0 0; min-height: 16px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: column; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 16px; }
}

/* 手机 / 平板：侧栏变顶部横向滚动条，表格横向滚动，卡片两列 */
@media (max-width: 720px) {
  .main { padding: 12px 10px 32px; }
  .side { padding: 10px; }
  .side-nav {
    flex-wrap: nowrap; overflow-x: auto; gap: 6px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav .tab { flex: 0 0 auto; min-height: 40px; display: inline-flex; align-items: center; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar-actions { flex-wrap: wrap; }
  .topbar-actions .btn { flex: 1 1 auto; min-height: 40px; }
  .kpi { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .filters { flex-direction: column; align-items: stretch; gap: 8px; }
  .filters input, .filters select, .filters .btn { width: 100%; min-height: 40px; }
  .filters .count { max-width: 100%; }
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .gallery { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .logbox { max-height: 60vh; font-size: 11.5px; }
  input, select, textarea { font-size: 16px; }
}

@media (max-width: 400px) {
  .kpi { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- 日志 */

.filters .count {
  max-width: min(72%, 720px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.logbox {
  margin: 0; padding: 16px; border-radius: 12px; background: #0f172a; color: #d7e2f5;
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  max-height: 66vh; overflow: auto; white-space: pre-wrap; word-break: break-all;
}


/* ---------------------------------------------------------------- 服务控制（v1.7.6） */

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.panel-head h2 { margin: 0; }

.svc-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}
.svc-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px 12px; border-radius: 11px;
  background: #f8fafc; border: 1px solid #eef2f7;
}
.svc-k { font-size: 11.5px; color: var(--muted); letter-spacing: .2px; }
.svc-v { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.svc-v::before {
  content: ""; display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; margin-right: 6px; vertical-align: 1px;
  background: #cbd5e1;
}
.svc-v.on::before { background: #16a34a; }
.svc-v.off::before { background: #dc2626; }
.svc-v.warn::before { background: #d97706; }

.svc-actions {
  display: flex; align-items: center; gap: 10px;
  margin-top: 14px; flex-wrap: wrap;
}
.svc-actions .sub { margin: 0; }

@media (max-width: 720px) {
  .svc-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------------------------------------------------------- 更新日志 */

.changelog { display: flex; flex-direction: column; gap: 14px; }
.cl-item {
  background: var(--card, #fff); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 18px;
}
.cl-item h3 {
  margin: 0 0 10px; font-size: 14px; font-weight: 700; color: var(--ink);
  padding-bottom: 8px; border-bottom: 1px dashed var(--line);
}
.cl-item h4 { margin: 14px 0 6px; font-size: 13px; color: var(--ink); }
.cl-item p { margin: 6px 0; font-size: 13px; line-height: 1.75; color: #334155; }
.cl-item ul { margin: 6px 0 10px; padding-left: 20px; }
.cl-item li { font-size: 13px; line-height: 1.75; color: #334155; }
.cl-item code {
  background: #f1f5f9; border-radius: 5px; padding: 1px 5px;
  font-family: Consolas, Monaco, monospace; font-size: 12px;
}
.cl-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px 0 12px; }
.cl-table { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: fixed; }
.cl-table-3 th:first-child, .cl-table-3 td:first-child { width: 46px; }
.cl-table th, .cl-table td {
  border: 1px solid #eef2f7; padding: 7px 9px; text-align: left;
  vertical-align: top; color: #334155; white-space: normal; word-break: break-word; overflow-wrap: anywhere;
}
.cl-table th { background: #f8fafc; font-weight: 600; color: var(--ink); }
