:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e6e8ec; --text: #1f2937; --muted: #6b7280;
  --accent: #1f2937; --accent-soft: #eef0f3; --green: #15803d; --red: #b91c1c; --amber: #b45309;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 16px; font-weight: 600; margin: 0; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; letter-spacing: .2px; }
.mark { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); position: relative; }
.mark::after { content: ""; position: absolute; left: 10px; top: 3px; width: 2px; height: 16px; background: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card .brand { justify-content: center; margin-bottom: 8px; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
nav { display: grid; gap: 2px; }
nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; }
nav a:hover { background: var(--accent-soft); color: var(--text); }
nav a.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.sidebar-footer { margin-top: auto; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.sidebar-footer a:hover { color: var(--text); }
.whoami { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.main { padding: 28px 36px; max-width: 1280px; width: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* cards */
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.stat .line { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); } .neg { color: var(--red); }

/* charts */
.chart-head { display: flex; justify-content: space-between; align-items: center; margin: 20px 0 10px; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 14px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.sw.pos { background: var(--green); } .sw.neg { background: var(--red); }
.pills { display: flex; gap: 4px; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; color: var(--muted); cursor: pointer; border: 1px solid var(--line); }
.pill.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chart-item { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.chart-item:last-child { border-bottom: 0; }
.chart-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-row: span 2; }
.chart-item:has(.bar-row:only-of-type) .chart-label { grid-row: span 1; }
.bar-row { display: flex; align-items: center; gap: 8px; height: 14px; }
.bar { height: 8px; border-radius: 4px; min-width: 2px; opacity: .85; }
.bar.pos { background: var(--green); } .bar.neg { background: var(--red); }
.bar-val { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; max-width: 320px; }
td.muted, .muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.row-actions a { color: var(--muted); margin-left: 10px; cursor: pointer; font-size: 13px; }
.row-actions a:hover { color: var(--text); }
.row-actions a.danger:hover { color: var(--red); }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--accent-soft); color: var(--text); }
.badge.ok { background: #dcfce7; color: var(--green); }
.badge.off { background: #fee2e2; color: var(--red); }
.badge.warn { background: #fef3c7; color: var(--amber); }

/* forms */
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #9ca3af; box-shadow: 0 0 0 3px rgba(31,41,55,.08); }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }
.filters { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.filters label { min-width: 130px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span { grid-column: 1 / -1; }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.hint { font-size: 12px; color: var(--muted); }

.btn { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; }
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #111827; }
.btn.full { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
button.icon { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

.error { color: var(--red); font-size: 13px; min-height: 18px; margin: 0; }
.notice { background: #fef3c7; color: var(--amber); border: 1px solid #fde68a; padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; padding: 22px 24px; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 60; }
.toast.err { background: var(--red); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { display: flex; flex-wrap: wrap; }
  .sidebar-footer { margin-left: auto; flex-direction: row; display: flex; gap: 14px; }
  .main { padding: 20px; }
  .form-grid { grid-template-columns: 1fr; }
}
