/* ==========================================================================
   Project Pulse · Platinum Amethyst Design System
   Graphite (#121214) + Platinum (#C8C5CD) + Royal Amethyst (#9146C8) + Sage (#A5BFAE)
   NO BLUE COLORS · 100% Mobile Responsive · Smooth 60 FPS Orbit Wave Animations
   ========================================================================== */

:root {
  --bg: #121214;
  --panel: #1B1B1F;
  --raised: #252429;
  --line: #38363D;
  --text: #F0F1F3;
  --muted: #B3B1B8;
  --accent: #C8C5CD;
  --violet: #9146C8;
  --violet-bright: #B475E3;
  --violet-edge: #79409F;
  --danger: #CEACF0;
  --ok: #A5BFAE;
  --warn: #DBC18E;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

*, *:before, *:after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

/* Base button and inputs */
button, input, select {
  font: inherit;
}
button, select {
  cursor: pointer;
  color: inherit;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  transition: background 0.18s ease, border-color 0.18s ease;
}
button:hover {
  background: var(--raised);
  border-color: var(--muted);
}
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--violet-bright);
  outline-offset: 3px;
}
button[aria-pressed="true"] {
  background: rgba(145, 70, 200, 0.18);
  border-color: rgba(145, 70, 200, 0.45);
  color: #F5EAFB;
}

/* Animations */
@keyframes orbit {
  to { stroke-dashoffset: -100; }
}

@keyframes travel {
  to { stroke-dashoffset: -196; }
}

@keyframes breathe {
  50% { opacity: 0.35; box-shadow: 0 0 9px rgba(165, 191, 174, 0.5); }
}

@keyframes sweep {
  0%, 72% { left: -35px; }
  100% { left: 110%; }
}

@keyframes slide-menu {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
header {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 18, 20, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 40;
  max-width: 100vw;
}

.brand {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.6px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand svg {
  width: 26px;
  height: 26px;
  color: var(--violet-bright);
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Entity Dropdown (Notion Switcher) */
.entity-selector {
  position: relative;
  display: inline-block;
  z-index: 50;
}
.entity-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 550;
  color: var(--text);
  transition: all 0.18s;
  cursor: pointer;
}
.entity-btn:hover {
  border-color: var(--violet-bright);
}
.entity-btn .chevron {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: transform 0.2s;
}
.entity-btn.open .chevron {
  transform: rotate(180deg);
}
.entity-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 290px;
  background: #1B1B1F;
  border: 1px solid #64407C;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.7), 0 0 20px rgba(145,70,200,0.25);
  padding: 6px;
  z-index: 100;
  animation: slide-menu 0.18s ease-out;
}
.entity-menu.hidden {
  display: none;
}
.menu-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.menu-item:hover {
  background: var(--raised);
}
.menu-item.active {
  background: rgba(145, 70, 200, 0.18);
  border: 1px solid rgba(145, 70, 200, 0.35);
}
.menu-item .icon {
  font-size: 16px;
  line-height: 1.2;
}
.menu-item .title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.menu-item .desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

.sync {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.dot {
  height: 6px;
  width: 6px;
  border-radius: 50%;
  display: inline-block;
  background: currentColor;
  flex: none;
}
.sync .dot {
  color: var(--ok);
}
.sync.busy .dot {
  animation: breathe 1.4s infinite;
}

.search {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--muted);
  background: rgba(25, 28, 32, 0.6);
  transition: border-color 0.18s;
}
.search:focus-within {
  border-color: var(--violet-bright);
}
.search input {
  width: 140px;
  background: none;
  border: 0;
  color: var(--text);
  padding: 7px 4px;
  outline: none;
  font-size: 13px;
}
.search small {
  font-size: 10px;
  padding: 2px 5px;
  background: var(--raised);
  border-radius: 4px;
  border: 1px solid var(--line);
}

/* Main Container */
main {
  max-width: 1536px;
  margin: auto;
  padding: 28px 32px 60px;
  box-sizing: border-box;
}

.intro {
  margin-bottom: 20px;
}

/* Master Context Switcher (Работа / Личное / Всё) */
.context-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #17171A;
  padding: 5px;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 24px;
}
.context-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  white-space: nowrap;
}
.context-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.context-btn.active {
  background: linear-gradient(135deg, rgba(145, 70, 200, 0.25), rgba(121, 64, 159, 0.15));
  border-color: #9146C8;
  color: #F5EAFB;
  box-shadow: 0 0 16px rgba(145, 70, 200, 0.28);
}
.context-btn .dot-active {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #B475E3;
  box-shadow: 0 0 8px #B475E3;
}

/* Brand logo Ч. with noble styling */
.brand-logo-ch {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #1A1A1A;
  border: 1px solid #5A3575;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  box-shadow: 0 0 12px rgba(145, 70, 200, 0.3);
}
.brand-logo-ch svg {
  width: 24px;
  height: 24px;
}
h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.8px;
  margin: 0;
}
h2 {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.4px;
  margin: 0;
}
p {
  margin: 0;
  color: var(--muted);
}

/* Metrics Section (Fixed ECG Pulse Animation & Line) */
.metrics {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr 1fr;
  background: linear-gradient(110deg, #242228, #1A191D);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}
.metric {
  position: relative;
  padding: 22px 24px;
  min-height: 135px;
  border-right: 1px solid var(--line);
}
.metric:last-child {
  border: 0;
}
.metric:nth-child(2) {
  background: linear-gradient(125deg, rgba(145, 70, 200, 0.12), transparent);
}
.label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}
.number {
  font-size: 36px;
  font-weight: 500;
  letter-spacing: -1.2px;
  line-height: 1.25;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.number.word {
  font-size: 24px;
  margin-top: 12px;
  margin-bottom: 6px;
}
.metric small {
  color: var(--muted);
  font-size: 12px;
}

/* FIXED ECG Pulse SVG */
.pulse {
  position: absolute;
  right: 18px;
  bottom: 16px;
  width: 108px;
  height: 36px;
  overflow: visible;
  pointer-events: none;
}
.pulse path {
  fill: none !important;
  stroke: #79409F;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.25;
}
.pulse .signal {
  fill: none !important;
  stroke: #B475E3 !important;
  stroke-width: 2.2 !important;
  stroke-dasharray: 18 180;
  animation: travel 4.5s linear infinite;
  filter: drop-shadow(0 0 5px #9146C8);
  opacity: 1 !important;
}

.mini-bar {
  height: 3px;
  background: var(--line);
  margin-top: 14px;
  width: 46%;
  border-radius: 2px;
  overflow: hidden;
}
.mini-bar i {
  height: 100%;
  display: block;
  width: 50%;
  background: var(--accent);
}
.danger {
  color: var(--danger);
}
.ok {
  color: var(--ok);
}
.warn {
  color: var(--warn);
}

/* Section Bar & Filters (Mobile Wrap Protection) */
.sectionbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  width: 100%;
}
.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filters button {
  border-color: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 6px;
}
.filters button:hover {
  background: var(--raised);
  color: var(--text);
}
.filters button[aria-pressed="true"] {
  background: rgba(145, 70, 200, 0.16);
  border-color: rgba(145, 70, 200, 0.4);
  color: #F5EAFB;
}
.filters b {
  font-weight: 600;
  margin-left: 6px;
  color: var(--text);
}

/* Grid & Cards (Platinum Amethyst) */
.grid-wrap {
  position: relative;
  isolation: isolate;
  width: 100%;
}
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  position: relative;
  z-index: 1;
  width: 100%;
}

.connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  color: var(--violet);
  z-index: 0;
}
.connections .track {
  stroke: #644078;
  stroke-width: 1;
  opacity: 0.4;
}
.connections .flow {
  stroke: #BD8CE2;
  stroke-width: 1.8;
  stroke-dasharray: 5 95;
  animation: orbit 9s linear infinite;
  filter: drop-shadow(0 0 4px #9146C8);
}
.connections .node {
  fill: #B475E3;
  stroke: none;
  opacity: 0.7;
}

.card {
  display: flex;
  flex-direction: column;
  text-align: left;
  min-height: 248px;
  padding: 24px;
  border: 1px solid #3B393F;
  border-radius: 12px;
  background: var(--panel);
  position: relative;
  isolation: isolate;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s, border-color 0.2s, background 0.2s;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
}
.card:hover {
  transform: translateY(-2px);
  border-color: #B475E3;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45), 0 0 22px rgba(145, 70, 200, 0.16);
}

/* Card: Risk / Срыв сроков */
.card.risk {
  background: linear-gradient(135deg, rgba(145, 70, 200, 0.1), transparent 65%), var(--panel);
  border-color: #64407C;
}
.card.risk .status {
  color: #D8BCF0;
  background: rgba(145, 70, 200, 0.18);
  border: 1px solid rgba(158, 89, 207, 0.45);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 550;
}
.card.risk .status .dot {
  box-shadow: 0 0 8px rgba(166, 100, 217, 0.8);
  background: #D8BCF0;
}
.card.risk .taskhint strong {
  color: #D8BCF0;
}

/* Card: Healthy / В ритме */
.card.healthy {
  background: #1B1D1C;
  border-color: #3A423D;
}
.card.healthy .status {
  padding: 4px 0;
  color: var(--ok);
  font-size: 12px;
  font-weight: 550;
}
.card.healthy .status .dot {
  background: var(--ok);
}

/* Card: Selected */
.card.selected {
  border-color: #CC9EED;
  box-shadow: 0 0 0 1px rgba(180, 117, 227, 0.45), 0 0 28px rgba(145, 70, 200, 0.2), 0 14px 32px rgba(0, 0, 0, 0.4);
}
.card.selected:after {
  content: 'Выбрано';
  position: absolute;
  right: 22px;
  bottom: 52px;
  color: #D5B8EE;
  font-size: 11px;
  font-weight: 500;
}
.card.selected h3 {
  color: #F5EAFB;
}

/* Contour Wave Animation */
.contour {
  position: absolute;
  inset: -1px;
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  overflow: visible;
  pointer-events: none;
  border-radius: inherit;
  color: var(--violet-bright);
}
.contour rect {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-dasharray: 10 90;
  animation: orbit 7s linear infinite;
  filter: drop-shadow(0 0 3px #9146C8);
  opacity: 0.9;
}
.card:not(.risk):not(.selected) .contour {
  display: none;
}
.card:nth-child(2) .contour rect { animation-delay: -2.3s; }
.card:nth-child(3) .contour rect { animation-delay: -4.6s; }
.card:nth-child(4) .contour rect { animation-delay: -1.2s; }
.card:nth-child(5) .contour rect { animation-delay: -3.5s; }
.card:nth-child(6) .contour rect { animation-delay: -5.8s; }
.card.selected .contour rect {
  stroke-width: 2;
  stroke-dasharray: 18 82;
  color: #D8BCF0;
}

/* Card internals */
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.status {
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-date {
  color: var(--muted);
  font-size: 11px;
  font-family: monospace;
}
.card h3 {
  font-size: 17px;
  font-weight: 550;
  line-height: 1.4;
  letter-spacing: -0.2px;
  margin: 16px 0 10px;
  min-height: 48px;
}
.taskhint {
  font-size: 13px;
  color: var(--muted);
  min-height: 40px;
}
.bar {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  margin-top: 18px;
  overflow: hidden;
}
.bar i {
  display: block;
  background: #C8C5CD;
  height: 100%;
  width: var(--progress, 0%);
  position: relative;
  transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bar i:after {
  content: '';
  position: absolute;
  width: 30px;
  inset: 0 auto 0 -35px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: sweep 7s ease-in-out infinite;
}
.card-foot {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-top: 12px;
}
.card-foot b {
  color: var(--text);
  font-weight: 500;
}

/* Card Variants */
.variant-inset .card {
  border-radius: 18px;
  background: linear-gradient(150deg, #25212B, #1A1A1E 72%);
  border-color: #45404D;
  padding: 25px;
}
.variant-inset .card.risk:before {
  content: '';
  position: absolute;
  left: 24px;
  right: 24px;
  top: 0;
  height: 3px;
  border-radius: 0 0 5px 5px;
  background: linear-gradient(90deg, #6A348C, #B475E3, #6A348C);
  box-shadow: 0 3px 17px rgba(145, 70, 200, 0.35);
}
.variant-inset .card.risk .contour { display: none; }
.variant-inset .card.selected .contour { display: block; }
.variant-inset .card.selected { border-color: #B475E3; }
.variant-inset .card.risk .status { background: none; border: 0; padding: 3px 0; }
.variant-inset .taskhint {
  padding: 10px 12px;
  background: rgba(18, 18, 21, 0.6);
  border-radius: 8px;
  min-height: 60px;
}
.variant-inset .card.healthy { background: linear-gradient(150deg, #202522, #1A1C1B); }

.variant-rail .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.variant-rail .card {
  min-height: 238px;
  border-radius: 8px;
  padding: 22px 26px 22px 30px;
  background: #1B1B1F;
  border-color: #454049;
}
.variant-rail .card:before {
  content: '';
  position: absolute;
  left: 0;
  top: 22px;
  bottom: 22px;
  width: 3px;
  background: #637469;
  border-radius: 3px;
}
.variant-rail .card.risk:before {
  background: linear-gradient(#724194, #BC83E4, #724194);
  box-shadow: 0 0 14px rgba(145, 70, 200, 0.3);
}
.variant-rail .card:not(.selected) .contour { display: none; }
.variant-rail .card h3 { min-height: 24px; }
.variant-rail .card.risk .status { background: rgba(145, 70, 200, 0.2); border: 0; border-radius: 4px; }
.variant-rail .card.selected { border-color: #C49AE1; }

/* Motion modes */
body[data-motion="contour"] .connections,
body[data-motion="off"] .connections { display: none; }
body[data-motion="links"] .contour,
body[data-motion="off"] .contour { display: none; }
body[data-motion="off"] * { animation: none !important; }
.paused *, .tab-hidden * { animation-play-state: paused !important; }

/* View: List Mode */
.view-list .connections { display: none; }
.view-list .grid { grid-template-columns: 1fr; }
.view-list .card {
  min-height: 0;
  display: grid;
  grid-template-columns: 170px 1.2fr 1fr 150px;
  gap: 20px;
  align-items: center;
  padding: 18px 22px;
}
.view-list .card h3 { min-height: 0; margin: 0; font-size: 15px; }
.view-list .card-head { display: block; }
.view-list .card-date { display: block; margin-top: 8px; }
.view-list .taskhint { min-height: 0; }
.view-list .bar { display: none; }
.view-list .card-foot { display: block; margin: 0; }
.view-list .card-foot span { display: block; }
.view-list .card.selected:after { display: none; }

/* Team Workload & Waiting Cards */
.extra-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 36px;
  width: 100%;
}
.sub-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
}
.sub-panel h3 {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sub-panel h3 span.badge {
  font-size: 11px;
  color: var(--muted);
  font-weight: normal;
}
.team-item { margin-bottom: 14px; }
.team-item:last-child { margin-bottom: 0; }
.team-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}
.team-bar {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.team-bar i {
  display: block;
  height: 100%;
  background: var(--ok);
  transition: width 0.4s ease;
}
.team-bar.overload i {
  background: linear-gradient(90deg, #9146C8, #B475E3);
}

.wait-item {
  padding: 12px 14px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.wait-item:last-child { margin-bottom: 0; }
.wait-tag {
  font-size: 11px;
  color: #D8BCF0;
  background: rgba(145, 70, 200, 0.18);
  border: 1px solid rgba(145, 70, 200, 0.35);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

/* Bottom Controls Section (Designbar moved to bottom) */
.bottom-controls-section {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.designbar {
  padding: 12px 18px;
  background: #1D1C21;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
}
.designbar label {
  display: flex;
  gap: 8px;
  align-items: center;
}
.designbar select {
  font-size: 12px;
  padding: 6px 10px;
  background: var(--panel);
  border-color: #54435F;
}
.variant-note {
  font-size: 12px;
  color: #B8A4C8;
  margin-top: 12px;
}

/* Legend & Footer */
.legend {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-top: 20px;
}
.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend .risk-key { color: #C79BE6; }
.legend .select-key {
  width: 12px;
  height: 12px;
  border: 1px solid #D8BCF0;
  border-radius: 3px;
  box-shadow: 0 0 7px rgba(145, 70, 200, 0.3);
}
.source {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

/* Backdrop & Drawer (Modal / Mobile Bottom Sheet) */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 999;
  display: none;
  overflow-x: hidden;
}
.backdrop.open {
  display: flex;
  justify-content: flex-end;
}
.drawer {
  position: relative;
  width: 520px;
  max-width: 100vw;
  height: 100%;
  background: #1B191E;
  border-left: 1px solid #8E57B3;
  padding: 32px 28px;
  overflow-y: auto;
  overflow-x: hidden;
  animation: slide 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.6);
  box-sizing: border-box;
}
.drawer h2 {
  font-size: 22px;
  margin: 18px 0 12px;
  line-height: 1.3;
}
.drawer .close {
  float: right;
  border-radius: 6px;
  padding: 6px 12px;
}
.details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px 0;
  margin: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.details span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.taskrow {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
}
.taskrow svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--danger);
  margin-top: 2px;
  stroke: currentColor;
}
.note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 18px;
  line-height: 1.5;
}

/* Lock Screen */
.lock-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 18, 20, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lock-box {
  background: #1B1B1F;
  border: 1px solid #64407C;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px rgba(145, 70, 200, 0.2);
  border-radius: 16px;
  padding: 34px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.lock-input {
  width: 100%;
  text-align: center;
  letter-spacing: 3px;
  padding: 12px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  margin: 16px 0 12px;
}
.lock-input:focus {
  border-color: var(--violet-bright);
}
.lock-btn {
  width: 100%;
  background: linear-gradient(135deg, #9146C8, #79409F);
  border: 0;
  color: #fff;
  font-weight: 550;
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  transition: opacity 0.2s;
}
.lock-btn:hover {
  opacity: 0.92;
}

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE RULES (FIXES HORIZONTAL SCROLL & OVERFLOWS)
   ========================================================================== */

@media (max-width: 1100px) {
  header { padding: 0 20px; gap: 14px; }
  main { padding: 22px 20px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .extra-section { grid-template-columns: 1fr; }
  .pulse { width: 85px; }
}

@media (max-width: 768px) {
  header {
    padding: 0 14px;
    height: 64px;
    gap: 10px;
  }
  .brand {
    font-size: 16px;
    gap: 8px;
  }
  .brand svg {
    width: 22px;
    height: 22px;
  }
  .entity-btn {
    padding: 6px 9px;
    font-size: 12px;
  }
  .search, .sync {
    display: none;
  }
  header > button {
    margin-left: auto;
  }

  main {
    padding: 16px 14px 40px;
    width: 100%;
    overflow-x: hidden;
  }
  h1 {
    font-size: 24px;
  }

  /* Context switcher on mobile */
  .context-bar {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    padding: 3px;
    margin-bottom: 16px;
  }
  .context-btn {
    padding: 7px 2px;
    font-size: 11px;
    justify-content: center;
    gap: 4px;
  }

  /* Metrics 2x2 grid */
  .metrics {
    grid-template-columns: 1fr 1fr;
    margin-bottom: 22px;
  }
  .metric {
    padding: 14px;
    min-height: 115px;
    border-bottom: 1px solid var(--line);
  }
  .metric:nth-child(2) { border-right: 0; }
  .metric:last-child { border-bottom: 0; }
  .number { font-size: 28px; }
  .number.word { font-size: 20px; margin-top: 8px; }
  
  /* ECG pulse is ALWAYS visible on mobile */
  .pulse {
    display: block !important;
    width: 68px;
    height: 24px;
    right: 10px;
    bottom: 10px;
  }

  /* Section bar & filters wrap evenly in 4 columns without overflow! */
  .sectionbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
  }
  .filters {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }
  .filters button {
    padding: 8px 3px;
    font-size: 11px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
    border-radius: 6px;
  }
  .filters button b {
    margin-left: 0;
  }

  /* Single column grid on phones */
  .grid, .variant-rail .grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .card, .variant-inset .card, .variant-rail .card {
    padding: 18px;
    min-height: 220px;
  }
  .connections { display: none; }

  /* Drawer turns into native Bottom Sheet on Mobile */
  .backdrop.open {
    justify-content: center;
    align-items: flex-end;
  }
  .drawer {
    width: 100%;
    max-width: 100vw;
    height: 90vh;
    border-left: none;
    border-top: 1px solid #8E57B3;
    border-radius: 20px 20px 0 0;
    padding: 22px 18px;
    animation: slide-up 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  @keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* Bottom Controls Section */
  .designbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .designbar label {
    justify-content: space-between;
  }
  .extra-section {
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 24px;
  }
  .legend {
    gap: 12px;
    font-size: 11px;
  }
  .source {
    flex-direction: column;
    gap: 6px;
  }
}
