:root {
  --bg: #0f1419;
  --panel: #1a2028;
  --panel-2: #232b35;
  --border: #2d3743;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #d9a441;
  --accent-2: #4a9eda;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 340px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.brand { color: var(--accent); }

/* ---- Layout ---- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; }
.sidebar .logo { font-weight: 700; font-size: 16px; padding: 8px 10px 16px; }
.sidebar nav a {
  display: block; padding: 9px 12px; border-radius: 6px; color: var(--text);
  margin-bottom: 2px; font-size: 14px;
}
.sidebar nav a:hover { background: var(--panel-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: #1a1204; font-weight: 600; }
.sidebar .user-box { margin-top: 24px; padding: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.sidebar .role-chip { display: inline-block; background: var(--panel-2); border: 1px solid var(--border); border-radius: 20px; padding: 2px 8px; margin-top: 6px; color: var(--text); }

.main { padding: 24px 28px; overflow: auto; }
.main h2 { margin: 0 0 4px; }
.page-sub { color: var(--muted); margin-bottom: 20px; }

/* ---- Components ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card .v { font-size: 28px; font-weight: 700; margin-top: 6px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.panel h3 { margin: 0 0 14px; font-size: 15px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: rgba(255,255,255,0.02); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.online { background: rgba(63,185,80,.15); color: var(--green); }
.badge.offline { background: rgba(139,152,165,.15); color: var(--muted); }
.badge.pending, .badge.sent { background: rgba(210,153,34,.15); color: var(--yellow); }
.badge.acked { background: rgba(63,185,80,.15); color: var(--green); }
.badge.failed { background: rgba(248,81,73,.15); color: var(--red); }
.badge.info { background: rgba(74,158,218,.15); color: var(--accent-2); }
.badge.warning { background: rgba(210,153,34,.15); color: var(--yellow); }
.badge.error { background: rgba(248,81,73,.15); color: var(--red); }

button, .btn {
  background: var(--accent); color: #1a1204; border: none; border-radius: 6px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.secondary, .btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--red); color: #fff; }
button.small { padding: 5px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 9px 11px; font-size: 14px; margin-bottom: 12px; font-family: inherit;
}
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 4px; }

.error-text { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.code-box { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: 420px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal h3 { margin: 0 0 16px; }

.hidden { display: none !important; }
.spinner { color: var(--muted); padding: 20px 0; }
canvas { max-width: 100%; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 10px; }
.metric-item { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; }
.metric-item .k { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.metric-item .v { font-size: 18px; font-weight: 600; margin-top: 3px; }

/* ---- Dashboard ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  position: relative; background: linear-gradient(160deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; overflow: hidden;
}
.kpi::after { content: ''; position: absolute; inset: 0 0 auto auto; width: 120px; height: 120px;
  background: radial-gradient(circle at top right, rgba(217,164,65,.14), transparent 70%); pointer-events: none; }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-icon { font-size: 20px; line-height: 1; opacity: .9; }
.kpi .kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi .kpi-value { font-size: 32px; font-weight: 700; margin-top: 10px; letter-spacing: -.5px; }
.kpi .kpi-value small { font-size: 16px; font-weight: 600; color: var(--muted); }
.kpi .kpi-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi.accent { border-color: rgba(217,164,65,.4); }
.kpi.good .kpi-value { color: var(--green); }
.kpi.warn .kpi-value { color: var(--yellow); }
.kpi.bad .kpi-value { color: var(--red); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.panel h3 .panel-sub { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.panel-head h3 { margin: 0; }

/* Bar chart (7-day activity) */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 8px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar { width: 70%; max-width: 34px; min-height: 3px; border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--accent), rgba(217,164,65,.35)); transition: height .3s ease; }
.bars .bar-lbl { font-size: 11px; color: var(--muted); }
.bars .bar-val { font-size: 11px; color: var(--text); font-weight: 600; min-height: 14px; }

/* Donut + legend */
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { position: relative; width: 120px; height: 120px; flex: none; }
.donut .donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut .donut-center .n { font-size: 22px; font-weight: 700; }
.donut .donut-center .l { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend .li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .li .lv { margin-left: auto; font-weight: 600; color: var(--muted); }

/* Attention list */
.attn-item { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px; background: var(--bg); }
.attn-item .who { min-width: 0; }
.attn-item .who .s { font-weight: 600; }
.attn-item .who .n { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attn-item .reasons { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.empty-good { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 8px 2px; }

.feed { display: flex; flex-direction: column; }
.feed .fi { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.feed .fi:last-child { border-bottom: none; }
.feed .fi .fi-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.feed .fi .fi-main { min-width: 0; flex: 1; }
.feed .fi .fi-type { font-size: 13px; }
.feed .fi .fi-meta { font-size: 11px; color: var(--muted); }
.feed .fi .fi-when { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Remote screen mirroring */
.remote-stage { display: flex; justify-content: center; background: #0b0b0b; border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.remote-canvas { max-height: 70vh; width: auto; background: #000; border-radius: 4px; cursor: crosshair; touch-action: none; }
.remote-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.remote-canvas:focus { outline: 2px solid var(--accent, #4f8cff); outline-offset: 2px; }
.remote-warn { background: #3a2a00; color: #ffcf66; border: 1px solid #6b5200; border-radius: 6px; padding: 8px 10px; font-size: 12px; margin-bottom: 10px; }
