:root{
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: rgba(15, 23, 42, .62);
  --border: #e6e8f0;
  --blue: #2563eb;
  --blue2: #1d4ed8;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --shadow: 0 10px 25px rgba(2, 6, 23, .08);
  --radius: 18px;
}

*{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 30% 0%, #eaf0ff, transparent),
              radial-gradient(900px 500px at 85% 20%, #f3e8ff, transparent),
              var(--bg);
}

.app{
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: rgba(255,255,255,.75);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand{
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  display: block;
}
.title{
  font-weight: 800;
  font-size: 18px;
  line-height: 1.05;
}
.subtitle{
  font-size: 13px;
  color: var(--muted);
}

.status{
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}
.dot{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #94a3b8;
}
.dot.idle{ background:#94a3b8; }
.dot.busy{ background: var(--amber); }
.dot.ok{ background: var(--green); }
.dot.warn{ background: var(--amber); }
.dot.error{ background: var(--red); }

.layout{
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 14px;
  align-items: start;
}

.card{
  background: rgba(255,255,255,.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel{
  padding: 16px;
}

.content{
  padding: 16px;
}

h2{
  margin: 0 0 12px 0;
  font-size: 16px;
}

h3{
  margin: 0;
  font-size: 14px;
}

.subtitleSmall{
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.grid{
  display: grid;
  gap: 14px;
}

.field{
  display: grid;
  gap: 8px;
}
.label{
  font-size: 12px;
  color: var(--muted);
}

select, input[type="date"], textarea{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  background: white;
}
select:focus, input[type="date"]:focus, textarea:focus{
  border-color: rgba(37,99,235,.55);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}

.segmented{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
#typeSegment.segmented{
  grid-template-columns: repeat(3, 1fr);
}
.seg{
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
  padding: 9px 10px;
  font-size: 13px;
  cursor: pointer;
  color: rgba(15, 23, 42, .78);
}
.seg.active{
  border-color: rgba(37,99,235,.45);
  background: rgba(37,99,235,.10);
  color: var(--blue2);
  font-weight: 700;
}

.range{
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.dash{ color: var(--muted); }

.actionsRow{
  display: flex;
  gap: 10px;
}

.btn{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn.primary{
  border-color: rgba(37,99,235,.35);
  background: linear-gradient(135deg, rgba(37,99,235,.95), rgba(124,58,237,.95));
  color: white;
  font-weight: 700;
}
.btn.secondary{
  background: white;
}
.btn:active{
  transform: translateY(1px);
}

.hint{
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.divider{
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.kpis{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.kpi{
  background: rgba(15,23,42,.03);
  border: 1px solid rgba(15,23,42,.06);
  border-radius: 14px;
  padding: 10px 12px;
}
.kpiLabel{
  font-size: 12px;
  color: var(--muted);
}
.kpiValue{
  margin-top: 6px;
  font-weight: 800;
  font-size: 16px;
}

.contentHeader{
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.legend{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.chip{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: rgba(15,23,42,.75);
  background: white;
}
.swatch{
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--blue);
}

.chartWrap{
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: white;
}
canvas{
  width: 100%;
  height: auto;
  display: block;
}

.tableHeader{
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.tableWrap{
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: auto;
  background: white;
  max-height: 320px;
}

table{
  width: 100%;
  border-collapse: collapse;
}
thead th{
  position: sticky;
  top: 0;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  padding: 10px 12px;
}
tbody td{
  padding: 10px 12px;
  border-bottom: 1px solid rgba(230,232,240,.7);
  font-size: 13px;
}
tbody tr:hover{
  background: rgba(37,99,235,.06);
}

.tech summary{
  cursor: pointer;
  color: rgba(15,23,42,.75);
  font-size: 13px;
}
.tech{
  margin-top: 4px;
}
.tech .field{
  margin-top: 10px;
}

.checks{
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  background: white;
}
.check{
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 2px;
}
.check input[type="checkbox"]{
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--blue);
}
#typeChecks{
  flex-direction: row;
  gap: 14px;
  max-height: none;
}
.modalSelects{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

/* --------- Модалка --------- */
.modalBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,.48);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 100;
}
.modalBackdrop.hidden{
  display: none;
}
.modal{
  width: min(760px, 96vw);
  padding: 14px;
}
.modalHeader{
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 10px 10px 10px;
}
.modalTitle{
  font-weight: 900;
  font-size: 16px;
}
.iconBtn{
  border: 1px solid var(--border);
  background: white;
  border-radius: 12px;
  width: 40px;
  height: 40px;
  cursor: pointer;
}
.modalBody{
  padding: 0 10px 10px 10px;
}
textarea{
  width: 100%;
  min-height: 260px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
.modalFooter{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 10px 10px;
}
.spacer{ flex: 1; }

/* Адаптив */
@media (max-width: 980px){
  .layout{
    grid-template-columns: 1fr;
  }
}
