:root {
  --safe-top: max(env(safe-area-inset-top, 0px), var(--android-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--android-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--android-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--android-inset-right, 0px));
}

.sidebar-toggle,
.sidebar .sidebar-close,
.sidebar-backdrop {
  display: none;
}

/* Layout hardening shared by desktop and responsive views. */
.toolbar {
  flex-wrap: wrap;
}

.toolbar > div:first-child {
  min-width: 0;
  margin-right: auto;
}

.card-head > div {
  min-width: 0;
}

.card-head h3,
.card-head p {
  overflow-wrap: anywhere;
}

.badge {
  flex: 0 0 auto;
  align-self: flex-start;
  white-space: nowrap;
  line-height: 1.2;
  min-width: max-content;
  text-align: center;
}

th,
td {
  vertical-align: middle;
}

th:nth-last-child(-n + 2),
td:nth-last-child(-n + 2) {
  white-space: nowrap;
}

.table-wrap table {
  min-width: 760px;
}

.modal-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: min(90vh, 820px);
  overflow: hidden;
}

.modal-head {
  background: #fff;
  position: relative;
  z-index: 2;
}

.modal-card form {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
}

.form-grid {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.form-grid .field,
.form-grid input,
.form-grid select,
.form-grid textarea {
  min-width: 0;
  width: 100%;
}

.modal-actions {
  background: #fff;
  box-shadow: 0 -8px 20px rgb(15 23 42 / 6%);
  position: relative;
  z-index: 2;
}

@media (min-width: 721px) and (max-width: 1100px) {
  main {
    padding-left: 22px;
    padding-right: 22px;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .cards,
  .cards.two {
    grid-template-columns: minmax(0, 1fr);
  }
}

@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
  }
}

@media (max-width: 720px) {
  body {
    min-height: 100dvh;
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

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

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

  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    width: min(300px, 85vw);
    height: 100dvh;
    padding: calc(24px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)) max(16px, var(--safe-left));
    overflow: hidden;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgb(15 23 42 / 50%);
  }

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

  .sidebar-toggle {
    display: flex;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font-size: 20px;
    cursor: pointer;
  }

  .sidebar .sidebar-close {
    position: absolute;
    top: calc(20px + var(--safe-top));
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .sidebar .brand {
    padding-right: 32px;
    flex-shrink: 0;
  }

  .sidebar nav {
    min-height: 0;
    align-content: start;
    overscroll-behavior-y: contain;
  }

  .sidebar nav button,
  .sidebar-footer a,
  .sidebar-footer button {
    min-height: 44px;
    flex-shrink: 0;
  }

  .sidebar-footer {
    flex-shrink: 0;
  }

  .header-title {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .profile {
    flex-shrink: 0;
  }

  main {
    min-height: auto;
    margin-left: 0;
    padding: 0 max(16px, var(--safe-right)) 28px max(16px, var(--safe-left));
  }

  header {
    position: sticky;
    z-index: 10;
    top: 0;
    min-height: calc(68px + var(--safe-top));
    height: auto;
    padding-top: var(--safe-top);
    background: rgba(248, 250, 252, 0.9);
    backdrop-filter: blur(10px);
    margin-bottom: 20px;
    gap: 10px;
  }

  header h1 {
    font-size: clamp(20px, 5.5vw, 26px);
  }

  .eyebrow {
    font-size: 10px;
  }

  .profile {
    padding: 4px 8px;
  }

  .profile div:last-child {
    display: none;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .metric {
    min-width: 0;
    padding: 16px 14px;
  }

  .metric strong {
    font-size: 20px;
    overflow-wrap: anywhere;
  }

  .toolbar {
    gap: 10px;
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar .btn,
  .toolbar input,
  .toolbar select {
    justify-content: center;
    max-width: none;
    width: 100%;
    min-height: 44px;
  }

  .toolbar .report-filters {
    flex-wrap: wrap;
    width: 100%;
    min-width: 0;
  }

  .toolbar .report-filters input {
    flex: 1 1 120px;
    min-width: 0;
    width: 0;
  }

  .cards,
  .cards.two {
    grid-template-columns: minmax(0, 1fr);
  }

  .card-head {
    align-items: flex-start;
  }

  .feature-grid,
  .checks {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap table {
    min-width: 680px;
  }

  .modal {
    align-items: flex-end;
    padding: var(--safe-top) 0 0;
  }

  .modal-card {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - var(--safe-top));
    margin: 0;
    border-radius: 20px 20px 0 0;
    position: relative;
  }

  .modal-card::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 10px auto 4px;
  }

  .modal-head,
  .form-grid,
  .modal-actions {
    padding-left: 18px;
    padding-right: 18px;
  }

  .modal-actions {
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .modal-actions .btn {
    flex: 1;
    justify-content: center;
    min-height: 46px;
  }

  #toast {
    right: 14px;
    bottom: calc(16px + var(--safe-bottom));
    left: 14px;
    text-align: center;
    justify-content: center;
  }
}

@media (max-width: 359px) {
  .metrics {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
