:root {
  --bg: #FAF9F5;
  --bg-raised: #FFFFFF;
  --bg-subtle: #F3F1EA;
  --ink: #262624;
  --ink-soft: #57534E;
  --ink-faint: #A8A29E;
  --line: #E7E5DC;
  --accent: #C96442;
  --accent-ink: #FFFFFF;
  --accent-soft: #F6E3DA;
  --green: #3F7D4E;
  --green-soft: #E4EFE6;
  --red: #B3382C;
  --red-soft: #F7E2DF;
  --amber: #9A6B15;
  --amber-soft: #F5EBD7;
  --blue: #3D6B8C;
  --blue-soft: #E2ECF3;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(38,38,36,.05), 0 1px 3px rgba(38,38,36,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }

.ic { vertical-align: -0.15em; flex-shrink: 0; }

/* ---------- layout ---------- */
.app-shell { display: none; min-height: 100vh; }
.app-shell.active { display: block; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 56px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.brand .logo-dot { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.nav { display: flex; gap: 2px; margin-left: 12px; }
.nav a {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 8px;
  color: var(--ink-soft); font-weight: 500;
}
.nav a:hover { background: var(--bg-subtle); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.live-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 550; padding: 4px 11px; border-radius: 999px; }
.live-badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.live-badge.on { color: var(--green); background: var(--green-soft); } .live-badge.on .dot { background: var(--green); animation: pulse 2s infinite; }
.live-badge.off { color: var(--red); background: var(--red-soft); } .live-badge.off .dot { background: var(--red); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.heartbeat-age { font-size: 12px; color: var(--ink-faint); }

/* bot control cluster */
.bot-ctl { display: inline-flex; align-items: center; gap: 7px; padding: 3px 4px 3px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-raised); }
.bot-status-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.bot-status-dot.online { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.bot-status-dot.stopped { background: var(--ink-faint); }
.bot-status-dot.errored { background: var(--red); }
.bot-status-dot.unknown { background: var(--amber); }
.bot-status-text { font-size: 12.5px; font-weight: 550; color: var(--ink-soft); min-width: 72px; white-space: nowrap; }
.bot-ctl button { width: 28px; height: 28px; padding: 0; }
.bot-ctl button:disabled { opacity: .4; cursor: not-allowed; }
.btn.small.success { color: var(--green); border-color: var(--green-soft); background: var(--green-soft); }
.btn.small.success:hover:not(:disabled) { background: var(--green); color: #fff; }
.btn.small.danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn.small.danger:hover:not(:disabled) { background: var(--red); color: #fff; }

.container { max-width: 1160px; margin: 0 auto; padding: 28px 24px 64px; }
.page-title { font-size: 20px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
.page-sub { color: var(--ink-faint); margin: 0 0 24px; font-size: 13.5px; }

/* ---------- cards & stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card { padding: 16px 18px; }
.stat-card .label { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 12.5px; font-weight: 550; margin-bottom: 8px; }
.stat-card .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-card .sub { font-size: 12px; color: var(--ink-faint); margin-top: 3px; }

.panel { margin-bottom: 20px; }
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  font-weight: 650; font-size: 13.5px;
}
.panel-body { padding: 8px 18px 16px; }

/* ---------- progress ---------- */
.progress-wrap { height: 8px; border-radius: 999px; background: var(--bg-subtle); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width .5s ease; }

/* ---------- tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-faint); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.rowlink:hover { background: var(--bg-subtle); cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- badges & pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: var(--bg-subtle); color: var(--ink-soft); }

.lvl { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 5px; }
.lvl.INFO { background: var(--bg-subtle); color: var(--ink-soft); }
.lvl.WARN { background: var(--amber-soft); color: var(--amber); }
.lvl.ERROR { background: var(--red-soft); color: var(--red); }
.lvl.SUCCESS { background: var(--green-soft); color: var(--green); }

/* ---------- forms / buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-raised); color: var(--ink); font-weight: 550; font-size: 13.5px;
  cursor: pointer; transition: all .12s ease;
}
.btn:hover { border-color: var(--ink-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

input[type="text"], input[type="password"], input[type="search"], select {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-raised); color: var(--ink); font-size: 13.5px; font-family: var(--sans);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 360px; max-width: 100%; padding: 32px; }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-logo .logo-dot { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.login-title { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.login-sub { color: var(--ink-faint); font-size: 13px; margin-bottom: 22px; }
.login-error { display: none; margin-bottom: 14px; padding: 9px 12px; border-radius: 8px; background: var(--red-soft); color: var(--red); font-size: 13px; font-weight: 500; }
.login-error.show { display: flex; align-items: center; gap: 8px; }

/* ---------- log viewer ---------- */
.log-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.log-box {
  background: #211f1d; border-radius: var(--radius);
  border: 1px solid #35322e;
  font-family: var(--mono); font-size: 12px; line-height: 1.7;
  height: 62vh; overflow-y: auto; padding: 12px 0;
}
.log-line { display: flex; gap: 10px; padding: 1px 14px; white-space: pre-wrap; word-break: break-all; }
.log-line:hover { background: rgba(255,255,255,.045); }
.log-line .t { color: #8a8580; flex-shrink: 0; }
.log-line .s { color: #c9a57e; flex-shrink: 0; min-width: 110px; }
.log-line .l { flex-shrink: 0; width: 62px; font-weight: 700; }
.log-line .m { color: #d6d3d0; }
.lvl-chip { font-size: 10px; padding: 0 5px; border-radius: 4px; font-weight: 700; }
.lvl-chip.INFO { background: #35322e; color: #b5b0ab; }
.lvl-chip.WARN { background: #4a3b17; color: #ecc56a; }
.lvl-chip.ERROR { background: #4e211c; color: #ff9d92; }
.lvl-chip.SUCCESS { background: #1f3a27; color: #85d69a; }

.chips { display: flex; gap: 6px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-raised); font-size: 12.5px; font-weight: 550; cursor: pointer; color: var(--ink-soft); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.empty { text-align: center; color: var(--ink-faint); padding: 40px 0; font-size: 13.5px; }

/* ---------- feed (chapters) ---------- */
.feed-item { display: flex; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); align-items: baseline; }
.feed-item:last-child { border-bottom: none; }
.feed-item .when { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint); flex-shrink: 0; width: 150px; }
.feed-item .what { font-size: 13.5px; }
.feed-item .what b { font-weight: 650; }
