:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1c1b19;
  --muted: #6b6963;
  --line: #e5e3de;
  --accent: #2553d8;
  --accent-soft: #e8eefc;
  --ok: #1f8a4c;
  --ok-soft: #e4f4ea;
  --warn: #a8660b;
  --warn-soft: #fcf1de;
  --bad: #c0362c;
  --bad-soft: #fbe7e5;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.topbar { display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { color: var(--text); background: var(--bg); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: var(--accent); }

button, .btn { font: inherit; border: 1px solid transparent; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--bg); }
button.danger { background: var(--bad); }
button.ok { background: var(--ok); }
button.small { padding: 5px 10px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=time], select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; min-height: 280px; resize: vertical; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafaf8; position: sticky; top: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafaf8; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.table-wrap table td, .table-wrap table th { white-space: nowrap; }
td.wrap { white-space: normal !important; max-width: 320px; word-break: break-word; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.alert.bad { background: var(--bad-soft); border-color: #f1c4bf; color: #7d231c; }
.alert.warn { background: var(--warn-soft); border-color: #efd6a8; color: #6e4308; }
.alert.ok { background: var(--ok-soft); border-color: #bfe3cc; color: #145a32; }
.alert.info { background: var(--accent-soft); border-color: #c9d6f7; color: #1b3a94; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

.switch { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 99px; white-space: nowrap; }
.switch.on { background: var(--ok-soft); color: var(--ok); }
.switch.off { background: var(--bad-soft); color: var(--bad); }

.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; display: flex; }
.progress > span { display: block; height: 100%; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 12px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor iframe { width: 100%; min-height: 420px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 180px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 18, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 12px; padding: 24px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 860px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.confirm-input { font-size: 16px !important; letter-spacing: .08em; text-align: center; font-weight: 700; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; max-width: 90vw; }
.toast.error { background: var(--bad); }

.login { max-width: 360px; margin: 12vh auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.bars .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars-labels { display: flex; gap: 4px; }
.bars-labels span { flex: 1; font-size: 10px; color: var(--muted); text-align: center; overflow: hidden; }
.empty { text-align: center; padding: 32px; color: var(--muted); }

@media (max-width: 760px) {
  main { padding: 16px; }
  .topbar { padding: 0 16px; gap: 10px; }
  .brand { display: none; }
  .editor { grid-template-columns: 1fr; }
}
