:root {
  --bg: #eef1f6;
  --bg-2: #e7ebf2;
  --panel: #ffffff;
  --panel-2: #f5f7fb;
  --border: #e2e6ee;
  --border-soft: #edf0f5;
  --text: #1e2a3a;
  --muted: #5b6b82;
  --muted-2: #90a0b6;
  --accent: #2563eb;
  --accent-2: #1e40af;
  --accent-soft: #eaf1ff;
  --teal: #0d9488;
  --green: #16a34a;
  --green-soft: #e8f6ee;
  --amber: #d97706;
  --amber-soft: #fdf3e6;
  --red: #dc2626;
  --red-soft: #fdecec;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow: 0 4px 16px rgba(16,24,40,.08), 0 2px 6px rgba(16,24,40,.05);
  --radius: 14px;
  --mono: 'SF Mono', ui-monospace, 'JetBrains Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 500px at 12% -8%, rgba(37,99,235,.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 5px 14px rgba(37,99,235,.30);
  color: #fff; font-size: 20px;
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: .2px; font-weight: 700; }
.brand p { margin: 0; font-size: 11.5px; color: var(--muted); }

.sources { display: flex; gap: 10px; margin-left: auto; }
.source {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 13px; border-radius: 10px;
  background: var(--green-soft); border: 1px solid #cfe9da;
  font-size: 11.5px;
}
.source .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.15); animation: pulse 2s infinite; }
.source .s-name { font-weight: 650; color: #157a3c; }
.source .s-kind { color: #4e9e6f; font-size: 10.5px; }

.clock { font-family: var(--mono); font-size: 12px; color: var(--muted); padding-left: 14px; border-left: 1px solid var(--border); }

/* ---------- Pipeline strip ---------- */
.pipeline {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
  padding: 18px 24px 6px; align-items: stretch;
}
.agent {
  position: relative; display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border: 1px solid var(--border);
  background: var(--panel); border-radius: 12px; margin-right: 26px;
  box-shadow: var(--shadow-sm);
  transition: border-color .3s, box-shadow .3s, transform .3s;
}
.agent:last-child { margin-right: 0; }
.agent::after {
  content: '→'; position: absolute; right: -22px; top: 50%; transform: translateY(-50%);
  color: var(--muted-2); font-size: 18px;
}
.agent:last-child::after { content: none; }
.agent .a-icon {
  width: 40px; height: 40px; flex: none; border-radius: 10px;
  display: grid; place-items: center; font-size: 20px;
  background: var(--panel-2); border: 1px solid var(--border);
}
.agent .a-name { font-weight: 700; font-size: 13.5px; }
.agent .a-role { color: var(--muted); font-size: 11.5px; }
.agent .a-detail { color: var(--muted-2); font-size: 10.5px; margin-top: 2px; }
.agent .a-status {
  margin-top: 8px; display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: #eef1f6; color: var(--muted);
}
.agent .a-status .sdot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); }

.agent.working { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 22px rgba(37,99,235,.15); }
.agent.working .a-icon { border-color: var(--accent); background: var(--accent-soft); }
.agent.working .a-status { background: var(--accent-soft); color: var(--accent-2); }
.agent.working .a-status .sdot { background: var(--accent); animation: pulse 1s infinite; }
.agent.done { border-color: #bfe6cd; }
.agent.done .a-icon { background: var(--green-soft); border-color: #bfe6cd; }
.agent.done .a-status { background: var(--green-soft); color: #157a3c; }
.agent.done .a-status .sdot { background: var(--green); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- Run bar ---------- */
.runbar { display: flex; align-items: center; gap: 14px; padding: 12px 24px 14px; }
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 11px 18px; border-radius: 11px; font-size: 13.5px; font-weight: 650;
  cursor: pointer; transition: transform .12s, background .2s, border-color .2s, box-shadow .2s;
  font-family: var(--sans); box-shadow: var(--shadow-sm);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff;
  box-shadow: 0 6px 18px rgba(37,99,235,.28);
}
.btn.ghost { background: var(--panel); }
.run-meta { color: var(--muted); font-size: 12px; }
.run-meta b { color: var(--text); }

.progress { flex: 1; height: 6px; background: var(--bg-2); border-radius: 10px; overflow: hidden; max-width: 340px; }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--teal)); transition: width .4s; }

/* ---------- Main grid ---------- */
.main {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 380px;
  gap: 16px; padding: 4px 24px 28px; flex: 1;
}
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
.panel > .head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 15px; border-bottom: 1px solid var(--border-soft);
}
.panel > .head h2 { font-size: 12px; margin: 0; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 700; }
.panel > .head .count { font-size: 11px; color: var(--muted-2); font-family: var(--mono); }

/* ---------- Procurement feed ---------- */
.feed { max-height: 640px; overflow-y: auto; }
.pcard {
  padding: 13px 15px; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; transition: background .18s; position: relative;
  animation: slidein .4s ease;
}
@keyframes slidein { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.pcard:hover { background: var(--panel-2); }
.pcard.active { background: var(--accent-soft); }
.pcard.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.pcard .p-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.badge { font-size: 10px; padding: 2px 7px; border-radius: 6px; font-weight: 700; letter-spacing: .3px; }
.badge.law44 { background: var(--accent-soft); color: var(--accent-2); }
.badge.law223 { background: #f0ebff; color: #6d28d9; }
.pcard .reg { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.pcard .p-title { font-size: 12.5px; font-weight: 650; line-height: 1.35; margin-bottom: 6px; }
.pcard .p-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px; color: var(--muted); }
.pcard .p-meta .nmck { color: var(--teal); font-weight: 700; font-family: var(--mono); }
.rel { margin-left: auto; font-size: 10.5px; font-family: var(--mono); color: var(--muted-2); display: flex; align-items: center; gap: 5px; }
.rel .relbar { width: 34px; height: 4px; border-radius: 4px; background: var(--bg-2); overflow: hidden; }
.rel .relbar i { display: block; height: 100%; background: var(--green); }

/* ---------- Detail ---------- */
.empty { padding: 64px 20px; text-align: center; color: var(--muted-2); }
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .7; }

.detail { padding: 18px 20px; }
.detail .d-law { margin-bottom: 10px; display: flex; align-items: center; gap: 10px; }
.detail h2.d-title { font-size: 18px; margin: 0 0 14px; line-height: 1.3; font-weight: 700; }
.d-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 22px; margin-bottom: 20px; }
.d-item .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted-2); }
.d-item .v { font-size: 13px; margin-top: 2px; }
.d-item .v.big { font-size: 17px; font-weight: 700; color: var(--teal); font-family: var(--mono); }

.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  font-weight: 700; margin: 22px 0 10px; display: flex; align-items: center; gap: 9px;
}
.section-title .n { font-family: var(--mono); font-size: 11px; color: var(--muted-2); font-weight: 400; letter-spacing: 0; text-transform: none; }
.section-title::before { content: ''; width: 3px; height: 14px; border-radius: 3px; background: var(--accent); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
table.tbl th {
  text-align: left; padding: 8px 10px; color: var(--muted-2);
  font-weight: 650; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
}
table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
table.tbl tbody tr:hover { background: var(--panel-2); }
table.tbl td.num, table.tbl th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
table.tbl .prod { font-weight: 650; }
table.tbl .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.reestr-tag { font-size: 10px; font-family: var(--mono); color: #157a3c; background: var(--green-soft); padding: 1px 6px; border-radius: 5px; }
.reestr-tag.none { color: var(--amber); background: var(--amber-soft); }

/* ---------- Money / decision ---------- */
.money { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-top: 16px; }
.mbox { background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px; }
.mbox .k { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .5px; }
.mbox .v { font-size: 16px; font-weight: 700; font-family: var(--mono); margin-top: 4px; }
.mbox.accent { background: var(--accent-soft); border-color: #cfe0ff; }
.mbox.accent .v { color: var(--accent-2); }
.mbox.good { background: var(--green-soft); border-color: #cfe9da; }
.mbox.good .v { color: #157a3c; }

.verdict { margin-top: 18px; padding: 14px 16px; border-radius: 12px; display: flex; gap: 13px; align-items: flex-start; }
.verdict .vicon { font-size: 22px; }
.verdict .vt { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.verdict .vd { font-size: 12px; color: var(--muted); line-height: 1.5; }
.verdict.go { background: var(--green-soft); border: 1px solid #bfe6cd; }
.verdict.go .vt { color: #157a3c; }
.verdict.tight { background: var(--amber-soft); border: 1px solid #f3ddb8; }
.verdict.tight .vt { color: #b45309; }
.verdict.skip { background: var(--red-soft); border: 1px solid #f5cccc; }
.verdict.skip .vt { color: var(--red); }

.actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- Telegram preview ---------- */
.phone {
  background: #ffffff; border: 1px solid var(--border); border-radius: 18px;
  overflow: hidden; box-shadow: var(--shadow);
}
.phone .tg-head {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  background: #f8fafc; border-bottom: 1px solid var(--border);
}
.phone .tg-av { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent-2)); display: grid; place-items: center; font-size: 16px; }
.phone .tg-name { font-weight: 700; font-size: 13px; }
.phone .tg-sub { font-size: 11px; color: var(--green); }
.tg-body {
  padding: 16px 12px; min-height: 300px; max-height: 560px; overflow-y: auto;
  background:
    linear-gradient(180deg, #eef2f8, #e9eef5);
}
.tg-msg {
  background: #ffffff; border-radius: 12px 12px 12px 4px; padding: 12px 13px;
  max-width: 100%; font-size: 12.5px; line-height: 1.5; animation: slidein .35s ease;
  box-shadow: 0 2px 8px rgba(16,24,40,.08); border: 1px solid #eceff4;
}
.tg-msg + .tg-msg { margin-top: 10px; }
.tg-msg .title { font-weight: 700; margin-bottom: 6px; color: var(--text); }
.tg-msg .kv { display: flex; gap: 6px; margin: 2px 0; }
.tg-msg .kv .kk { color: var(--muted); min-width: 78px; }
.tg-msg .list { margin: 8px 0; padding-left: 0; list-style: none; }
.tg-msg .list li { padding: 4px 0; border-top: 1px solid #eef1f5; }
.tg-msg .list li:first-child { border-top: none; }
.tg-msg .list .pn { font-weight: 650; }
.tg-msg .list .pp { color: var(--teal); font-family: var(--mono); float: right; }
.tg-msg .total { margin-top: 10px; padding-top: 9px; border-top: 1px solid #e6eaf0; font-weight: 700; }
.tg-msg .total .cyan { color: var(--teal); font-family: var(--mono); }
.tg-msg .tag { display: inline-block; margin-top: 8px; font-size: 11px; padding: 3px 9px; border-radius: 6px; font-weight: 650; }
.tg-msg .tag.go { background: var(--green-soft); color: #157a3c; }
.tg-msg .tag.tight { background: var(--amber-soft); color: #b45309; }
.tg-msg .tag.skip { background: var(--red-soft); color: var(--red); }
.tg-msg .time { text-align: right; font-size: 10px; color: var(--muted-2); margin-top: 6px; }
.tg-empty { text-align: center; color: var(--muted-2); padding: 60px 20px; font-size: 12px; }

/* ---------- Log ---------- */
.log { font-family: var(--mono); font-size: 11px; max-height: 220px; overflow-y: auto; padding: 12px 14px; background: #fbfcfe; }
.log .line { padding: 2px 0; color: var(--muted); animation: slidein .3s ease; }
.log .line .ts { color: var(--muted-2); }
.log .line .ag { color: var(--accent); font-weight: 650; }
.log .line.ok { color: #157a3c; }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cdd5e2; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #b6c1d2; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1180px) {
  .main { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: 1fr 1fr; gap: 12px; }
  .agent { margin-right: 0; }
  .agent::after { content: none; }
}
