@media screen {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

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

  body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

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

  input,
  select,
  textarea,
  button {
    max-width: 100%;
  }

  .main,
  .view,
  .panel,
  .topbar,
  .section-heading,
  .metric-card,
  .source-card,
  .visual-panel,
  .report-preview,
  .water-test-card {
    min-width: 0;
  }

  .main {
    width: 100%;
  }

  .topbar,
  .section-heading,
  .panel-header,
  .filter-bar,
  .form-grid,
  .nested-form,
  .button-row,
  .form-actions {
    min-width: 0;
  }

  .topbar h1,
  .section-heading h2,
  .panel-header h3,
  .metric-card strong,
  .source-card strong,
  .water-test-doc h3,
  .water-test-context strong {
    overflow-wrap: anywhere;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
  }

  .table-wrap table {
    width: max-content;
    min-width: min(760px, calc(100vw - 32px));
  }

  .button,
  .nav-item,
  input,
  select {
    min-height: 42px;
  }

  textarea {
    min-height: 96px;
  }

  .chart-frame,
  .analytics-chart-block {
    min-width: 0;
  }

  .usage-chart {
    width: 100%;
  }

  .report-preview {
    overflow-x: auto;
  }
}

@media screen and (max-width: 1280px) {
  .app-shell {
    grid-template-columns: 252px minmax(0, 1fr);
  }

  .sidebar {
    width: 252px;
  }

  .main {
    padding-left: 18px;
    padding-right: 18px;
  }

  .metric-grid,
  .action-summary,
  .source-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analytics-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-grid .panel:nth-child(3) {
    grid-column: auto;
  }
}

@media screen and (max-width: 980px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    border-bottom: 1px solid var(--border);
    border-right: 0;
    height: auto;
    max-height: 42vh;
    overflow: auto;
    padding: 10px 12px;
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 50;
  }

  .brand {
    align-items: center;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    margin-bottom: 8px;
  }

  .brand .brand-logo {
    width: 132px;
  }

  .nav-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 2px 0 6px;
    scrollbar-width: thin;
  }

  .nav-item {
    flex: 0 0 auto;
    padding-left: 12px;
    padding-right: 12px;
    white-space: nowrap;
  }

  .sidebar-note,
  .nav-section-label {
    display: none;
  }

  .main {
    padding: 14px;
  }

  .topbar {
    position: static;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .filter-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid,
  .nested-form,
  .compliance-grid,
  .report-meta-grid,
  .report-brand-row,
  .report-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .water-test-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .water-test-actions,
  .water-test-facts {
    justify-content: flex-start;
  }

  .water-test-detail,
  .water-test-facts {
    grid-column: 1;
  }
}

@media screen and (max-width: 720px) {
  .auth-shell {
    min-height: 100svh;
    padding: 16px;
  }

  .auth-card {
    border-radius: 12px;
    padding: 22px;
  }

  .auth-card .auth-brand-logo {
    width: min(220px, 84vw);
  }

  .sidebar {
    max-height: 46vh;
  }

  .brand {
    grid-template-columns: 1fr;
  }

  .brand .brand-logo {
    width: 118px;
  }

  .main {
    padding: 10px;
  }

  .topbar,
  .section-heading,
  .panel-header,
  .form-actions,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .button-row,
  .form-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .topbar-actions > *,
  .button-row .button,
  .form-actions .button {
    width: 100%;
  }

  .button-row,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .metric-grid,
  .action-summary,
  .source-grid,
  .dashboard-grid,
  .insight-grid,
  .filter-bar,
  .form-grid,
  .nested-form,
  .compliance-grid,
  .report-meta-grid,
  .report-brand-row,
  .report-stat-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .panel {
    padding: 14px;
  }

  .metric-card,
  .source-card,
  .visual-panel {
    min-height: auto;
  }

  .analytics-chart-block {
    min-height: 220px;
  }

  .usage-chart {
    max-height: none;
  }

  .water-test-card {
    gap: 12px;
    padding: 14px;
  }

  .water-test-doc,
  .water-test-detail {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .water-test-doc h3,
  .water-test-doc p,
  .water-test-context strong,
  .water-test-meta > span:last-child {
    white-space: normal;
  }

  .water-test-actions {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
    white-space: normal;
  }

  .water-test-meta,
  .water-test-facts {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    white-space: normal;
  }

  .water-test-actions .admin-only {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .water-test-facts span {
    width: fit-content;
  }

  .report-preview {
    border-radius: 10px;
    padding: 10px;
  }
}

@media screen and (max-width: 420px) {
  .main {
    padding: 8px;
  }

  .panel,
  .auth-card,
  .water-test-card {
    border-radius: 8px;
  }

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

  .nav-item {
    padding-left: 10px;
    padding-right: 10px;
  }

  .panel {
    padding: 12px;
  }

  th,
  td {
    padding: 9px 8px;
  }
}
