  .demo-embed, .demo-embed *, .demo-embed *::before, .demo-embed *::after { box-sizing: border-box; margin: 0; padding: 0; }

  .demo-embed {
    --bg: #f0f9ff;
    --surface: #ffffff;
    --border: #bae6fd;
    --border-soft: rgba(14,165,233,0.12);
    --text: #0c4a6e;
    --muted: #64748b;
    --accent: #0ea5e9;
    --accent-dark: #0369a1;
    --accent-light: #e0f2fe;
    --green: #16a34a;
    --red: #dc2626;
    --orange: #ea580c;
    --yellow: #ca8a04;
    --blue: #2563eb;
    --navy: #0c4a6e;
  }

  .demo-embed {
    position: relative;
    width: 100%;
    height: 80vh;
    max-height: 800px;
    min-height: 560px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(14, 165, 233, 0.2);
    border: 1px solid rgba(14, 165, 233, 0.15);
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
  }

  /* ── HEADER ── */
  #header {
    height: 52px;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 12px rgba(14,165,233,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    gap: 16px;
  }
  .logo { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; color: var(--accent); white-space: nowrap; }
  .logo span { color: var(--text); }

  /* ── TABS ── */
  #tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 8px; padding: 4px; }
  .tab-btn {
    padding: 6px 16px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
  }
  .tab-btn.active { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
  .tab-btn:hover:not(.active) { color: var(--text); }

  .live-indicator { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; white-space: nowrap; }
  .live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); animation: pulse-green 2s infinite; }
  @keyframes pulse-green {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
    70%  { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
  }

  /* ── TAB VIEWS ── */
  .tab-view { display: none; height: calc(100% - 52px); }
  .tab-view.active { display: flex; }

  /* ════════════════════════════════════════
     TAB 1 — THE JOURNEY
  ════════════════════════════════════════ */
  #view-journey { flex-direction: row; }

  #journey-map { flex: 1; min-width: 0; min-height: 400px; }
  #journey-map .leaflet-container { width: 100%; height: 100%; min-height: 400px; }

  #journey-sidebar {
    width: 320px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .journey-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
  }
  .journey-header h2 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
  .journey-header p  { font-size: 12px; color: var(--muted); line-height: 1.5; }

  #journey-steps {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .journey-step {
    display: flex;
    gap: 12px;
    padding: 12px 8px;
    border-radius: 8px;
    transition: background 0.3s;
    position: relative;
  }
  .journey-step.active-step { background: rgba(14,165,233,0.08); border: 1px solid rgba(14,165,233,0.2); }
  .journey-step.done-step   { opacity: 0.5; }

  .step-icon-col { display: flex; flex-direction: column; align-items: center; gap: 0; }
  .step-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: border-color 0.4s, background 0.4s;
    z-index: 1;
  }
  .journey-step.active-step .step-icon { border-color: var(--accent); background: rgba(14,165,233,0.15); }
  .journey-step.done-step   .step-icon { border-color: var(--green);  background: rgba(34,197,94,0.1); }

  .step-connector {
    width: 2px;
    flex: 1;
    min-height: 16px;
    background: var(--border);
    margin: 2px auto;
    transition: background 0.4s;
  }
  .step-connector.lit { background: var(--accent); }

  .step-content { flex: 1; padding-top: 6px; }
  .step-title { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
  .step-subtitle { font-size: 11px; color: var(--muted); line-height: 1.5; }
  .step-tag {
    display: inline-block;
    margin-top: 5px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }
  .step-tag.source    { background: rgba(59,130,246,0.15); color: var(--blue); }
  .step-tag.treatment { background: rgba(234,179,8,0.15);  color: var(--yellow); }
  .step-tag.bulk      { background: rgba(249,115,22,0.15); color: var(--orange); }
  .step-tag.storage   { background: rgba(14,165,233,0.15); color: var(--accent); }
  .step-tag.product   { background: rgba(34,197,94,0.15);  color: var(--green); border: 1px solid rgba(34,197,94,0.3); }

  #journey-nrw {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: linear-gradient(135deg, #fff1f2 0%, #ffe4e6 100%);
    flex-shrink: 0;
  }
  #journey-nrw .nrw-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
  #journey-nrw .nrw-stat  { font-size: 26px; font-weight: 800; color: var(--red); }
  #journey-nrw .nrw-sub   { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.5; }

  #journey-cta {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }
  #journey-cta button {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
  }
  #journey-cta button:hover { opacity: 0.85; }

  /* ════════════════════════════════════════
     TAB 2 — LIVE NETWORK
  ════════════════════════════════════════ */
  #view-network { flex-direction: column; }

  /* Stats bar */
  #stats-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  }
  .stat-item {
    flex: 1;
    padding: 8px 16px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
  }
  .stat-item:last-child { border-right: none; }
  .stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
  .stat-value { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); }
  .stat-value.alert-val { color: var(--red); }
  .stat-sub { font-size: 10px; color: var(--muted); }

  #network-body { display: flex; flex: 1; overflow: hidden; }

  /* Map */
  #map-container { flex: 1; position: relative; min-width: 0; }
  #map { width: 100%; height: 100%; }
  #map-hint {
    position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    background: rgba(255,255,255,0.92); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px 16px; font-size: 12px; color: var(--muted);
    pointer-events: none; transition: opacity 0.5s; z-index: 1000; white-space: nowrap;
    box-shadow: 0 2px 12px rgba(14,165,233,0.12);
  }
  #reset-btn {
    display: none; position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
    z-index: 1000; background: var(--surface); border: 1px solid var(--border);
    color: var(--text); padding: 8px 20px; border-radius: 8px; font-size: 13px;
    font-weight: 600; cursor: pointer; transition: background 0.2s;
  }
  #reset-btn:hover { background: var(--border); }

  /* Side panels */
  #side-panels {
    width: 460px; flex-shrink: 0; display: flex;
    flex-direction: column; border-left: 1px solid var(--border); overflow: hidden;
  }

  #sensor-panel { flex: 1; display: flex; flex-direction: column; border-bottom: 1px solid var(--border); overflow: hidden; }
  .panel-header {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--muted); flex-shrink: 0;
    display: flex; align-items: center; justify-content: space-between;
  }
  #sensor-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }

  .sensor-card {
    background: #f8fafc; border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px;
    display: grid; grid-template-columns: 1fr 1fr 1fr auto;
    align-items: center; gap: 8px; transition: border-color 0.3s, background 0.3s;
  }
  .sensor-card.affected    { border-color: var(--orange); background: rgba(234,88,12,0.05); }
  .sensor-card.leak-source { border-color: var(--red);    background: rgba(220,38,38,0.06); }

  .sensor-id   { font-size: 13px; font-weight: 700; color: var(--accent); }
  .sensor-addr { font-size: 10px; color: var(--muted); grid-column: 1 / -1; margin-top: -4px; }
  .sensor-metric { text-align: center; }
  .sensor-metric .label { font-size: 10px; color: var(--muted); margin-bottom: 2px; }
  .sensor-metric .value { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; transition: color 0.3s; }
  .sensor-metric .value.drop   { color: var(--red); }
  .sensor-metric .value.normal { color: var(--text); }

  .sensor-status { width: 10px; height: 10px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
  .sensor-status.warn  { background: var(--orange); }
  .sensor-status.alert { background: var(--red); animation: blink 0.8s infinite; }
  @keyframes blink { 50% { opacity: 0.2; } }

  #water-loss {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: none; flex-direction: column; gap: 4px; flex-shrink: 0;
  }
  #water-loss.visible { display: flex; }
  .loss-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
  .loss-values { display: flex; gap: 24px; }
  .loss-item { display: flex; flex-direction: column; }
  .loss-num  { font-size: 22px; font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; }
  .loss-unit { font-size: 11px; color: var(--muted); }

  /* Alert feed */
  #alert-panel { height: 280px; flex-shrink: 0; display: flex; flex-direction: column; overflow: hidden; }
  #alert-list  { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
  #alert-quiet { display: flex; align-items: center; justify-content: center; height: 100%; flex-direction: column; gap: 8px; color: var(--muted); font-size: 13px; }
  #alert-quiet .quiet-icon { font-size: 28px; opacity: 0.4; }

  .alert-card {
    border-radius: 8px; padding: 10px 12px; border-left: 3px solid transparent;
    background: #f8fafc; border: 1px solid var(--border);
    opacity: 0; transform: translateY(8px);
    transition: opacity 0.4s, transform 0.4s; font-size: 12px; line-height: 1.5;
  }
  .alert-card.visible { opacity: 1; transform: none; }
  .alert-card.ai     { border-left-color: var(--red); }
  .alert-card.tech   { border-left-color: var(--orange); }
  .alert-card.mgr    { border-left-color: var(--yellow); }
  .alert-card.ticket { border-left-color: var(--blue); }

  .alert-time  { font-size: 10px; color: var(--muted); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
  .alert-title { font-weight: 700; margin-bottom: 3px; }
  .alert-title.ai     { color: var(--red); }
  .alert-title.tech   { color: var(--orange); }
  .alert-title.mgr    { color: var(--yellow); }
  .alert-title.ticket { color: var(--blue); }
  .alert-body  { color: var(--muted); }
  .alert-body strong { color: var(--text); }

  /* Leaflet overrides */
  .demo-embed .leaflet-container { background: #e0f2fe !important; }
  .demo-embed .leaflet-tile { filter: brightness(1.05) saturate(0.7); }
  .demo-embed ::-webkit-scrollbar { width: 4px; }
  .demo-embed ::-webkit-scrollbar-track { background: transparent; }
  .demo-embed ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  .demo-embed .leaflet-popup-content-wrapper {
    background: var(--surface) !important; border: 1px solid var(--border) !important;
    border-radius: 8px !important; color: var(--text) !important;
    box-shadow: 0 8px 32px rgba(14,165,233,0.15) !important;
  }
  .demo-embed .leaflet-popup-tip { background: var(--surface) !important; }
  .demo-embed .leaflet-popup-content { margin: 12px 14px !important; font-size: 12px !important; line-height: 1.6 !important; }
  .demo-embed .popup-title { font-weight: 700; font-size: 13px; margin-bottom: 6px; color: var(--accent); }
  .demo-embed .popup-row { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); }
  .demo-embed .popup-row span:last-child { color: var(--text); font-weight: 600; }
  .demo-embed .popup-action {
    margin-top: 10px; width: 100%; padding: 7px;
    background: var(--red); color: #fff; border: none; border-radius: 6px;
    font-size: 12px; font-weight: 700; cursor: pointer; transition: opacity 0.2s;
  }
  .demo-embed .popup-action:hover { opacity: 0.85; }
  .demo-embed .popup-action:disabled { background: var(--muted); cursor: default; }

  .demo-embed .leak-pulse {
    width: 20px; height: 20px; border-radius: 50%;
    background: rgba(239,68,68,0.6);
    animation: leak-ring 1.2s ease-out infinite;
  }
  @keyframes leak-ring {
    0%   { transform: scale(0.8); opacity: 1; box-shadow: 0 0 0 0 rgba(239,68,68,0.6); }
    100% { transform: scale(2.4); opacity: 0; box-shadow: 0 0 0 20px rgba(239,68,68,0); }
  }

  /* ════════════════════════════════════════
     MOBILE — max 768px
     Desktop layout untouched above this
  ════════════════════════════════════════ */
  @media (max-width: 768px) {

    /* Let the widget grow with its content on mobile instead of clipping */
    .demo-embed { height: auto; max-height: none; overflow: visible; }

    /* Header — stack logo + tabs vertically */
    #header {
      height: auto;
      flex-wrap: wrap;
      padding: 10px 14px;
      gap: 8px;
    }
    #tabs { width: 100%; justify-content: center; }
    .tab-btn { padding: 6px 12px; font-size: 12px; }
    .live-indicator { font-size: 12px; }

    /* Tab views — full height auto, column layout */
    .tab-view { height: auto; min-height: calc(100svh - 90px); flex-direction: column !important; }

    /* ── JOURNEY TAB ── */
    #journey-map { height: 45svh; min-height: 220px; width: 100%; }
    #journey-sidebar { width: 100%; border-left: none; border-top: 1px solid var(--border); }
    #journey-steps { max-height: 320px; }
    .journey-step { padding: 10px 6px; }

    /* ── NETWORK TAB ── */
    #view-network { overflow-y: auto; }

    /* Stats bar — 2×2 grid */
    #stats-bar { display: grid; grid-template-columns: 1fr 1fr; }
    .stat-item { border-right: none; border-bottom: 1px solid var(--border); }
    .stat-item:nth-child(odd)  { border-right: 1px solid var(--border); }
    .stat-item:nth-child(3),
    .stat-item:nth-child(4)    { border-bottom: none; }
    .stat-value { font-size: 15px; }

    /* Network body — stack map over panels */
    #network-body { flex-direction: column; }

    /* Map — fixed height on mobile */
    #map-container { height: 55svh; min-height: 280px; width: 100%; }
    #map { height: 100%; }

    /* Side panels — full width, stacked */
    #side-panels {
      width: 100%;
      border-left: none;
      border-top: 1px solid var(--border);
      max-height: none;
    }

    /* Sensor panel — don't cap height on mobile */
    #sensor-panel { flex: none; max-height: none; overflow: visible; }
    #sensor-list  { overflow: visible; max-height: none; }

    /* Sensor cards — 2-col grid on mobile */
    .sensor-card {
      grid-template-columns: 1fr 1fr auto;
      grid-template-rows: auto auto;
    }
    .sensor-addr { grid-column: 1 / -1; }

    /* Alert panel — full height, no cap */
    #alert-panel { height: auto; }
    #alert-list  { max-height: none; overflow: visible; }

    /* Reset button — wider on mobile */
    #reset-btn { width: calc(100% - 32px); text-align: center; }

    /* Map hint — smaller text */
    #map-hint { font-size: 11px; padding: 6px 12px; bottom: 10px; }

    /* Journey CTA button */
    #journey-cta button { font-size: 14px; padding: 12px; }
  }

  /* Extra small — phones under 400px */
  @media (max-width: 400px) {
    .tab-btn { padding: 5px 8px; font-size: 11px; }
    .stat-value { font-size: 13px; }
    #map-container { height: 50svh; }
  }

