:root {
  --app-safe-top: env(safe-area-inset-top, 0px);
  --app-safe-right: env(safe-area-inset-right, 0px);
  --app-safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-safe-left: env(safe-area-inset-left, 0px);
  --app-nav-height: 64px;
}

.enzy-bottom-nav,
.enzy-more-backdrop,
.enzy-more-sheet,
.enzy-install-guide,
.enzy-app-toast,
.enzy-network-banner {
  display: none;
}

.enzy-install-entry[hidden] {
  display: none !important;
}

@media (display-mode: standalone) {
  html {
    min-height: 100%;
    background: #050608;
  }

  body {
    min-height: 100svh;
    overscroll-behavior-y: none;
  }
}

@media (max-width: 780px) {
  html {
    -webkit-text-size-adjust: 100%;
    background: #050608;
  }

  body {
    min-width: 0 !important;
    padding-bottom: calc(var(--app-nav-height) + var(--app-safe-bottom)) !important;
  }

  button,
  a,
  input,
  select,
  summary {
    touch-action: manipulation;
  }

  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .terminal-shell {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow: visible !important;
  }

  .terminal-rail {
    display: none !important;
  }

  .terminal-main,
  .profile-main,
  .terminal-main.wrap {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: max(8px, var(--app-safe-top)) max(8px, var(--app-safe-right)) 12px max(8px, var(--app-safe-left)) !important;
    overflow-x: clip !important;
  }

  .enzy-bottom-nav {
    position: fixed;
    z-index: 300;
    right: 0;
    bottom: 0;
    left: 0;
    min-height: calc(var(--app-nav-height) + var(--app-safe-bottom));
    padding: 5px max(6px, var(--app-safe-right)) var(--app-safe-bottom) max(6px, var(--app-safe-left));
    border-top: 1px solid #26313e;
    background: rgba(6, 9, 13, .96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    direction: ltr;
  }

  .enzy-bottom-link {
    min-width: 0;
    min-height: 54px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #7f8b99;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    padding: 3px 2px;
    text-decoration: none;
    font: inherit;
    cursor: pointer;
  }

  .enzy-bottom-link.active {
    color: #f4f7fa;
    background: #111923;
  }

  .enzy-bottom-icon {
    min-height: 22px;
    display: grid;
    place-items: center;
    font-size: 19px;
    font-weight: 950;
    line-height: 1;
  }

  .enzy-bottom-label {
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
    font-size: 9px;
    font-weight: 850;
    white-space: nowrap;
  }

  .enzy-more-backdrop {
    position: fixed;
    z-index: 390;
    inset: 0;
    background: rgba(0, 0, 0, .66);
  }

  .enzy-more-backdrop.open {
    display: block;
  }

  .enzy-more-sheet,
  .enzy-install-guide {
    position: fixed;
    z-index: 400;
    right: max(8px, var(--app-safe-right));
    bottom: calc(var(--app-nav-height) + var(--app-safe-bottom) + 8px);
    left: max(8px, var(--app-safe-left));
    max-height: min(680px, calc(100svh - 90px));
    overflow-y: auto;
    border: 1px solid #2a3543;
    border-radius: 18px;
    background: #0c1118;
    color: #edf2f7;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .7);
    padding: 10px 12px 14px;
    transform: translateY(18px);
    opacity: 0;
  }

  .enzy-more-sheet.open,
  .enzy-install-guide.open {
    display: block;
    transform: translateY(0);
    opacity: 1;
  }

  .enzy-sheet-handle {
    width: 44px;
    height: 4px;
    margin: 0 auto 10px;
    border-radius: 999px;
    background: #384352;
  }

  .enzy-sheet-title {
    margin: 0 0 10px;
    color: #fff;
    font-size: 16px;
    font-weight: 950;
  }

  .enzy-more-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .enzy-more-item {
    min-height: 48px;
    border: 1px solid #222d3a;
    border-radius: 10px;
    background: #090e14;
    color: #dfe6ed;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 11px;
    text-decoration: none;
    font: inherit;
    font-size: 12px;
    font-weight: 850;
    cursor: pointer;
  }

  .enzy-more-item.active {
    border-color: #4c84ce;
    color: #fff;
    background: #102039;
  }

  .enzy-more-item.danger {
    border-color: rgba(239, 98, 106, .45);
    color: #ffb4ba;
  }

  .enzy-install-guide p {
    margin: 8px 0 14px;
    color: #9eabba;
    font-size: 13px;
    line-height: 1.8;
  }

  .enzy-install-guide strong {
    color: #fff;
  }

  .enzy-guide-close {
    width: 100%;
    min-height: 48px;
    border: 1px solid #5b9dff;
    border-radius: 10px;
    background: #11243a;
    color: #fff;
    font: inherit;
    font-weight: 900;
  }

  .enzy-app-toast,
  .enzy-network-banner {
    position: fixed;
    z-index: 360;
    right: max(10px, var(--app-safe-right));
    bottom: calc(var(--app-nav-height) + var(--app-safe-bottom) + 10px);
    left: max(10px, var(--app-safe-left));
    min-height: 46px;
    border: 1px solid #334253;
    border-radius: 11px;
    background: #101720;
    color: #e8edf3;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 11px;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 14px 45px rgba(0, 0, 0, .55);
  }

  .enzy-app-toast.show,
  .enzy-network-banner.show {
    display: flex;
  }

  .enzy-app-toast button {
    min-height: 34px;
    border: 1px solid #5b9dff;
    border-radius: 8px;
    background: #11243a;
    color: #fff;
    padding: 0 10px;
    font: inherit;
    font-weight: 900;
  }

  .enzy-network-banner {
    border-color: #8c6722;
    color: #ffd978;
  }

  /* Exposure Profile: full-width mobile execution view. */
  .profile-main {
    gap: 8px !important;
  }

  .profile-top {
    min-height: 0 !important;
    padding: 12px !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .profile-top h1 {
    font-size: 23px !important;
  }

  .profile-sub {
    font-size: 11px !important;
  }

  .profile-actions {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px !important;
  }

  .profile-actions > * {
    min-width: 0 !important;
    min-height: 44px !important;
    width: 100% !important;
    white-space: normal !important;
  }

  .profile-top .profile-actions a[href="/swing"] {
    display: none !important;
  }

  .profile-top .earnings-notice {
    grid-column: 1 / -1;
  }

  .impact-news {
    height: 40px !important;
  }

  .selector-workspace,
  .selector-head {
    grid-template-columns: 1fr !important;
  }

  .selector-primary,
  .history-top-panel {
    min-width: 0 !important;
    padding: 10px !important;
  }

  .history-top-panel {
    border-left: 0 !important;
    border-top: 1px solid var(--profile-line) !important;
  }

  .search-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }

  .search-wrap,
  .profile-search {
    width: 100% !important;
  }

  .chip-row {
    grid-template-columns: 54px minmax(0, 1fr) !important;
    gap: 6px !important;
  }

  .selector-rows .chips,
  .profile-levels {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    padding-bottom: 5px;
  }

  .profile-chip,
  .level-chip {
    flex: 0 0 auto !important;
    min-height: 40px !important;
  }

  .profile-status {
    min-height: 44px !important;
    white-space: normal !important;
    line-height: 1.45 !important;
    padding-block: 8px !important;
  }

  .decision-read-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .profile-chart-panel,
  .entry-demo-panel,
  .site-collapse {
    border-radius: 8px !important;
  }

  .chart-head {
    padding: 10px !important;
    gap: 9px !important;
  }

  .chart-title {
    font-size: 13px !important;
  }

  .chart-tools {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    overflow-x: auto !important;
    gap: 7px !important;
    padding-bottom: 4px;
  }

  .chart-tools > * {
    flex: 0 0 auto !important;
  }

  .chart-tools .segmented {
    display: flex !important;
  }

  .chart-tools button,
  .chart-tools select,
  .chart-tools input {
    min-height: 40px !important;
  }

  .market-chart-wrap {
    height: 330px !important;
    min-height: 330px !important;
  }

  .chart-wrap {
    height: 300px !important;
    min-height: 300px !important;
  }

  .dark-pool-strip {
    overflow-x: auto !important;
    overscroll-behavior-x: contain;
  }

  .readiness-grid,
  .gate-grid,
  .time-metrics,
  .time-insights,
  .time-grid {
    grid-template-columns: 1fr !important;
  }

  .session-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    overflow: hidden !important;
  }

  .entry-demo-table-wrap {
    overflow: visible !important;
    padding: 8px;
  }

  .entry-demo-table,
  .entry-demo-table tbody,
  .entry-demo-table tr,
  .entry-demo-table td {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .entry-demo-table thead {
    display: none !important;
  }

  .entry-demo-table tr {
    margin-bottom: 9px;
    overflow: hidden;
    border: 1px solid var(--profile-line);
    border-radius: 10px;
    background: #080d13;
  }

  .entry-demo-table tr:last-child {
    margin-bottom: 0;
  }

  .entry-demo-table td {
    min-height: 42px;
    padding: 8px 10px 8px 42% !important;
    position: relative;
    border-right: 0 !important;
    text-align: left;
  }

  .entry-demo-table td::before {
    position: absolute;
    top: 9px;
    left: 10px;
    width: 36%;
    color: var(--profile-muted);
    font-size: 9px;
    font-weight: 900;
    text-transform: uppercase;
  }

  .entry-demo-table td:nth-child(1)::before { content: "Side"; }
  .entry-demo-table td:nth-child(2)::before { content: "State"; }
  .entry-demo-table td:nth-child(3)::before { content: "Reference"; }
  .entry-demo-table td:nth-child(4)::before { content: "Potential entry"; }
  .entry-demo-table td:nth-child(5)::before { content: "Scenario failure"; }
  .entry-demo-table td:nth-child(6)::before { content: "Next level"; }
  .entry-demo-table td:nth-child(7)::before { content: "Evidence"; }

  .entry-demo-table td[colspan] {
    padding-left: 10px !important;
  }

  .entry-demo-table td[colspan]::before {
    content: none;
  }

  /* Heatmap: dense data stays scrollable inside one deliberate surface. */
  .title-bar {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 9px !important;
    padding: 11px !important;
  }

  .title-actions {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px !important;
  }

  .title-actions > * {
    min-height: 44px !important;
  }

  .ticker-selector {
    padding: 9px !important;
  }

  .ticker-search-line {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 7px !important;
  }

  .ticker-search,
  .ticker-hint {
    grid-column: 1 / -1;
    width: 100% !important;
    min-width: 0 !important;
  }

  .ticker-search input,
  .ticker-action,
  .ticker-btn.merged-link {
    min-height: 44px !important;
    height: 44px !important;
  }

  .ticker-btn.merged-link {
    grid-column: 1 / -1;
  }

  .ticker-thin-row {
    grid-template-columns: 54px minmax(0, 1fr) !important;
    gap: 6px !important;
  }

  .ticker-chips {
    padding-bottom: 5px;
    overscroll-behavior-x: contain;
  }

  .ticker-btn {
    min-height: 40px !important;
  }

  .mode-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 7px !important;
  }

  .toggle-group {
    width: 100%;
    overflow-x: auto !important;
    overscroll-behavior-x: contain;
  }

  .toggle-group button {
    flex: 1 0 64px;
    min-height: 42px !important;
    padding-inline: 10px !important;
  }

  .legend-inline {
    margin: 0 !important;
    justify-content: flex-start;
  }

  .horizon-controls {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  .horizon-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    padding-bottom: 4px;
  }

  .horizon-row button {
    flex: 0 0 auto;
    min-height: 40px !important;
  }

  .heatmap-color-legend {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  .heatmap-container {
    width: 100%;
    max-height: min(66svh, 620px) !important;
    border-radius: 9px !important;
    scrollbar-width: thin;
    overscroll-behavior: contain;
  }

  .heatmap-container::after {
    content: "اسحب أفقياً لعرض بقية تواريخ الانتهاء";
    position: sticky;
    right: 8px;
    bottom: 8px;
    float: right;
    margin: 8px;
    padding: 5px 8px;
    border: 1px solid rgba(91, 157, 255, .42);
    border-radius: 999px;
    background: rgba(7, 12, 18, .9);
    color: #bfd6f4;
    font-size: 9px;
    pointer-events: none;
  }

  .heatmap-table th.strike-head,
  .heatmap-table td.strike-cell {
    position: sticky !important;
    left: 0 !important;
    z-index: 12 !important;
    width: 118px !important;
    min-width: 118px !important;
    max-width: 118px !important;
    box-shadow: 3px 0 8px rgba(0, 0, 0, .38);
  }

  .heatmap-table th.strike-head {
    z-index: 20 !important;
  }

  .heatmap-table td.strike-cell {
    background-color: #111923;
  }

  .heatmap-table td {
    min-width: 52px !important;
  }

  .force-strip,
  .decision-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .map-read-grid {
    grid-template-columns: 1fr !important;
  }

  .node-read-scroll {
    overscroll-behavior-x: contain;
  }

  .site-collapse-summary {
    min-height: 48px !important;
  }
}

@media (max-width: 380px) {
  .enzy-bottom-label {
    font-size: 8px;
  }

  .profile-main,
  .terminal-main,
  .terminal-main.wrap {
    padding-inline: 6px !important;
  }

  .decision-read-grid,
  .volume-pressure-panel,
  .session-metrics {
    grid-template-columns: 1fr !important;
  }

  .title-actions,
  .profile-actions {
    grid-template-columns: 1fr !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .enzy-more-sheet,
  .enzy-install-guide {
    transition: none !important;
  }
}
