:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --info: #2563eb;
  --sidebar-w: 240px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 8px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; word-break: break-all; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.small, small { font-size: 12px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.wrap { min-width: 160px; max-width: 260px; }
.big { font-size: 20px; }
.t-ok { color: var(--ok); } .t-bad { color: var(--bad); } .t-warn { color: var(--warn); } .t-info { color: var(--info); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: #0f172a; color: #cbd5e1;
  display: flex; flex-direction: column; z-index: 30; transition: width .2s, transform .2s; overflow-x: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; color: #fff; font-weight: 600; white-space: nowrap; }
.brand img { border-radius: 6px; background: #fff; flex: none; }
.sidebar nav { flex: 1; padding: 6px 8px; overflow-y: auto; }
.sidebar nav a, .logout button {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 2px; border-radius: 8px;
  color: #cbd5e1; white-space: nowrap; font: inherit; width: 100%; background: none; border: 0; cursor: pointer; text-align: left;
}
.sidebar nav a:hover, .logout button:hover { background: #1e293b; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar svg { flex: none; }
.logout { padding: 8px; border-top: 1px solid #1e293b; }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; transition: margin-left .2s; }
body.collapsed .sidebar { width: 64px; }
body.collapsed .sidebar span, body.collapsed .brand-text { display: none; }
body.collapsed .main { margin-left: 64px; }
.sidebar-backdrop { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-spacer { flex: 1; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--text); display: inline-flex; }
.icon-btn:hover { background: var(--bg); }
.mode { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; letter-spacing: .04em; }
.mode-live { background: #dcfce7; color: #166534; }
.mode-test { background: #fef3c7; color: #92400e; }
.mode-unknown { background: #fee2e2; color: #991b1b; }
.range { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.range-sep { color: var(--muted); }
.content { padding: 20px; max-width: 1500px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin: 24px 0 8px; }

/* Controls */
input, select, button { font: inherit; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], input:not([type]), select {
  height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); min-width: 0;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Cards & panels */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.card strong { font-size: 22px; font-weight: 700; }
.card small { color: var(--muted); }
.card-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.card-accent { border-color: #bfdbfe; background: linear-gradient(180deg, #eff6ff, #fff); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.panel-error { border-color: #fecaca; background: #fef2f2; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.panel-wide { grid-column: 1 / -1; }
.chart-box { position: relative; height: 300px; }
.detail-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.detail-head > div { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.filters label.grow { flex: 1 1 240px; }
.filters label.check { flex-direction: row; align-items: center; height: 36px; font-weight: 500; color: var(--text); }
.filters input[type=number] { width: 110px; }
.filter-actions { display: flex; gap: 8px; }
.export-btns { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.sub > td { background: #f8fafc; padding: 12px 16px; }
tr.sub table { background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.empty { color: var(--muted); text-align: center; padding: 28px 10px; margin: 0; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pager span { color: var(--muted); margin-right: auto; font-size: 13px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-bad { background: #fee2e2; color: #991b1b; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-muted { background: #f1f5f9; color: #475569; }

/* Definition lists */
.dl { margin: 0; display: grid; gap: 0; }
.dl > div { display: grid; grid-template-columns: 180px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
.steps { padding-left: 20px; margin: 0 0 8px; }
.steps li { margin-bottom: 6px; }

/* Alerts & loading */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.loading { position: fixed; inset: 0; background: rgba(244, 246, 251, .7); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; z-index: 50; color: var(--muted); }
.loading[hidden] { display: none; }
.spinner { width: 36px; height: 36px; border: 3px solid #cbd5e1; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 10px 30px rgba(15, 23, 42, .08); padding: 32px 28px; width: 100%; max-width: 400px; text-align: center; }
.login-card h1 { margin: 12px 0 2px; font-size: 22px; }
.login-card p { margin: 0 0 18px; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.login-card input { height: 40px; }
.login-card .alert { text-align: left; }

/* Responsive */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 900px) {
  .sidebar, body.collapsed .sidebar { width: var(--sidebar-w); transform: translateX(-100%); }
  body.collapsed .sidebar span, body.collapsed .brand-text { display: inline; }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .4); z-index: 25; }
  .main, body.collapsed .main { margin-left: 0; }
  .topbar { padding: 10px 16px; }
  .topbar-spacer { display: none; }
  .range { width: 100%; }
  .range input[type=date] { flex: 1 1 120px; }
  .content { padding: 16px; }
  .dl > div { grid-template-columns: 1fr; gap: 0; }
  .chart-box { height: 240px; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card strong { font-size: 17px; }
  .filters label, .filters label.grow { flex: 1 1 100%; }
  .filters input[type=number] { width: 100%; }
  .range .preset { flex: 1 1 100%; }
}

/* Events CMS forms */
input[type=time], input[type=datetime-local], input[type=email], input[type=url], input[type=tel], textarea {
  height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); min-width: 0; font: inherit;
}
textarea { height: auto; min-height: 160px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-grid label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: 1 / -1; }
.form-grid label.check, .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); font-size: 13px; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.field-err { color: var(--bad); font-weight: 500; }
.cover-preview { max-width: 320px; border-radius: 8px; border: 1px solid var(--border); display: block; margin-bottom: 6px; }
.q-table input, .q-table select { width: 100%; }
.q-table td { vertical-align: middle; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; z-index: 5; }
details.inline { display: inline-block; }
details.inline summary { cursor: pointer; color: var(--bad); font-size: 12px; list-style: none; }
details.inline summary::-webkit-details-marker { display: none; }
details.inline[open] summary { margin-bottom: 4px; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.inline-form { display: inline; margin: 0; }
@media (max-width: 900px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
}
