/* ════════════════════════════════════════════════════════════════════════════
   Portway Work — responsive layer (container-query driven) + review chrome
   The app reflows against its OWN width (container queries), so the device-
   preview stage can show desktop vs phone without touching the viewport.
   PORT NOTE: swap `@container app` → `@media` and the phone stage away when
   moving into webapp.html. Breakpoint: 720px.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── review chrome (NOT part of the app — strip on port) ─────────────────── */
.stage-chrome {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: #20211d; color: #e9e7df;
  font-size: 12px; font-family: var(--font-sans);
}
.stage-chrome .ch-title { font-weight: 600; letter-spacing: 0.01em; }
.stage-chrome .ch-title b { color: #fff; }
.stage-chrome .ch-note { color: #9a978c; font-family: var(--font-mono); font-size: 11px; }
.stage-chrome .ch-spacer { margin-left: auto; }
.seg {
  display: inline-flex; background: rgba(255,255,255,0.08); border-radius: 8px; padding: 2px;
}
.seg button {
  appearance: none; border: 0; background: transparent; color: #c8c6bd;
  font: inherit; font-weight: 500; padding: 6px 14px; border-radius: 6px; cursor: pointer;
}
.seg button.active { background: #f4f2ea; color: #20211d; }

/* ── stage + device frame ───────────────────────────────────────────────── */
.stage { padding: 0; transition: background 0.2s; }
.stage[data-device="phone"] {
  display: flex; justify-content: center;
  padding: 28px 16px 40px; background: #d8d6cd;
}
.device { width: 100%; }
.stage[data-device="phone"] .device {
  width: 390px; height: 800px; flex: 0 0 390px;
  background: #1c1c1c; border-radius: 46px; padding: 11px;
  box-shadow: 0 30px 70px -20px rgba(0,0,0,0.5), 0 0 0 2px rgba(255,255,255,0.04) inset;
}
.stage[data-device="phone"] .device .pw-app {
  height: 100%; overflow-y: auto; border-radius: 36px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.stage[data-device="phone"] .device .pw-app::-webkit-scrollbar { display: none; }
/* notch */
.stage[data-device="phone"] .device { position: relative; }
.stage[data-device="phone"] .device::before {
  content: ""; position: absolute; top: 11px; left: 50%; transform: translateX(-50%);
  width: 128px; height: 26px; background: #1c1c1c; border-radius: 0 0 16px 16px; z-index: 60;
}

/* the overflow menu + mobile-only bits hidden by default */
.topbar-menu { display: none; position: absolute; top: 52px; right: 16px; z-index: 70;
  background: var(--b-surface); border: 0.5px solid var(--b-line); border-radius: var(--r-md);
  box-shadow: var(--shadow-pop); padding: 6px; min-width: 200px; flex-direction: column; gap: 2px; }
.topbar-menu.open { display: flex; }
.topbar-menu button { appearance: none; border: 0; background: transparent; text-align: left;
  font: inherit; padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer; color: var(--b-ink);
  display: flex; align-items: center; gap: 9px; min-height: var(--touch); }
.topbar-menu button:hover { background: var(--b-paper); }
.topbar-menu .menu-meta { padding: 8px 12px; font-size: 11px; color: var(--b-muted);
  font-family: var(--b-font-meta); border-top: 0.5px solid var(--b-line-soft); margin-top: 4px; }

/* mobile matrix views hidden on desktop */
.matrix-mobile { display: none; }

/* ════════════════════════════════ MOBILE ═════════════════════════════════ */
@container app (max-width: 720px) {
  .app { padding: 14px 14px 32px; }

  /* —— topbar collapses —— */
  .topbar { gap: 10px; padding: 10px 0 14px; position: relative; }
  .brand-divider, .brand-stack { display: none; }
  .brand-logo .wordmark { font-size: 18px; }
  .topbar-actions { gap: 8px; }
  .topbar-actions .sync-btn .lbl,
  .topbar-actions .tenant-badge.plan,
  .topbar-actions .status-live .lbl { display: none; }   /* icon/dot only */
  .topbar-actions .sk-btn { display: none; }             /* moved into overflow menu */
  .sync-btn { padding: 8px; min-width: var(--touch); min-height: var(--touch); justify-content: center; }
  .status-live { padding: 8px; min-width: 40px; justify-content: center; }
  .topbar-overflow {
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--touch); height: var(--touch); border-radius: var(--r-sm);
    background: var(--b-surface); border: 0.5px solid var(--b-line); cursor: pointer; color: var(--b-ink);
  }
  .topbar-overflow .ic { width: 18px; height: 18px; }

  /* —— tab-nav scrolls —— */
  .tab-nav { overflow-x: auto; scrollbar-width: none; gap: 0; margin-bottom: 18px; }
  .tab-nav::-webkit-scrollbar { display: none; }
  .tab-btn { padding: 11px 14px; flex: 0 0 auto; }

  /* —— master–detail → swap with slide —— */
  .layout { display: block; min-height: 0; }
  .list-panel { align-self: stretch; }
  .list-items { max-height: none; }
  .item-chevron, svg.item-chevron { display: block; }
  .detail-panel { display: none; padding: 16px 16px 28px; }
  .layout[data-detail-open="1"] .list-panel { display: none; }
  .layout[data-detail-open="1"] .detail-panel { display: block; animation: pw-slide-in 0.26s var(--ease); }
  @keyframes pw-slide-in { from { transform: translateX(14px); opacity: 0; } to { transform: none; opacity: 1; } }

  .detail-back {
    display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
    background: transparent; border: 0; color: var(--b-accent-ink); font: inherit; font-weight: 500;
    padding: 6px 0; margin-bottom: 12px; min-height: 40px;
  }
  .detail-back .ic { width: 17px; height: 17px; }
  .detail-head { flex-wrap: wrap; }
  .detail-name { font-size: 19px; }
  .detail-actions { width: 100%; }
  .detail-actions .btn { flex: 1; justify-content: center; min-height: var(--touch); }

  /* —— data-table → label/value cards —— */
  .data-table thead { display: none; }
  .data-table, .data-table tbody { display: block; }
  .data-table tr {
    display: block; border: 0.5px solid var(--b-line); border-radius: var(--r-sm);
    padding: 6px 12px; margin-bottom: 8px; background: var(--b-surface);
  }
  .data-table tr.redundant { background: var(--c-amber-soft); }
  .data-table td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 8px 0; border: none; border-bottom: 0.5px solid var(--b-line-soft);
  }
  .data-table tr td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label); font-size: 11px; color: var(--b-muted);
    text-transform: uppercase; letter-spacing: 0.4px; font-family: var(--b-font-meta); flex-shrink: 0;
  }
  .data-table td .cal-name { text-align: right; }

  .validation-detail { grid-template-columns: 1fr; gap: 2px; }
  .validation-detail .label { margin-top: 6px; }

  /* —— matrix: desktop table hidden unless scroll-mode —— */
  .matrix-desktop { display: none; }
  .matrix-mobile { display: block; }
  [data-matrix-mode="scroll"] .matrix-desktop { display: block; }
  [data-matrix-mode="scroll"] .matrix-mobile .mm-view { display: none; }
  [data-matrix-mode="accordion"] .mm-accordion { display: block; }
  [data-matrix-mode="accordion"] .mm-focused,
  [data-matrix-mode="accordion"] .mm-scrollnote { display: none; }
  [data-matrix-mode="focused"] .mm-focused { display: block; }
  [data-matrix-mode="focused"] .mm-accordion,
  [data-matrix-mode="focused"] .mm-scrollnote { display: none; }
  [data-matrix-mode="scroll"] .mm-accordion,
  [data-matrix-mode="scroll"] .mm-focused { display: none; }
  [data-matrix-mode="scroll"] .mm-scrollnote { display: block; }

  .matrix-container { max-height: 60vh; }
  .matrix-table thead th { min-width: 78px; }
}

/* ════════════════════════ matrix mobile components ═══════════════════════ */
/* shown only inside .matrix-mobile (which is display:none on desktop) */

/* mode badge row */
.mm-modebar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
  font-size: 12px; color: var(--b-muted); font-family: var(--b-font-meta);
}
.mm-modebar .mm-pill {
  background: var(--b-accent-soft); color: var(--b-accent-ink);
  padding: 4px 9px; border-radius: var(--r-sm); font-weight: 500;
}

/* accordion */
.mm-acc-row { border: 0.5px solid var(--b-line); border-radius: var(--r-md); margin-bottom: 8px; background: var(--b-surface); overflow: hidden; }
.mm-acc-row.inactive { opacity: 0.62; }
.mm-acc-head {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; background: transparent; border: 0; cursor: pointer; text-align: left;
  font: inherit; color: var(--b-ink); min-height: var(--touch);
}
.mm-acc-head .mm-role { flex: 1; min-width: 0; }
.mm-acc-head .mm-role .nm { display: block; font-weight: 500; color: var(--b-accent-ink); }
.mm-acc-head .mm-role .em { display: block; font-size: 11px; color: var(--b-muted); font-family: var(--font-mono); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mm-acc-head .mm-frac { font-size: 12px; color: var(--b-muted); font-family: var(--b-font-meta); }
.mm-acc-head .mm-caret { width: 16px; height: 16px; color: var(--b-muted); transition: transform var(--dur) var(--ease); }
.mm-acc-row.open .mm-acc-head .mm-caret { transform: rotate(90deg); }
.mm-acc-body { display: none; padding: 4px 8px 10px; border-top: 0.5px solid var(--b-line-soft); }
.mm-acc-row.open .mm-acc-body { display: block; }
.mm-cat-toggle {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 8px; background: transparent; border: 0; border-bottom: 0.5px solid var(--b-line-soft);
  cursor: pointer; font: inherit; color: var(--b-ink); text-align: left; min-height: var(--touch);
}
.mm-cat-toggle:last-child { border-bottom: none; }
.mm-cat-toggle .mm-cat-nm { flex: 1; font-weight: 500; }
.mm-cat-toggle .mm-cat-usage { font-size: 11px; color: var(--b-muted); font-family: var(--b-font-meta); }
.mm-switch { position: relative; width: 40px; height: 24px; border-radius: 999px; background: var(--b-line); transition: background var(--dur) var(--ease); flex-shrink: 0; }
.mm-switch i { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform var(--dur) var(--ease); }
.mm-cat-toggle[aria-pressed="true"] .mm-switch { background: var(--c-green); }
.mm-cat-toggle[aria-pressed="true"] .mm-switch i { transform: translateX(16px); }
.mm-acc-row.inactive .mm-acc-head { cursor: default; }

/* focused editor */
.mm-focused .mm-pickers { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 16px; }
.mm-field label { display: block; font-size: 11px; color: var(--b-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.4px; font-family: var(--b-font-meta); }
.mm-field select { width: 100%; padding: 12px; min-height: var(--touch); font-size: 15px; border: 0.5px solid var(--b-line); border-radius: var(--r-md); background: var(--b-surface); color: var(--b-ink); font-family: inherit; }
.mm-focus-card {
  border: 0.5px solid var(--b-line); border-radius: var(--r-lg); padding: 20px; background: var(--b-surface);
  display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center;
}
.mm-focus-card .fc-role { font-size: 13px; color: var(--b-muted); font-family: var(--font-mono); }
.mm-focus-card .fc-cat { font-size: 20px; font-weight: 500; }
.mm-focus-card .fc-usage { font-size: 12px; color: var(--b-muted); font-family: var(--b-font-meta); }
.mm-bigswitch {
  width: 100%; max-width: 280px; padding: 16px; border-radius: var(--r-md); border: 0;
  cursor: pointer; font: inherit; font-weight: 500; font-size: 15px; min-height: 56px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: background var(--dur) var(--ease);
}
.mm-bigswitch[data-on="1"] { background: var(--c-green-soft); color: var(--c-green); }
.mm-bigswitch[data-on="0"] { background: var(--b-paper); color: var(--b-muted); border: 0.5px solid var(--b-line); }
.mm-bigswitch .ic { width: 20px; height: 20px; }
.mm-focus-summary { margin-top: 18px; }
.mm-focus-summary .fs-title { font-size: 12px; color: var(--b-muted); text-transform: uppercase; letter-spacing: 0.4px; font-family: var(--b-font-meta); margin-bottom: 9px; }
.mm-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.mm-chip { font-size: 12px; padding: 6px 11px; border-radius: var(--r-sm); background: var(--c-green-soft); color: var(--c-green); font-weight: 500; }
.mm-chip.muted { background: var(--b-line-soft); color: var(--b-muted); font-weight: 400; }

/* scroll-mode note */
.mm-scrollnote {
  display: none; font-size: 12px; color: var(--c-amber); background: var(--c-amber-soft);
  padding: 10px 12px; border-radius: var(--r-sm); margin-bottom: 12px; line-height: 1.5;
}
