:root {
  --bg: #f6f7fb; --panel: #ffffff; --ink: #161a26; --muted: #646b7f; --line: #e3e6ef;
  --accent: #4f46e5; --accent-ink: #fff; --ok: #0f9d58; --warn: #b7791f; --err: #d93025;
  --ig: #d62976; --fb: #1877f2; --chip: #eef0f7; --shadow: 0 1px 2px rgba(16,24,40,.06);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1117; --panel: #171a23; --ink: #e8eaf1; --muted: #9aa1b5; --line: #2a2f3d;
          --chip: #222736; --accent: #7c74ff; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
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 10px; } h3 { font-size: 14px; margin: 0 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .logo { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.side a.nav { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.side a.nav:hover { background: var(--chip); text-decoration: none; }
.side a.nav.active { background: var(--accent); color: var(--accent-ink); }
.side .sec { margin: 18px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side .count { margin-left: auto; background: var(--err); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; }
main { padding: 22px 28px 60px; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; } .g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; } .side { position: static; height: auto; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; } main { padding: 16px; }
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line);
           border-radius: var(--radius); padding: 10px 12px; margin-bottom: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a { padding: 6px 12px; color: var(--ink); border-right: 1px solid var(--line); }
.seg a:last-child { border-right: 0; } .seg a.on { background: var(--accent); color: var(--accent-ink); } .seg a:hover { text-decoration: none; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
input[type=text], input[type=url], input[type=password], input[type=number] { min-width: 0; }
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 3px; }
.form-row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.full { width: 100%; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
               padding: 6px 12px; border-radius: 8px; display: inline-flex; gap: 6px; align-items: center; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--err); } button:hover, .btn:hover { filter: brightness(.97); text-decoration: none; }
form.inline { display: inline; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.kpi .v { font-size: 24px; font-weight: 650; } .kpi .l { color: var(--muted); font-size: 12px; }
.delta.up { color: var(--ok); } .delta.down { color: var(--err); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: var(--chip); color: var(--ink); white-space: nowrap; }
.badge.ig { background: color-mix(in srgb, var(--ig) 15%, transparent); color: var(--ig); }
.badge.fb { background: color-mix(in srgb, var(--fb) 15%, transparent); color: var(--fb); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.err { background: color-mix(in srgb, var(--err) 15%, transparent); color: var(--err); }
.badge.p1 { background: var(--err); color: #fff; }
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--line); background: var(--panel); }
.flash.ok { border-left: 4px solid var(--ok); } .flash.warn { border-left: 4px solid var(--warn); }
.flash.error { border-left: 4px solid var(--err); } .flash.info { border-left: 4px solid var(--accent); }
.banner { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; background: color-mix(in srgb, var(--warn) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line)); }
.msg { padding: 10px 12px; border-radius: 10px; background: var(--chip); margin: 6px 0; max-width: 680px; white-space: pre-wrap; }
.msg.brand { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); margin-left: auto; }
.draft { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; margin: 10px 0; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 6px; }
.cal .dow { font-size: 11px; color: var(--muted); text-transform: uppercase; padding: 0 4px; }
.cal .day { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-height: 104px; padding: 6px; overflow: hidden; }
.cal .day.out { opacity: .45; } .cal .day.today { outline: 2px solid var(--accent); }
.cal .day .n { font-size: 11px; color: var(--muted); }
.cal .item { display: block; font-size: 11.5px; padding: 3px 6px; border-radius: 6px; margin-top: 4px; background: var(--chip); color: var(--ink);
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--muted); }
.cal .item.ig { border-left-color: var(--ig); } .cal .item.fb { border-left-color: var(--fb); }
.cal .item:hover { text-decoration: none; filter: brightness(.96); }
@media (max-width: 760px) { .cal { grid-template-columns: 1fr; } .cal .dow, .cal .day.out { display: none; } }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.status-dot.connected { background: var(--ok); } .status-dot.expiring { background: var(--warn); }
.status-dot.expired, .status-dot.permission_error, .status-dot.error { background: var(--err); }
.pre { white-space: pre-wrap; }
details summary { cursor: pointer; color: var(--accent); }
.login { max-width: 360px; margin: 12vh auto; }
.chart-box { position: relative; height: 240px; }
.cap-supported { color: var(--ok); } .cap-conditional { color: var(--warn); } .cap-unsupported { color: var(--err); }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
