/* 2ai_dashboard — app shell styles, Linear-restraint */
@import url('tokens.css');

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  background: var(--color-bg);
  color: var(--color-text1);
  font-family: var(--font-body);
  font-size: 14px;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; }
button:active { transform: scale(0.97); }
input, textarea, select { font-family: inherit; color: inherit; }

/* Subtle ambient — one aurora orb in the top-right, very subdued */
body::before {
  content: '';
  position: fixed;
  top: -200px; right: -200px;
  width: 700px; height: 700px;
  background: radial-gradient(circle, rgba(124,106,255,0.10), transparent 60%);
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}

/* Layout */
.app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
@media (max-width: 1023px) {
  .app { grid-template-columns: 1fr; }
}

/* Sidebar (desktop) */
.sidebar {
  position: sticky; top: 0;
  height: 100vh;
  border-right: 1px solid var(--color-border);
  background: rgba(12,10,20,0.7);
  backdrop-filter: blur(12px);
  display: flex; flex-direction: column;
  padding: 20px 14px;
}
@media (max-width: 1023px) { .sidebar { display: none; } }

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 22px;
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #7c6aff, #e879f9);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700; font-size: 12px; color: #fff;
  letter-spacing: -0.02em;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600; font-size: 14px;
  letter-spacing: -0.01em;
}
.brand-name .muted { color: var(--color-text3); font-weight: 400; }

.nav-section {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text3);
  padding: 14px 10px 6px;
}
/* View Mode toggle in topbar (Business / Technical) */
.view-toggle {
  display: inline-flex;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 2px;
  gap: 0;
}
.view-toggle-btn {
  background: none;
  border: 0;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--color-text3);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 6px;
  cursor: pointer;
  transition: all 160ms;
  min-height: 28px;
}
.view-toggle-btn:hover { color: var(--color-text2); }
.view-toggle-btn.active {
  background: var(--color-accent);
  color: white;
  box-shadow: 0 2px 6px rgba(124,106,255,0.3);
}
@media (max-width: 768px) {
  .view-toggle-btn { padding: 4px 8px; font-size: 10px; }
}

/* Collapsible Система group header */
button.nav-section.nav-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--color-text3);
  text-align: left;
  padding: 14px 10px 6px;
  transition: color 160ms;
}
button.nav-section.nav-section-toggle:hover { color: var(--color-text2); }
button.nav-section.nav-section-toggle:active { transform: none; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--color-text2);
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: 0;
  width: 100%; text-align: left;
  transition: all 160ms var(--ease-out);
}
.nav-item:hover { color: var(--color-text1); background: rgba(255,255,255,0.04); }
.nav-item.active { color: var(--color-text1); background: rgba(124,106,255,0.12); }
.nav-item.active .nav-ico { color: var(--color-accent); }
.nav-ico { width: 16px; height: 16px; color: var(--color-text3); flex-shrink: 0; }
.nav-item .badge { margin-left: auto; }

.sidebar-foot {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--color-border);
}

/* Main content */
.main {
  min-width: 0;
  padding-bottom: 84px; /* space for mobile bottom nav + safe area */
}
@media (min-width: 1024px) {
  .main { padding-bottom: 0; }
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(12,10,20,0.78);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 20px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 {
  font-family: var(--font-display);
  font-weight: 600; font-size: 18px; letter-spacing: -0.01em;
  margin: 0;
}
.topbar-spacer { flex: 1; }
.topbar-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text3);
  letter-spacing: 0.05em;
}
@media (max-width: 1023px) {
  .topbar { padding: 12px 16px; }
}

/* Health pill on topbar */
.health-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: rgba(255,255,255,0.02);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--color-text2);
  cursor: pointer;
  transition: all 160ms var(--ease-out);
}
.health-pill:hover { border-color: var(--color-border-h); color: var(--color-text1); }
.health-pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--color-green);
  position: relative;
}
.health-pill.degraded .dot { background: var(--color-amber); }
.health-pill.down .dot { background: var(--color-red); }
.health-pill .dot::after {
  content: ''; position: absolute; inset: -3px; border-radius: 50%;
  background: inherit; opacity: 0.35;
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(2); opacity: 0; }
}

/* Page container */
.page {
  padding: 20px;
  max-width: 1280px;
  margin: 0 auto;
}
@media (min-width: 1024px) { .page { padding: 28px 32px; } }

.page-header { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-family: var(--font-display); font-weight: 600; font-size: 24px; letter-spacing: -0.02em; margin: 0; }
.page-sub { color: var(--color-text2); font-size: 13px; margin: 4px 0 0; }
@media (min-width: 1024px) {
  .page-title { font-size: 28px; }
}

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 100;
  background: rgba(12,10,20,0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 8px 8px calc(env(safe-area-inset-bottom, 16px) + 8px);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.4);
}
@media (min-width: 1024px) { .bottom-nav { display: none; } }
.bottom-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 4px;
  border-radius: 10px;
  background: transparent; border: 0;
  color: var(--color-text3);
  font-size: 10px;
  font-weight: 500;
  position: relative;
}
.bottom-item.active { color: var(--color-text1); }
.bottom-item.active .nav-ico { color: var(--color-accent); }
.bottom-item .nav-ico { width: 20px; height: 20px; }
.bottom-item .badge-dot {
  position: absolute; top: 6px; right: calc(50% - 14px);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-red);
}

/* Mobile drawer — slide-up overlay with all nav groups */
.mobile-drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 201;
  background: var(--color-bg2);
  border-top: 1px solid var(--color-border);
  border-radius: 20px 20px 0 0;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  animation: drawer-up 0.24s var(--ease-out) both;
  box-shadow: 0 -20px 60px rgba(0,0,0,0.5);
}
@media (min-width: 1024px) { .mobile-drawer { display: none !important; } }
@keyframes drawer-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.mobile-drawer-handle {
  width: 36px; height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 10px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.mobile-drawer-body {
  overflow-y: auto;
  flex: 1;
  padding: 6px 10px calc(env(safe-area-inset-bottom, 16px) + 80px);
}
.mobile-drawer-group { margin-bottom: 4px; }
.mobile-drawer-section {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text3);
  padding: 10px 12px 4px;
  font-weight: 600;
}
.mobile-drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  background: transparent;
  border: 0;
  color: var(--color-text2);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 100ms;
}
.mobile-drawer-item:active { background: var(--color-surface); }
.mobile-drawer-item.active {
  color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
}
.mobile-drawer-item .nav-ico { width: 18px; height: 18px; flex-shrink: 0; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 20px;
  transition: all 200ms var(--ease-out);
}
.card.hover:hover { border-color: var(--color-border-h); transform: translateY(-1px); }
.card-tight { padding: 16px; border-radius: 12px; }

/* Stat */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 16px 18px;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text3);
}
.stat-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.02em;
  color: var(--color-text1);
  margin-top: 6px;
  line-height: 1;
}
.stat-delta { font-family: var(--font-mono); font-size: 11px; margin-top: 6px; color: var(--color-text3); }
.stat-delta.bad { color: var(--color-red); }
.stat-delta.good { color: var(--color-green); }
.stat-delta.warn { color: var(--color-amber); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--color-border-h);
  background: var(--color-surface2);
  color: var(--color-text1);
  font-size: 13px; font-weight: 500;
  transition: all 160ms var(--ease-out);
}
.btn:hover { background: var(--color-surface3); border-color: rgba(255,255,255,0.2); }
.btn.primary {
  background: var(--color-accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(124,106,255,0.4), 0 6px 20px -8px rgba(124,106,255,0.6);
}
.btn.primary:hover { background: #8b7aff; }
.btn.ghost { background: transparent; border-color: var(--color-border); }
.btn.ghost:hover { border-color: var(--color-border-h); background: rgba(255,255,255,0.03); }
.btn.danger { background: rgba(251,113,133,0.12); border-color: rgba(251,113,133,0.3); color: var(--color-red); }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.icon { padding: 7px; }

/* Tag / chip */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: rgba(255,255,255,0.03);
  color: var(--color-text2);
}
.chip.purple { color: var(--color-accent); border-color: rgba(124,106,255,0.3); background: rgba(124,106,255,0.08); }
.chip.mint { color: var(--color-accent3); border-color: rgba(6,214,160,0.3); background: rgba(6,214,160,0.08); }
.chip.magenta { color: var(--color-accent2); border-color: rgba(232,121,249,0.3); background: rgba(232,121,249,0.08); }
.chip.amber { color: var(--color-amber); border-color: rgba(251,191,36,0.3); background: rgba(251,191,36,0.08); }
.chip.red { color: var(--color-red); border-color: rgba(251,113,133,0.3); background: rgba(251,113,133,0.08); }

/* Form */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text3);
}
.input, .textarea, .select {
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--color-text1);
  outline: none;
  transition: border-color 160ms var(--ease-out);
}
.input:focus, .textarea:focus, .select:focus { border-color: rgba(124,106,255,0.5); box-shadow: 0 0 0 3px rgba(124,106,255,0.12); }
.textarea { resize: vertical; min-height: 96px; font-family: var(--font-body); line-height: 1.55; }

/* Mono */
.mono { font-family: var(--font-mono); font-size: 12px; }
.muted { color: var(--color-text3); }
.text2 { color: var(--color-text2); }

/* Section header */
.section-h {
  display: flex; align-items: end; justify-content: space-between;
  margin: 26px 0 12px;
  gap: 12px;
}
.section-h h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  margin: 0;
}
.section-h .meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text3);
}

/* Grid utils */
.grid { display: grid; gap: 14px; }
.grid-stats { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { .grid-stats { grid-template-columns: repeat(4, 1fr); } }
.grid-2 { grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-agents { grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid-agents { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1180px) { .grid-agents { grid-template-columns: 1fr 1fr 1fr; } }

/* Severity row */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: all 140ms var(--ease-out);
}
.row:hover { background: rgba(255,255,255,0.02); border-color: var(--color-border); }
.row.error { background: rgba(251,113,133,0.06); border-color: rgba(251,113,133,0.18); }
.row.warn { background: rgba(251,191,36,0.05); border-color: rgba(251,191,36,0.16); }

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

/* Kanban */
.kanban {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(280px, 1fr));
  overflow-x: auto;
  padding-bottom: 4px;
}
@media (max-width: 900px) {
  .kanban {
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-auto-columns: 82vw;
    scroll-snap-type: x mandatory;
    margin: 0 -16px;
    padding: 0 16px 4px;
  }
  .kanban > .col { scroll-snap-align: start; }
}
.col {
  background: rgba(255,255,255,0.015);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 200px;
}
.col-h { display: flex; align-items: center; gap: 8px; padding: 4px 4px 6px; }
.col-h .name { font-family: var(--font-display); font-weight: 600; font-size: 13px; }
.col-h .count {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--color-text3);
  background: var(--color-surface2);
  padding: 2px 7px; border-radius: 999px;
}

.task {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  cursor: grab;
  transition: all 160ms var(--ease-out);
}
.task:hover { border-color: var(--color-border-h); transform: translateY(-1px); }
.task .title { font-size: 13px; font-weight: 500; color: var(--color-text1); line-height: 1.4; }
.task .meta { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 10.5px; color: var(--color-text3); }

/* Agent dot */
.agent-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}

/* Log entry */
.log {
  display: grid;
  grid-template-columns: 80px 90px minmax(70px, 110px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
}
.log:hover { background: rgba(255,255,255,0.02); border-color: var(--color-border); }
.log.expanded { background: rgba(255,255,255,0.025); border-color: var(--color-border-h); }
.log .ts { color: var(--color-text3); }
.log .sev { font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; font-size: 10px; }
.log .sev.error { color: var(--color-red); }
.log .sev.warn { color: var(--color-amber); }
.log .sev.info { color: var(--color-text2); }
.log .src { color: var(--color-accent); }
.log .msg { color: var(--color-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.log.expanded .msg { white-space: pre-wrap; word-break: break-word; color: var(--color-text1); }
@media (max-width: 720px) {
  .log { grid-template-columns: 70px 1fr; row-gap: 4px; }
  .log .src, .log .sev { grid-column: auto; }
  .log .msg { grid-column: 1 / -1; white-space: normal; }
}

/* Mini bar chart */
.bars { display: flex; gap: 3px; align-items: end; height: 36px; }
.bars .bar { flex: 1; background: rgba(124,106,255,0.25); border-radius: 2px 2px 0 0; transition: background 200ms; }
.bars .bar.peak { background: var(--color-red); }
.bars .bar.warn { background: var(--color-amber); }

/* Banner */
.banner {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid;
  font-size: 13px;
  margin-bottom: 14px;
}
.banner.warn { border-color: rgba(251,191,36,0.3); background: rgba(251,191,36,0.06); color: var(--color-text1); }
.banner.error { border-color: rgba(251,113,133,0.3); background: rgba(251,113,133,0.06); }
.banner.info { border-color: rgba(124,106,255,0.3); background: rgba(124,106,255,0.06); }

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text3);
  font-size: 13px;
}

/* Modal */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade 200ms var(--ease-out);
}
.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border-h);
  border-radius: 18px;
  padding: 24px;
  max-width: 540px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  animation: pop 240ms var(--ease-out);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* Filter pills */
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text2);
  transition: all 140ms var(--ease-out);
}
.pill:hover { color: var(--color-text1); border-color: var(--color-border-h); }
.pill.active { background: rgba(124,106,255,0.14); border-color: rgba(124,106,255,0.4); color: var(--color-text1); }

/* Scrollbar restraint */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.12); }

/* ─────────────────── MOBILE (≤ 768px) comprehensive fixes */
@media (max-width: 768px) {
  /* Page padding — compact on phone */
  .page { padding: 16px 16px 100px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
  .page-title { font-size: 22px; }

  /* Cockpit Layout Stacking */
  .cockpit-grid {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }
  .cockpit-feed-wrap {
    order: 2; /* feed below agents */
    max-height: 400px;
  }

  /* Cards — full width, reduced padding */
  .card { padding: 16px; border-radius: 14px; }

  /* Stats grid — 2 columns on phone */
  .grid-stats { grid-template-columns: 1fr 1fr; gap: 12px; }

  /* Agents grid — 1 column on phone */
  .grid-agents { grid-template-columns: 1fr; }

  /* Grid-2 (products, etc.) — stack on phone */
  .grid-2 { grid-template-columns: 1fr; }

  /* Metric value — slightly smaller */
  .stat-value { font-size: 22px; }

  /* Buttons — larger touch targets */
  .btn { min-height: 48px; padding: 10px 20px; font-size: 14px; }
  .btn.sm { min-height: 40px; }
  .btn.icon { min-width: 48px; min-height: 48px; }

  /* Modal — bottom sheet on mobile */
  .modal-back { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92dvh;
    border-radius: 24px 24px 0 0;
    padding: 24px 20px;
    animation: slideup 300ms var(--ease-out);
  }
  @keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }

  /* Log grid — compact */
  .log { grid-template-columns: 70px 1fr; row-gap: 6px; font-size: 11px; padding: 10px 12px; }
  .log .src, .log .sev { font-size: 10px; }

  /* Voice FAB — repositioned above bottom nav */
  .voice-orb-fab {
    bottom: calc(env(safe-area-inset-bottom, 16px) + 84px) !important;
    right: 20px !important;
    left: auto !important;
    transform: none !important;
  }
  .voice-orb-fab:hover { transform: scale(1.06) !important; }

  /* Voice panel — above bottom nav */
  .voice-panel {
    bottom: calc(env(safe-area-inset-bottom, 16px) + 84px);
    width: calc(100vw - 32px);
  }

  /* Tweaks panel — push it up above bottom nav */
  .tweaks-panel { bottom: 90px !important; }

  /* ── CRITICAL: prevent horizontal overflow (was 850px on 390px viewport) */
  html, body { overflow-x: hidden; }
  .main { min-width: 0; max-width: 100vw; overflow-x: hidden; }
  .page { max-width: 100%; }
  .card { max-width: 100%; overflow: hidden; }

  /* Flex rows wrap with title taking full width on mobile */
  .row {
    flex-wrap: wrap;
    row-gap: 4px;
    column-gap: 8px;
    padding: 10px 12px;
  }
  .row > * { min-width: 0; }
  /* Title spans with inline flex:1 — give them full row, push chips/badges to second line */
  .row > span[style*="flex: 1"],
  .row > div[style*="flex: 1"] {
    flex-basis: 100% !important;
    order: 0;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  /* Section header: title shrinks with ellipsis */
  .section-h { min-width: 0; flex-wrap: wrap; }
  .section-h h3 {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }
  .section-h .btn { flex-shrink: 0; }

  /* Page header: + Создать button — same row as title, smaller */
  .page-header { flex-direction: row !important; align-items: center !important; gap: 8px !important; flex-wrap: nowrap; }
  .page-header > div:first-child { min-width: 0; flex: 1; }
  .page-header .page-title { font-size: 19px; line-height: 1.2; }
  .page-header .page-sub { font-size: 11px; }
  .page-header .btn.primary { padding: 8px 12px; min-height: 40px; font-size: 13px; flex-shrink: 0; }
  .page-header .btn.primary .nav-ico { width: 14px; height: 14px; }

  /* Hermes AI floating bubble — out of the way of bottom nav */
  button[title="Hermes AI"],
  [class*="hermes"] > button:first-child {
    bottom: 90px !important;
    right: 14px !important;
    width: 44px !important;
    height: 44px !important;
    font-size: 18px !important;
    box-shadow: 0 4px 14px rgba(0,0,0,0.45) !important;
  }

  /* Topbar — single h1, less padding */
  .topbar h1 { font-size: 15px; }
  .topbar { padding: 10px 14px; gap: 8px; }

  /* Brand /v1 hide on mobile */
  .brand-version { display: none; }
}

/* ─────────────────── TABLET (640–1023px) tweaks */
@media (min-width: 640px) and (max-width: 1023px) {
  .page { padding: 16px 20px 24px; }
  .grid-stats { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .grid-agents { grid-template-columns: 1fr 1fr; }
  .modal { max-width: 520px; }
}

/* ─────────────────── TOUCH — larger tap targets everywhere */
@media (hover: none) and (pointer: coarse) {
  .btn, button, a, .pill, .card.hover { min-height: 44px; min-width: 44px; }
  .log { padding: 12px 12px; }
  select, input[type="text"], input[type="search"] { min-height: 44px; font-size: 16px; /* prevent zoom */ }
}

/* Mobile additions consolidated above (line 530-600). Touch target normalisation. */
@media (max-width: 768px) {
  .agent-card {
    min-height: 120px;
    padding: 16px !important;
  }
  .kanban .col {
    min-width: 280px; /* Force scroll on mobile */
  }
  .bottom-item {
    gap: 4px;
  }
  .bottom-item span {
    font-size: 10px;
  }
  /* Tap-to-show tooltip на сенсоре */
  [data-tooltip]:active::after,
  [data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: none;
  }
  /* select прозум-фикс iOS */
  select { font-size: 16px !important; }
}

/* Animations */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(124, 106, 255, 0.45); }
  70% { box-shadow: 0 0 0 10px rgba(124, 106, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(124, 106, 255, 0); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: 6px;
}
.skeleton-text { height: 12px; margin: 6px 0; }
.skeleton-title { height: 22px; margin: 8px 0 12px; width: 60%; }
.skeleton-card { height: 100px; border-radius: 14px; }
.skeleton-stat { height: 88px; border-radius: 14px; }

/* Accessibility — focus visible */
*:focus { outline: none; }
*:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible, .pill:focus-visible, .nav-item:focus-visible, .bottom-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Skip-link для screen readers */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-accent);
  color: #fff;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 0 0 8px 0;
  z-index: 10000;
  font-weight: 600;
}
.skip-link:focus { top: 0; }

/* Reduced motion respect */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .health-pill .dot::after,
  .voice-orb-ring,
  .voice-mic.live,
  .agent-card .dot,
  .skeleton {
    animation: none !important;
  }
}

/* Severity info colour (был только error/warn) */
.log .sev.info { color: var(--color-text2); }

/* Logs grid fix — msg съедался grid item'ом без min-width:0 */
.log {
  grid-template-columns: 80px 90px minmax(70px, 110px) minmax(0, 1fr);
}
.log .msg { min-width: 0; }
.log .src { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ─────────────────── TOASTER ─────────────────── */
.toaster {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 48px);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--color-surface2);
  border: 1px solid var(--color-border-h);
  border-left: 3px solid var(--color-accent);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  min-width: 280px;
  max-width: 420px;
  font-size: 13px;
  line-height: 1.45;
  animation: toast-in 200ms var(--ease-out);
}
.toast-success { border-left-color: var(--color-green); }
.toast-error   { border-left-color: var(--color-red); }
.toast-warn    { border-left-color: var(--color-amber); }
.toast-info    { border-left-color: var(--color-accent); }
.toast-ico {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  font-family: var(--font-mono);
}
.toast-success .toast-ico { background: rgba(52, 211, 153, 0.18); color: var(--color-green); }
.toast-error   .toast-ico { background: rgba(251, 113, 133, 0.18); color: var(--color-red); }
.toast-warn    .toast-ico { background: rgba(251, 191, 36, 0.18); color: var(--color-amber); }
.toast-info    .toast-ico { background: rgba(124, 106, 255, 0.18); color: var(--color-accent); }
.toast-text {
  flex: 1;
  color: var(--color-text1);
  word-wrap: break-word;
}
.toast-close {
  background: transparent;
  border: 0;
  color: var(--color-text3);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
  border-radius: 4px;
}
.toast-close:hover { color: var(--color-text1); background: rgba(255, 255, 255, 0.06); }
.toast-close:focus-visible { outline: 2px solid var(--color-accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@media (max-width: 768px) {
  .toaster {
    left: 16px;
    right: 16px;
    bottom: calc(env(safe-area-inset-bottom, 16px) + 88px); /* выше bottom-nav */
    align-items: stretch;
  }
  .toast {
    min-width: 0;
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* SSE-connection indicator */
.sse-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 10px;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--color-border);
  color: var(--color-text3);
}
.sse-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-text3);
}
.sse-pill.live .dot { background: var(--color-green); animation: pulse 2s infinite; }
.sse-pill.live { color: var(--color-text2); }
.sse-pill.down .dot { background: var(--color-red); }
.sse-pill.down { color: var(--color-red); border-color: rgba(251,113,133,0.3); }

/* Empty state icon */
.empty-illustration {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 32px 16px;
  color: var(--color-text3);
  text-align: center;
}
.empty-illustration .ico {
  width: 48px; height: 48px;
  opacity: 0.4;
  margin-bottom: 4px;
}
.empty-illustration .label {
  font-size: 14px; color: var(--color-text2);
}
.empty-illustration .hint {
  font-size: 12px; color: var(--color-text3);
}

/* Tooltip styles */
[data-tooltip] {
  position: relative;
  cursor: help;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%) translateY(5px);
  background: var(--color-surface3);
  color: var(--color-text1);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-family: var(--font-body);
  white-space: pre-wrap;
  width: 200px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border-h);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s var(--ease-out);
  z-index: 100;
}
[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.info-ico {
  display: inline-flex;
  opacity: 0.4;
  margin-left: 6px;
  transition: opacity 0.2s;
}
.info-ico:hover { opacity: 1; color: var(--color-accent); }
