/* Overview charts and Log Explorer */

.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-sm { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.compact td, table.compact th { padding: .4em .5em; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: none; padding: .45em .9em; font: inherit; font-size: .88rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--primary-soft); color: var(--primary); }

.kpi {
  display: grid; gap: .15rem; padding: 1rem 1.1rem; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); text-decoration: none !important;
}
.kpi:hover { border-color: var(--primary); }
.kpi-label { display: flex; align-items: center; gap: .45rem; font-weight: 600; color: var(--muted); font-size: .88rem; }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw-critical { background: var(--c-critical); }
.sw-error { background: var(--c-error); }
.sw-warning { background: var(--c-warning); }
.sw-info { background: var(--c-info); }
.delta-bad { color: var(--critical); font-weight: 600; }
.delta-good { color: var(--ok); font-weight: 600; }

.ov-row-1 { grid-template-columns: minmax(0, 2.2fr) minmax(240px, 1fr); margin-top: 1rem; }
.chart { position: relative; min-height: 60px; }
.chart svg { display: block; overflow: visible; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 11px; }
.row-label { fill: var(--text); font-size: 12.5px; }
.row-value { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.track { fill: var(--surface-2); }
.hit { fill: transparent; }
.hit:hover { fill: color-mix(in srgb, var(--primary) 6%, transparent); }
.donut-wrap { display: flex; align-items: center; justify-content: center; gap: 1.2rem; flex-wrap: wrap; }
.donut-track { stroke: var(--surface-2); }
.donut-num { fill: var(--text); font-size: 30px; font-weight: 800; }
.donut-sub { fill: var(--muted); font-size: 12px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin-top: .6rem; font-size: .82rem; color: var(--muted); }
.chart-legend.vertical { flex-direction: column; margin: 0; }
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.chart-legend b { color: var(--text); margin-left: .2rem; }
.chart-legend i, .chart-tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.chart-tip {
  position: fixed; z-index: 200; display: none; pointer-events: none; min-width: 150px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: .55rem .7rem; font-size: .82rem;
}
.chart-tip b { display: block; margin-bottom: .25rem; }
.chart-tip div { display: flex; align-items: center; gap: .45rem; }
.chart-tip div span { margin-left: auto; padding-left: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tip-total { border-top: 1px solid var(--border); margin-top: .25rem; padding-top: .25rem; }

/* ------------------------------------------------------------ log explorer */
.log-filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.log-filters .f-search { flex: 1 1 200px; min-width: 180px; width: auto; }
.log-filters select { width: auto; }
.custom-range { display: inline-flex; gap: .4rem; }
.custom-range input { width: auto; }
.level-toggles { display: inline-flex; gap: .35rem; flex-wrap: wrap; }
.lvl-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.lvl-toggle span {
  display: inline-block; padding: .3em .75em; border-radius: 999px; border: 1px solid var(--border);
  font-size: .82rem; font-weight: 700; cursor: pointer; color: var(--muted); background: var(--surface);
}
.lvl-toggle input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }
.lvl-critical input:checked + span { background: var(--critical-bg); color: var(--critical); border-color: currentColor; }
.lvl-error input:checked + span { background: var(--error-bg); color: var(--error); border-color: currentColor; }
.lvl-warning input:checked + span { background: var(--warning-bg); color: var(--warning); border-color: currentColor; }
.lvl-information input:checked + span { background: var(--info-bg); color: var(--info); border-color: currentColor; }
.result-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .4rem 0; flex-wrap: wrap; }
.pager { display: inline-flex; align-items: center; gap: .5rem; }
.log-table td { font-size: .9rem; }
.th-sort { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: .3rem; font: inherit; color: inherit; white-space: nowrap; }
.th-sort:hover, .th-sort.active { color: var(--primary, #2563eb); }
.th-sort:focus-visible { outline: 2px solid var(--primary, #2563eb); outline-offset: 2px; border-radius: 3px; }
.sort-arrow { font-size: .7rem; opacity: .45; }
.th-sort.active .sort-arrow { opacity: 1; }
.load-more { text-align: center; padding: .9rem 0 .2rem; min-height: 1.5rem; }
.log-row { cursor: pointer; }
.log-row:focus { outline: 2px solid var(--primary); outline-offset: -2px; }
.log-row.lv-critical td:first-child { box-shadow: inset 3px 0 0 var(--c-critical); }
.log-row.lv-error td:first-child { box-shadow: inset 3px 0 0 var(--c-error); }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); z-index: 50; background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: -12px 0 40px rgba(0, 0, 0, .15);
  transform: translateX(105%); transition: transform .2s ease; display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1.2rem; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 1.1rem; }
.drawer-head .icon-btn { font-size: 1.6rem; }
.drawer-body { overflow-y: auto; padding: 1.1rem 1.2rem 2rem; }
.ev-title { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.ev-title h3 { margin: 0; font-size: 1.05rem; }
.compact-kv dt, .compact-kv dd { padding: .3rem .4rem; font-size: .88rem; }
.drawer-body h4 { margin: 1.1rem 0 .4rem; }
.ev-message {
  white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: .75rem; font-family: var(--mono); font-size: .85rem; max-height: 280px; overflow-y: auto; margin: 0;
}
.explain { margin-top: 1rem; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 8px; padding: .4rem 1rem .8rem; background: var(--surface-2); }
.explain-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.explain-head h4 { margin: .7rem 0 .3rem; }
.explain .cause { margin: .3rem 0 .6rem; }
.solution { margin: 0; padding-left: 1.3rem; }
.solution li { margin: .25rem 0; }
.badge { font-size: .75rem; font-weight: 700; padding: .15em .6em; border-radius: 999px; border: 1px solid var(--border); }
.badge-knowledge { background: var(--ok-bg); color: var(--ok); }
.badge-ai { background: var(--info-bg); color: var(--info); }
.badge-general { background: var(--surface); color: var(--muted); }
details.raw { margin-top: 1rem; }
details.raw summary { cursor: pointer; color: var(--primary); font-weight: 600; }

@media (max-width: 1000px) { .ov-row-1 { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ alerts */
.nav-badge { margin-left: auto; min-width: 1.35rem; padding: 0 .4rem; border-radius: 999px; background: var(--critical);
  color: #fff; font-size: .72rem; font-weight: 700; line-height: 1.35rem; text-align: center; }
.dot-new { background: var(--critical); } .dot-ack { background: var(--warning); }
.flash-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.bulk-bar { display: flex; align-items: center; gap: .75rem; padding: .5rem 0 .75rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.bulk-actions { margin-left: auto; display: flex; gap: .4rem; }
label.check { display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; cursor: pointer; }
label.check input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--primary); }
.alert-table td { vertical-align: top; }
.alert-table td:first-child { width: 2rem; padding-top: .9rem; }
.alert-title { display: flex; gap: .5rem; align-items: baseline; font-weight: 600; }
.alert-title a { color: inherit; }
.alert-title a:hover { color: var(--primary); }
.alert-row.st-resolved .alert-title { color: var(--muted); font-weight: 500; }
.alert-row.highlight { background: var(--primary-soft); }
.count-badge { display: inline-block; padding: 0 .45rem; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--border); font-weight: 700; font-variant-numeric: tabular-nums; }
.row-actions { text-align: right; }
.row-actions .btn + .btn { margin-left: .3rem; }
.card > .pager { display: flex; justify-content: flex-end; margin-top: .75rem; }

/* ------------------------------------------------------------- my account */
.section-title { display: flex; align-items: center; gap: .5rem; font-size: 1.15rem; margin: 1.75rem 0 .25rem; }
.channel-card .form { gap: .75rem; }
.level-pick { border: 0; padding: 0; margin: 0; display: flex; gap: 1rem; flex-wrap: wrap; }
.level-pick legend { font-weight: 600; font-size: .9rem; margin-bottom: .4rem; padding: 0; }
.form-actions.start { justify-content: flex-start; }
.channel-actions { display: flex; gap: .5rem; margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.offline-row { align-items: center; justify-content: space-between; }
.mt-s { margin-top: .5rem; }
.spinner { display: inline-block; width: .8rem; height: .8rem; border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; vertical-align: -1px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ------------------------------------------------------------------- admin */
.live-note { display: inline-flex; align-items: center; gap: .4rem; }
.tile-link { color: inherit; text-decoration: none !important; }
.tile-link:hover { border-color: var(--primary); }
.meter-tile { display: grid; gap: .3rem; }
.meter { position: relative; height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: visible; }
.meter span { display: block; height: 100%; border-radius: 999px; background: var(--c-info); transition: width .4s; }
.meter span.over { background: var(--c-critical); }
.meter i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--muted); border-radius: 1px; }
.admin-table td { vertical-align: top; }
.row-actions .inline-form { display: inline-block; margin-left: .25rem; }
.settings-grid { align-items: stretch; }
.settings-grid .card + form, .test-form { margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.grid.tight { gap: .75rem; }
.radio-row { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr; gap: .4rem; }
.radio-row legend { font-weight: 600; font-size: .9rem; margin-bottom: .4rem; padding: 0; }
.radio-card { display: flex !important; gap: .5rem; align-items: flex-start; padding: .6rem .7rem; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-weight: 400 !important; }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio-card > span { display: flex; flex-wrap: wrap; gap: .1rem .5rem; align-items: baseline; }
.radio-card input { width: auto; flex: none; margin: .2rem 0 0; accent-color: var(--primary); }
@media (max-width: 700px) { .radio-row { grid-template-columns: 1fr; } }

/* ----------------------------------------------------------------- reports */
.report-filters { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.segmented .seg { display: inline-flex; cursor: pointer; }
.segmented .seg + .seg { border-left: 1px solid var(--border); }
.segmented .seg input { position: absolute; opacity: 0; pointer-events: none; }
.segmented .seg span { padding: .45em .9em; font-size: .88rem; font-weight: 600; color: var(--muted); }
.segmented .seg input:checked + span { background: var(--primary-soft); color: var(--primary); }
.segmented .seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }
.report { margin-top: 1rem; }
.report-head { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; border-bottom: 2px solid var(--text); padding-bottom: .9rem; }
.report-head h2 { margin: .2rem 0; font-size: 1.5rem; }
.report-head p { margin: 0; }
.report-meta { min-width: 260px; }
.report-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin: 1.1rem 0; }
.rk { display: grid; gap: .15rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.rk b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.rk-critical b { color: var(--critical); } .rk-error b { color: var(--error); }
.rk-warning b { color: var(--warning); } .rk-information b { color: var(--info); }
.report-section { margin-top: 1.4rem; break-inside: avoid-page; }
.report-section h3 { font-size: 1.02rem; margin: 0 0 .5rem; }
.report-table td, .report-table th { padding: .35rem .55rem; font-size: .85rem; }
.report-foot { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: .6rem; }

@media print {
  @page { size: A4; margin: 14mm; }
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --surface-2: #f6f7f9; --text: #111; --muted: #555; --border: #d5d9e0; }
  body { background: #fff !important; }
  .sidebar, .topbar, .no-print, .flash, .toast { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none !important; }
  .report { border: 0 !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important; }
  .table-wrap { overflow: visible !important; }
  .report-table thead { display: table-header-group; }
  .report-table tr { break-inside: avoid; }
  .pill { border: 1px solid currentColor; }
  a { color: inherit; text-decoration: none; }
}
.admin-table .mono.strong, .admin-table td.mono { white-space: nowrap; }
.admin-table .row-actions { min-width: 9rem; }
.admin-table .row-actions .inline-form { margin: .15rem 0 .15rem .25rem; }

/* on/off switch (a styled checkbox) */
.switch-form { margin: 0; }
.switch { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; font-weight: 600; font-size: .9rem; position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 2.6rem; height: 1.45rem; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; top: .18rem; left: .2rem; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track::after { transform: translateX(1.1rem); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch-label { min-width: 1.8rem; }
