/* ============================================================
   Womarkt OS — Mobile shell (320–768px)
   Loaded after app.css / hud-theme.css — desktop unchanged above 768px
   ============================================================ */

:root {
  --mobile-touch: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --mobile-drawer-width: min(280px, 88vw);
}

/* Topbar brand filter (base — used on all viewports) */
.brand-context-wrap {
  position: relative;
  z-index: 140;
  pointer-events: auto;
}

.brand-context-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--mobile-touch);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.brand-context-trigger:hover,
.brand-context-trigger:focus-visible {
  border-color: rgba(0, 212, 170, 0.45);
  outline: none;
  box-shadow: 0 0 0 1px rgba(0, 212, 170, 0.2);
}

.brand-context-sector {
  color: var(--text);
  white-space: nowrap;
}

.brand-context-sep {
  color: var(--text3);
  opacity: 0.8;
}

.brand-context-brand {
  color: var(--accent-bright);
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-context-chevron {
  font-size: 9px;
  color: var(--text3);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.brand-context-chevron--open {
  transform: rotate(180deg);
}

.brand-filter-backdrop {
  position: fixed;
  inset: 0;
  z-index: 139;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.brand-filter-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 141;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 24px));
  max-height: 260px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  touch-action: manipulation;
}

.brand-filter-panel-head {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  padding: 2px 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.brand-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-size: 11px;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  min-height: var(--mobile-touch);
}

.brand-filter-name {
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
}

.brand-filter-name:hover {
  color: var(--accent-bright);
}

.brand-filter-item input {
  flex-shrink: 0;
  pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Sentra IDE — conversation layout (≤1200px: full-screen sheet, no overlap)
   Fixes app.css panel hide + flex height chain for chat composer/messages
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1200px) {
  .sentra-seam-toggle {
    display: none !important;
  }

  .right-panel {
    display: flex !important;
    flex-direction: column;
    position: fixed !important;
    inset: 0;
    top: var(--safe-top);
    bottom: var(--safe-bottom);
    left: 0;
    right: 0;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100vw;
    z-index: 200;
    overflow: hidden;
    border-left: none !important;
    box-shadow: none;
  }

  .right-panel .sentra-agent-panel,
  .sentra-agent-panel {
    display: flex !important;
    flex: 1 1 auto;
    flex-direction: column;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .sentra-agent-panel .sap-header {
    flex-shrink: 0;
    padding-right: calc(var(--mobile-touch) + 12px);
    align-items: flex-start;
    gap: 8px;
  }

  .sentra-agent-panel .sap-header-leading {
    min-width: 0;
    padding-right: 8px;
  }

  .sentra-agent-panel .sap-brand-badge {
    display: inline-flex;
  }

  .sentra-agent-panel .sap-tabs {
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .sentra-agent-panel .sap-tabs::-webkit-scrollbar {
    display: none;
  }

  .sentra-agent-panel .sap-tab {
    flex-shrink: 0;
    min-height: 40px;
  }

  .sentra-agent-panel .sap-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .sap-chat-tab {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  .sap-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sap-chat-composer {
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-bottom: calc(12px + var(--safe-bottom));
  }

  .sap-composer-box {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .sap-composer-context {
    max-height: 140px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sap-chat-input {
    font-size: 16px;
    max-width: 100%;
  }

  .sap-chat-send {
    width: var(--mobile-touch);
    height: var(--mobile-touch);
    min-width: var(--mobile-touch);
  }

  .sap-chat-msg-content {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .sap-chat-welcome {
    padding: 24px 16px;
    justify-content: flex-start;
  }

  .sap-query-tabs,
  .sap-query-chips {
    max-width: 100%;
  }

  .context-shelf {
    flex-shrink: 0;
    max-width: 100%;
    overflow-x: auto;
  }

  .sentra-mobile-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 210;
    width: var(--mobile-touch);
    height: var(--mobile-touch);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(10, 10, 10, 0.9);
    color: var(--text);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 14px;
    overflow-x: hidden;
  }

  body {
    overflow-x: hidden;
  }

  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
  }

  .app-shell > .main-row {
    min-width: 0;
    position: relative;
  }

  /* ── Activity bar: hide on phone — sidebar drawer covers nav ── */
  .activity-bar {
    display: none;
  }

  /* ── Sidebar off-canvas drawer ── */
  .sidebar-toggle-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .sidebar-wrapper {
    position: fixed !important;
    left: 0;
    top: var(--safe-top);
    bottom: var(--safe-bottom);
    width: var(--mobile-drawer-width) !important;
    min-width: 0 !important;
    max-width: var(--mobile-drawer-width);
    transform: translateX(-105%);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    z-index: 120;
    flex-shrink: 0;
    overflow: visible !important;
    box-shadow: none;
  }

  .sidebar-toggle-input:checked ~ .sidebar-wrapper {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.55);
  }

  .sidebar-wrapper .sidebar,
  .sidebar-wrapper--open .sidebar {
    display: flex !important;
    width: 100% !important;
    min-width: 0 !important;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Hide the seam toggle on mobile — mobile menu toggle handles it */
  .sidebar-seam-toggle {
    display: none !important;
  }

  .nav-item,
  .nav-button {
    min-height: var(--mobile-touch);
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .mobile-menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: calc(var(--safe-top) + 8px);
    left: calc(var(--safe-left) + 8px);
    z-index: 130;
    width: var(--mobile-touch);
    height: var(--mobile-touch);
    padding: 0;
    border: 1px solid rgba(0, 172, 172, 0.28);
    border-radius: 10px;
    background: rgba(10, 10, 10, 0.92);
    color: var(--text);
    cursor: pointer;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }

  .mobile-menu-icon {
    pointer-events: none;
    font-size: 18px;
    line-height: 1;
  }

  .sidebar-backdrop {
    display: none;
  }

  .sidebar-toggle-input:checked ~ .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    top: var(--safe-top);
    bottom: var(--safe-bottom);
    z-index: 110;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
  }

  /* ── Main content ── */
  .main-panel {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .terminal-layout,
  .terminal-main {
    min-width: 0;
    max-width: 100%;
  }

  .main-scroll {
    padding: 12px;
    padding-left: max(12px, var(--safe-left));
    padding-right: max(12px, var(--safe-right));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Topbar ── */
  .topbar {
    position: relative;
    z-index: 100;
    pointer-events: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    min-height: auto;
    padding: calc(var(--mobile-touch) + 4px) 0 10px;
    margin: -12px -12px 8px;
    padding-left: max(12px, var(--safe-left));
    padding-right: max(12px, var(--safe-right));
    border-bottom: 1px solid var(--border);
  }

  .topbar-leading {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    min-width: 0;
    overflow: visible;
  }

  .sector-selector {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  .sector-label {
    font-size: 11px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-context-wrap {
    width: 100%;
    max-width: 100%;
    z-index: 145;
  }

  .brand-context-trigger {
    width: 100%;
    max-width: 100%;
    min-height: var(--mobile-touch);
    justify-content: flex-start;
    font-size: 11px;
    padding: 0 12px;
  }

  .brand-context-brand {
    max-width: none;
    flex: 1 1 auto;
    text-align: left;
  }

  .brand-filter-panel {
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    max-height: min(50dvh, 320px);
    z-index: 146;
  }

  .brand-filter-item {
    min-height: var(--mobile-touch);
    padding: 4px 0;
    font-size: 12px;
  }

  .page-title {
    white-space: normal;
    max-width: 100%;
    font-size: 16px;
    line-height: 1.25;
    word-break: break-word;
  }

  .page-subtitle {
    white-space: normal;
    max-width: 100%;
    font-size: 11px;
  }

  .module-context-badge {
    margin-left: 0;
    margin-top: 4px;
    display: inline-block;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
    row-gap: 8px;
  }

  .topbar-actions .btn,
  .topbar-actions .btn-ghost,
  .topbar-actions .notif-bell,
  .topbar-actions .profile-chip,
  .topbar-actions .role-switcher-trigger,
  .topbar-actions .lang-select,
  .topbar-actions .sector-select {
    min-height: var(--mobile-touch);
  }

  .lang-selector {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .lang-select,
  .sector-select {
    min-height: var(--mobile-touch);
    padding: 8px 10px;
    font-size: 12px;
  }

  .ticker-strip {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .profile-chip {
    max-width: none;
    min-height: var(--mobile-touch);
    padding: 6px 10px 6px 6px;
  }

  .profile-chip-text {
    display: none;
  }

  .profile-chip-caret {
    display: none;
  }

  .profile-dropdown-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 12px 12px 0 0;
    padding-bottom: calc(8px + var(--safe-bottom));
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  }

  .profile-dropdown-item {
    min-height: var(--mobile-touch);
    padding-top: 12px;
    padding-bottom: 12px;
    font-size: 13px;
  }

  .notif-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: min(70vh, 480px);
    border-radius: 12px 12px 0 0;
    padding-bottom: var(--safe-bottom);
  }

  /* Sentra full-screen rules live in @media (max-width: 1200px) above */

  /* ── Status bar ── */
  .status-bar {
    height: auto;
    min-height: 28px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-left: max(8px, var(--safe-left));
    padding-right: max(8px, var(--safe-right));
    scrollbar-width: none;
  }

  .status-bar::-webkit-scrollbar {
    display: none;
  }

  .sb-item {
    flex-shrink: 0;
    font-size: 10px;
    padding: 6px 6px;
  }

  /* ── KPI / dashboard grids ── */
  .kpi-grid,
  .metrics-row,
  .pnl-deductions {
    flex-direction: column;
    gap: 10px;
  }

  .kpi-grid .kpi-card,
  .kpi-grid .metric,
  .metrics-row .metric,
  .metrics-row .kpi-card {
    flex: 1 1 100%;
    min-width: 0 !important;
    width: 100%;
  }

  .dashboard-grid,
  .ceo-intel-grid,
  .recon-grid,
  .finding-grid,
  .portfolio-grid,
  .g2,
  .g3,
  .g4,
  .g23,
  .g32 {
    grid-template-columns: 1fr !important;
  }

  .dashboard-hero {
    flex-direction: column;
  }

  .metric-hero .hero-value {
    font-size: 36px;
  }

  .table-wrap,
  .hud-table-wrap,
  .hunting-table-wrap,
  .vault-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    min-width: 520px;
  }

  /* ── Role switcher (dev) ── */
  .role-switcher-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    z-index: 500;
  }

  .role-switcher-body {
    max-height: calc(100dvh - 7.5rem);
    overflow-y: auto;
  }

  .role-card-grid {
    grid-template-columns: 1fr;
  }

  .role-switcher-trigger {
    min-width: 0;
    max-width: 140px;
  }

  /* ── Page tabs ── */
  .page-tab-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-left: 0;
    padding-right: 0;
  }

  .page-tab {
    min-height: var(--mobile-touch);
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .main-scroll {
    padding: 10px;
    padding-left: max(10px, var(--safe-left));
    padding-right: max(10px, var(--safe-right));
  }

  .topbar {
    padding-top: calc(var(--mobile-touch) + 2px);
    margin-left: -10px;
    margin-right: -10px;
    padding-left: max(10px, var(--safe-left));
    padding-right: max(10px, var(--safe-right));
  }

  .page-title {
    font-size: 15px;
  }

  .metric-hero .hero-value {
    font-size: 28px;
  }

  .topbar-actions .topbar-ai-link {
    display: none;
  }

  .sb-sep:nth-of-type(n+4),
  .status-bar .sb-item:nth-child(n+7) {
    display: none;
  }

  .auth-layout {
    padding: max(20px, var(--safe-top)) 14px max(20px, var(--safe-bottom));
    align-items: flex-start;
    min-height: 100dvh;
  }

  .auth-shell {
    max-width: 100%;
  }

  .auth-layout .auth-card .hud-card-body {
    padding: 24px 20px 28px;
  }

  .auth-form .form-input,
  .auth-form .btn-block {
    min-height: var(--mobile-touch);
    font-size: 16px;
  }
}

/* Desktop-only: hide mobile Sentra close control */
@media (min-width: 1201px) {
  .sentra-mobile-close {
    display: none !important;
  }
}
