:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --line: #e3e6ec;
  --accent: #2f5bd3;
  --pos: #1f8a4c;
  --neg: #c8362e;
  --warn-bg: #fff4e0;
  --warn-text: #8a5300;
  --danger-bg: #fdeceb;
  --chart-fill: rgba(47, 91, 211, .10);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --card: #1b2029;
    --text: #e7eaf0;
    --muted: #949cad;
    --line: #2c3340;
    --accent: #7c9cff;
    --pos: #4cc27f;
    --neg: #ff6b62;
    --warn-bg: #3a2c12;
    --warn-text: #ffcf7a;
    --danger-bg: #3a1a18;
    --chart-fill: rgba(124, 156, 255, .12);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", Arial, sans-serif;
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

.top {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.controls { display: flex; flex-wrap: wrap; gap: 10px; }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--text); padding: 6px 12px; cursor: pointer; font: inherit;
}
.seg button.on { background: var(--accent); color: #fff; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 2px; direction: ltr; text-align: right; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi.main { border-color: var(--accent); border-width: 2px; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; background: var(--warn-bg); color: var(--warn-text); }
.alert.danger { background: var(--danger-bg); color: var(--neg); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.chart svg { width: 100%; height: 240px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num { direction: ltr; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.inactive td { opacity: .45; }
.table-wrap { overflow-x: auto; }
.empty { color: var(--muted); padding: 10px 0; }

.tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.late { color: var(--neg); border-color: var(--neg); }

.tabs { display: flex; gap: 4px; margin: 24px 0 0; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line); border-bottom: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 8px 8px 0 0; cursor: pointer; font: inherit;
}
.tabs button.on { background: var(--card); color: var(--text); font-weight: 600; }
.tabs + .card, .tab { border-top-right-radius: 0; }

input, select, button { font: inherit; color: var(--text); }
input, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0;
}
input[type=number] { width: 120px; }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button.ghost, button.link { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.link { border: 0; padding: 2px 6px; }
button.link.danger { color: var(--neg); }

.row-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.row-form .small { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.row-form.editing { background: var(--warn-bg); padding: 10px; border-radius: 8px; }

.conn { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.conn-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.conn-head .title { font-weight: 600; }
.conn .err { color: var(--neg); font-size: 13px; margin-top: 6px; }
.conn ul { list-style: none; padding: 0; margin: 8px 0 0; }
.conn li { display: flex; gap: 10px; justify-content: space-between; padding: 4px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-inline-end: 4px; }
.dot.ok { background: var(--pos); }
.dot.error { background: var(--neg); }
.dot.run { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }
.sync-log { margin-top: 12px; font-size: 12px; color: var(--muted); max-height: 160px; overflow: auto; }
#sync-all[disabled] { opacity: .6; cursor: default; }

.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }
.login form { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.login h1 { text-align: center; margin-bottom: 8px; }
.login input, .login button { padding: 10px 12px; font-size: 16px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; z-index: 20;
}

@media (max-width: 600px) {
  .top { padding: 12px 16px; }
  input[type=number] { width: 100px; }
  .kpi .value { font-size: 20px; }
}
