:root {
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #172031;
  --line: #222c3d;
  --line-soft: #1b2432;
  --text: #e6ebf5;
  --muted: #8b98ad;
  --dim: #5f6b80;
  --accent: #4f8cff;
  --accent-2: #7b5cff;
  --green: #2fbf71;
  --red: #ef5350;
  --amber: #f5a623;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.55 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; font-weight: 600; }

.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

/* ------------------------------------------------------------------ sidebar */
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 22px 16px 16px;
  background: linear-gradient(180deg, #10151f, #0c1017 70%);
  border-right: 1px solid var(--line-soft);
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 6px 22px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 700; font-size: 18px; color: #fff;
  box-shadow: 0 6px 18px rgba(79, 140, 255, .35);
}
.brand-name { font-weight: 600; font-size: 15px; }
.brand-sub { color: var(--dim); font-size: 11px; letter-spacing: .04em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 10px; color: #b6c1d4; font-size: 14px;
}
.nav a:hover { background: #17203180; text-decoration: none; color: #fff; }
.nav a.active { background: #1a2436; color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.nav .ico { width: 18px; text-align: center; color: var(--dim); font-size: 13px; }
.nav a.active .ico { color: var(--accent); }
.pill {
  margin-left: auto; min-width: 20px; text-align: center; padding: 1px 6px;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600;
}
.pill:empty { display: none; }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.agent-status {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted);
  padding: 6px 4px 12px;
}
.agent-status .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 191, 113, .15);
}
.agent-status.busy .dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(245, 166, 35, .18); animation: pulse 1.4s infinite; }
.agent-status.off .dot { background: var(--dim); box-shadow: none; }
@keyframes pulse { 50% { opacity: .35; } }
.user-row { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--dim); }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12.5px; padding: 0; }
.link-btn:hover { color: #fff; }

/* --------------------------------------------------------------------- main */
.main { min-width: 0; padding: 26px 34px 60px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 26px; }
.topbar h1 { font-size: 24px; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.view { display: flex; flex-direction: column; gap: 18px; max-width: 1180px; }

/* -------------------------------------------------------------------- cards */
.card {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 15px; }
.card-head .muted { font-size: 12.5px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); font-size: 12.5px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }
.kpi .value { font-size: 28px; font-weight: 650; margin-top: 4px; letter-spacing: -.03em; }
.kpi .hint { color: var(--dim); font-size: 12px; margin-top: 2px; }

.banner {
  display: flex; gap: 14px; align-items: center; padding: 14px 18px; border-radius: 12px;
  background: linear-gradient(90deg, rgba(245,166,35,.12), rgba(245,166,35,.03));
  border: 1px solid rgba(245, 166, 35, .3); font-size: 13.5px;
}
.banner .b-title { font-weight: 600; }
.banner .b-actions { margin-left: auto; display: flex; gap: 8px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; transition: .15s;
}
.btn:hover { border-color: #33415a; background: #1c2739; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #3f6fe0); border-color: transparent; color: #fff; font-weight: 550; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.green { background: rgba(47,191,113,.14); border-color: rgba(47,191,113,.35); color: #7ee2ab; }
.btn.danger { background: rgba(239,83,80,.1); border-color: rgba(239,83,80,.35); color: #ff9d9a; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: #fff; background: #1a2436; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }

/* ------------------------------------------------------------------- inputs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
input, select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: #0d121c; color: var(--text); font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.14); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
textarea.code { font-family: "JetBrains Mono", Consolas, monospace; font-size: 13px; min-height: 320px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.inline { display: flex; gap: 10px; align-items: center; }

/* -------------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 500; color: var(--dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #151d2b; }
td .title { font-weight: 500; color: #e9eef8; }
td .small { color: var(--dim); font-size: 12px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.draft { background: #1d2637; color: #a9b7cd; border-color: #2a3648; }
.badge.approved { background: rgba(79,140,255,.12); color: #8fb6ff; border-color: rgba(79,140,255,.3); }
.badge.published, .badge.ok { background: rgba(47,191,113,.12); color: #7ee2ab; border-color: rgba(47,191,113,.28); }
.badge.failed, .badge.error { background: rgba(239,83,80,.12); color: #ff9d9a; border-color: rgba(239,83,80,.28); }
.badge.rejected, .badge.skipped { background: #1a1f2a; color: #6f7b8f; border-color: #262f3f; }
.badge.new { background: rgba(123,92,255,.12); color: #b9a4ff; border-color: rgba(123,92,255,.3); }

/* --------------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 7px 13px; border-radius: 9px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px;
}
.tab:hover { color: #fff; }
.tab.active { background: #1a2436; color: #fff; border-color: var(--line); }

/* ------------------------------------------------------------------- charts */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 110px; padding-top: 8px; }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.chart .bar {
  width: 100%; max-width: 44px; border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--accent), #2f5fb0); min-height: 3px;
}
.chart .bar.zero { background: #1c2432; }
.chart .bar-label { font-size: 11px; color: var(--dim); }

/* -------------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 8, 13, .72); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 28px; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(920px, 100%); max-height: 90vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
}
.modal-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding: 18px 22px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--line-soft); position: sticky; bottom: 0; background: var(--panel); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; display: flex; gap: 8px; }

/* ------------------------------------------------------------------- toasts */
.toast-wrap { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast {
  padding: 11px 15px; border-radius: 10px; background: #172031; border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0,0,0,.4); font-size: 13.5px; max-width: 380px;
  animation: slide-in .2s ease-out;
}
.toast.ok { border-color: rgba(47,191,113,.4); }
.toast.err { border-color: rgba(239,83,80,.45); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------------- switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #263143; border-radius: 999px; cursor: pointer; transition: .2s;
}
.switch span::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  left: 3px; top: 3px; background: #8b98ad; transition: .2s;
}
.switch input:checked + span { background: rgba(79,140,255,.35); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent); }

/* ------------------------------------------------------------------ utility */
.empty { text-align: center; padding: 34px 12px; color: var(--dim); font-size: 13.5px; }
.empty .big { font-size: 26px; margin-bottom: 8px; opacity: .5; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.check input { width: auto; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.split { display: grid; grid-template-columns: 1.35fr .8fr; gap: 18px; align-items: start; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: #17203180; border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.error-text { color: #ff9d9a; font-size: 12.5px; word-break: break-word; }
.pre { white-space: pre-wrap; font-family: "JetBrains Mono", Consolas, monospace; font-size: 12.5px; background: #0d121c; padding: 12px; border-radius: 10px; border: 1px solid var(--line-soft); max-height: 260px; overflow: auto; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .nav { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .nav a { white-space: nowrap; }
  .sidebar-foot { display: flex; justify-content: space-between; align-items: center; }
  .main { padding: 20px 16px 50px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .split { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .topbar { flex-direction: column; }
}
