/* My DCENT responsive layer v9
 * Loaded after app.css. This file deliberately neutralizes intrinsic-width
 * expansion from nested grid/flex children on phones and tablets.
 */

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

.app-shell,
.main-wrap,
.content,
.dashboard-layout,
.traffic-shell,
.grid,
.card,
.page-head,
.chart-card,
.chart-body,
.table-wrap,
.stack-form,
.form-grid,
.service-card,
.invoice-sheet {
  min-width: 0;
  max-width: 100%;
}

.dashboard-layout,
.traffic-shell {
  grid-template-columns: minmax(0, 1fr);
}

.dashboard-layout > *,
.traffic-shell > *,
.grid > *,
.page-head > *,
.chart-head > *,
.service-card > * {
  min-width: 0;
  max-width: 100%;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  touch-action: pan-x pan-y;
}

.data-table {
  max-width: none;
}

img,
svg,
canvas {
  max-width: 100%;
}

@media (max-width: 1024px) {
  .app-shell {
    display: block;
    width: 100%;
  }

  .main-wrap {
    width: 100% !important;
    max-width: 100vw !important;
    margin-left: 0 !important;
    overflow-x: clip;
  }

  .sidebar {
    transform: translateX(-105%);
    transition: transform .22s ease;
    will-change: transform;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-toggle {
    display: grid;
  }

  .content {
    width: 100% !important;
    margin: 0 !important;
  }

  .dashboard-layout,
  .traffic-shell {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }
}

@media (max-width: 850px) {
  :root {
    --mobile-gutter: 14px;
  }

  body {
    font-size: 14px;
  }

  .topbar {
    width: 100%;
    min-width: 0;
    height: 64px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    gap: 10px;
  }

  .menu-toggle {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
  }

  .topbar > div:first-of-type {
    flex: 1 1 auto;
    min-width: 0;
  }

  .topbar > div:first-of-type strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-tools {
    flex: 0 0 auto;
    min-width: 0;
    gap: 5px;
  }

  .topbar-brand {
    display: none;
  }

  .lang-switch {
    gap: 4px;
  }

  .lang-switch a {
    min-width: 36px;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: .8rem;
  }

  .content {
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 18px var(--mobile-gutter) 38px !important;
    overflow: visible !important;
  }

  footer {
    padding: 16px var(--mobile-gutter);
  }

  h1 {
    max-width: 100%;
    font-size: clamp(1.65rem, 8vw, 2rem);
    line-height: 1.08;
    overflow-wrap: anywhere;
  }

  h2,
  h3,
  p,
  .field-help,
  .subline,
  .stat-label,
  .stat-sub {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .eyebrow {
    font-size: .66rem;
    letter-spacing: .1em;
  }

  .page-head {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    gap: 14px;
    margin-bottom: 18px;
  }

  .page-head > div:first-child {
    width: 100%;
    min-width: 0;
  }

  .page-head p {
    width: 100%;
    max-width: 100%;
    white-space: normal;
  }

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

  .page-actions > *,
  .page-actions > form,
  .page-actions .button,
  .page-actions .button-secondary,
  .page-actions .button-ghost,
  .page-actions .button-danger {
    width: 100%;
    max-width: 100%;
  }

  .card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 17px;
    border-radius: 12px;
  }

  .card + .card,
  .grid > .card,
  .grid > article.card,
  .grid > div.card {
    margin-top: 0 !important;
  }

  .grid,
  .grid-2,
  .grid-3,
  .grid-4,
  .dashboard-primary-grid,
  .dashboard-secondary-grid {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px !important;
  }

  .dashboard-layout,
  .traffic-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    gap: 16px !important;
    overflow: visible !important;
  }

  .dashboard-layout > section,
  .dashboard-layout > .page-head,
  .traffic-shell > section,
  .traffic-shell > .page-head {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
  }

  /* Four compact dashboard counters: two columns, not four oversized rows. */
  .dashboard-stat-grid,
  .traffic-stat-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100%;
    gap: 10px !important;
  }

  .dashboard-stat-grid .stat-card,
  .traffic-stat-grid .stat-card {
    min-width: 0;
    min-height: 102px;
    height: auto;
    padding: 15px;
  }

  .stat-value,
  .traffic-stat-grid .stat-value {
    font-size: clamp(1.3rem, 7vw, 1.7rem) !important;
    line-height: 1.08;
    overflow-wrap: anywhere;
  }

  .stat-label {
    font-size: .82rem;
    line-height: 1.25;
  }

  .stat-sub {
    font-size: .72rem;
  }

  .dashboard-primary-grid > article,
  .dashboard-secondary-grid > article {
    width: 100%;
    min-height: 0 !important;
    height: auto !important;
  }

  .hero-card,
  .billing-summary-card,
  .account-summary-card,
  .collector-status-card,
  .recent-customers-card {
    padding: 19px !important;
  }

  .hero-metric {
    font-size: clamp(2.25rem, 14vw, 3rem);
  }

  .card-head-compact {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: start !important;
    gap: 10px;
  }

  .card-head-compact > a,
  .card-head-compact > .button,
  .card-head-compact > .button-ghost,
  .card-head-compact > .button-secondary {
    width: 100%;
  }

  .form-grid,
  form.form-grid,
  .form-grid[style] {
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
  }

  .form-grid .full {
    grid-column: 1 !important;
  }

  .stack-form,
  .fieldset,
  .inline-form,
  .actions {
    max-width: 100%;
    min-width: 0;
  }

  .inline-form,
  .actions {
    flex-wrap: wrap;
  }

  .actions > *,
  .actions > form {
    max-width: 100%;
  }

  input,
  select,
  textarea {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
  }

  .button,
  .button-secondary,
  .button-danger,
  .button-ghost {
    max-width: 100%;
    white-space: normal;
  }

  .key-value {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 3px;
  }

  .key-value > strong {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .service-card {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
  }

  .service-card > div,
  .service-card > [style] {
    width: 100% !important;
    min-width: 0 !important;
  }

  .invoice-sheet {
    width: 100%;
    padding: 16px;
    border-radius: 10px;
  }

  .invoice-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .invoice-head .text-right {
    text-align: left;
  }

  .table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto !important;
    overflow-y: hidden;
  }

  .data-table:not(.traffic-data-table) {
    width: max-content;
    min-width: 720px;
  }

  /* Traffic page */
  .traffic-page-head {
    align-items: start !important;
  }

  .traffic-page-head > div,
  .traffic-back-link {
    width: 100%;
  }

  .traffic-back-link {
    justify-content: center;
  }

  .traffic-toolbar-card {
    padding: 15px !important;
  }

  .traffic-toolbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    gap: 11px;
  }

  .traffic-toolbar > * {
    width: 100%;
    min-width: 0;
  }

  .combined-port-note {
    width: 100%;
    min-width: 0;
    padding: 11px;
  }

  .traffic-chart-card,
  .dashboard-chart-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden !important;
  }

  .traffic-chart-card .chart-head,
  .dashboard-chart-card .chart-head {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    gap: 11px;
    padding: 15px;
  }

  .chart-legend,
  .traffic-chart-card .chart-legend,
  .dashboard-chart-card .chart-legend {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start !important;
    width: 100%;
    gap: 7px;
  }

  .chart-body,
  .traffic-chart-card .chart-body,
  .dashboard-chart-card .chart-body {
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 0 8px 12px !important;
    overflow: hidden !important;
  }

  .traffic-chart,
  .traffic-chart-card .traffic-chart,
  .dashboard-chart-card .traffic-chart {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 310px !important;
  }

  .traffic-table-card {
    width: 100%;
    min-width: 0;
    padding: 15px 0 0 !important;
    overflow: hidden !important;
  }

  .traffic-table-head {
    width: 100%;
    padding: 0 15px;
  }

  .traffic-table-card .table-wrap {
    width: 100%;
    overflow: visible !important;
    border: 0;
  }

  .traffic-data-table {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    background: transparent;
  }

  .traffic-data-table thead {
    display: none;
  }

  .traffic-data-table tbody {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    width: 100%;
    padding: 0 10px 12px;
  }

  .traffic-data-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
  }

  .traffic-data-table td {
    display: block;
    width: auto !important;
    min-width: 0 !important;
    max-width: 100%;
    padding: 8px 0;
    border: 0 !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .traffic-data-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: #728096;
    font-size: .65rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  .traffic-data-table td:nth-child(n+3) {
    border-top: 1px solid #edf1f5 !important;
    padding-top: 9px;
  }

  .traffic-data-table td:last-child {
    grid-column: 1 / -1;
  }

  .sample-cell {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .sample-value {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* Off-canvas navigation */
  .sidebar {
    width: min(86vw, 310px);
    max-width: 310px;
  }

  .sidebar.open + .sidebar-backdrop {
    display: block;
  }
}

@media (max-width: 430px) {
  :root {
    --mobile-gutter: 10px;
  }

  .topbar {
    padding-left: 8px;
    padding-right: 8px;
  }

  .menu-toggle {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .lang-switch a {
    min-width: 34px;
    width: 34px;
    height: 34px;
  }

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

  .dashboard-stat-grid .stat-card,
  .traffic-stat-grid .stat-card {
    min-height: 96px;
    padding: 13px;
  }

  .stat-value,
  .traffic-stat-grid .stat-value {
    font-size: 1.22rem !important;
  }

  .traffic-chart,
  .traffic-chart-card .traffic-chart,
  .dashboard-chart-card .traffic-chart {
    height: 285px !important;
  }

  .traffic-data-table tr {
    grid-template-columns: minmax(0, 1fr);
  }

  .traffic-data-table td,
  .traffic-data-table td:last-child {
    grid-column: 1;
  }

  .traffic-data-table td + td {
    border-top: 1px solid #edf1f5 !important;
    padding-top: 9px;
  }

  .sample-cell {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

@media (max-width: 340px) {
  .dashboard-stat-grid,
  .traffic-stat-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
