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

.mobile-header,
.sidebar-backdrop,
.drawer-close {
  display: none;
}

.main {
  width: calc(100% - 250px);
  max-width: none;
}

.card,
.detail-title > div,
.campaign-row > div,
.form-grid > * {
  min-width: 0;
}

.settings-card,
.settings-card > *,
.settings-card label,
.settings-card .form-grid,
.settings-card .form-grid > *,
.business-hours {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.settings-card {
  overflow: hidden;
}

.business-hours-table {
  width: 100%;
  table-layout: fixed;
}

.business-hours-table th:first-child,
.business-hours-table td:first-child {
  width: 120px;
}

.business-hours-table th:not(:first-child),
.business-hours-table td:not(:first-child) {
  width: auto;
}

.business-hours-table td:first-child label {
  grid-template-columns: auto minmax(0, 1fr) !important;
  gap: 6px;
}

.business-hours-table input[type="time"] {
  min-width: 0;
  width: 100%;
  direction: ltr;
}

.card-head,
.topbar,
.detail-title,
.actions,
.dialog-actions {
  flex-wrap: wrap;
}

.actions {
  justify-content: flex-end;
}

.muted,
.knowledge-item p,
.campaign-row p,
td {
  overflow-wrap: anywhere;
}

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

.responsive-table {
  min-width: 640px;
}

.settings-card .responsive-table {
  min-width: 480px;
}

.tabs {
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  min-height: 44px;
}

dialog {
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  overflow: hidden;
}

.dialog-form {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

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

button,
.nav-item,
.button {
  min-height: 44px;
}

@media (max-width: 1100px) {
  .sidebar {
    width: 88px;
    padding: 22px 12px;
  }

  .sidebar .brand {
    justify-content: center;
    margin: 0 0 26px;
  }

  .sidebar .brand div,
  .sidebar-foot {
    display: none;
  }

  .sidebar nav {
    gap: 10px;
  }

  .nav-item {
    position: relative;
    padding: 12px 8px;
    font-size: 0;
    text-align: center;
  }

  .nav-item::before {
    display: block;
    font-size: 21px;
    line-height: 1;
  }

  .nav-item:nth-child(1)::before {
    content: "⌂";
  }

  .nav-item:nth-child(2)::before {
    content: "◫";
  }

  .nav-item:nth-child(3)::before {
    content: "☎";
  }

  .nav-item:nth-child(4)::before {
    content: "◈";
  }

  .nav-item:nth-child(5)::before {
    content: "✓";
  }

  .nav-item:nth-child(6)::before {
    content: "◎";
  }

  .main {
    width: calc(100% - 88px);
    margin-right: 88px;
    padding: 28px;
  }

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

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

@media (max-width: 700px) {
  body {
    padding-bottom: 0;
  }

  .sidebar {
    position: fixed;
    z-index: 130;
    inset: 0 0 0 auto;
    display: flex;
    width: min(84vw, 320px);
    height: 100dvh;
    padding: 24px 18px calc(18px + env(safe-area-inset-bottom));
    border: 0;
    box-shadow: -22px 0 55px #0713263d;
    transform: translateX(108%);
    visibility: hidden;
    transition:
      transform 480ms cubic-bezier(.22, 1, .36, 1),
      visibility 0s linear 480ms;
    will-change: transform;
  }

  body.menu-open {
    overflow: hidden;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition:
      transform 480ms cubic-bezier(.22, 1, .36, 1),
      visibility 0s;
  }

  .sidebar .brand {
    display: flex;
    justify-content: flex-start;
    margin: 0 4px 30px;
  }

  .drawer-close {
    position: absolute;
    top: calc(18px + env(safe-area-inset-top));
    left: 18px;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0 0 3px;
    border: 1px solid #ffffff1c;
    border-radius: 12px;
    background: #ffffff0d;
    color: #fff;
    font-size: 27px;
    line-height: 1;
    cursor: pointer;
  }

  .sidebar .brand div,
  .sidebar-foot {
    display: block;
  }

  .sidebar nav {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .nav-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    min-width: 0;
    min-height: 48px;
    padding: 10px 14px;
    border-radius: 11px;
    font-size: 13px;
    text-align: right;
  }

  .nav-item::before {
    display: block;
    width: 22px;
    font-size: 18px;
    text-align: center;
  }

  .sidebar-foot {
    margin-top: auto;
  }

  .sidebar-backdrop {
    position: fixed;
    z-index: 120;
    inset: 0;
    display: block;
    border: 0;
    background: #07132680;
    opacity: 0;
    visibility: hidden;
    backdrop-filter: blur(2px);
    transition:
      opacity 350ms ease,
      visibility 0s linear 350ms;
  }

  body.menu-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    transition:
      opacity 350ms ease,
      visibility 0s;
  }

  .mobile-header {
    position: sticky;
    z-index: 90;
    top: 0;
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 68px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    border-bottom: 1px solid #e2e8f0;
    background: #f4f7fbeF;
    box-shadow: 0 8px 24px #253b600a;
    backdrop-filter: blur(14px);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .mobile-brand .brand-mark {
    width: 39px;
    height: 39px;
    border-radius: 12px;
    font-size: 19px;
  }

  .mobile-brand b,
  .mobile-brand small {
    display: block;
  }

  .mobile-brand b {
    font-size: 14px;
  }

  .mobile-brand small {
    margin-top: 1px;
    color: #75839a;
    font-size: 10px;
  }

  .menu-toggle {
    display: grid;
    place-content: center;
    gap: 4px;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid #dce4ee;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 14px #253b6010;
    cursor: pointer;
  }

  .menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 9px;
    background: #17233c;
    transition:
      transform 300ms ease,
      opacity 200ms ease;
  }

  body.menu-open .menu-toggle span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  body.menu-open .menu-toggle span:nth-child(2) {
    opacity: 0;
  }

  body.menu-open .menu-toggle span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .main {
    width: 100%;
    margin: 0;
    padding: 18px 14px 24px;
  }

  .topbar {
    align-items: center;
    margin-bottom: 18px;
  }

  .topbar h1,
  .dialog-head h2 {
    font-size: 21px;
  }

  .topbar .eyebrow {
    letter-spacing: 1px;
  }

  .topbar .button {
    padding-inline: 13px;
    font-size: 12px;
  }

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

  .card {
    padding: 16px;
    border-radius: 14px;
  }

  .settings-card input,
  .settings-card textarea,
  .settings-card select {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .settings-card input[type="range"] {
    padding-inline: 0;
  }

  .business-hours-table th,
  .business-hours-table td {
    padding-inline: 4px;
  }

  .business-hours-table.responsive-table th,
  .business-hours-table.responsive-table td {
    width: 75%;
  }

  .business-hours-table.responsive-table td {
    grid-template-columns: minmax(72px, 28%) minmax(0, 1fr);
    gap: 8px;
  }

  .business-hours-table input[type="time"] {
    min-height: 44px;
    padding-inline: 5px;
    font-size: 14px;
    text-align: center;
  }

  .stat strong {
    font-size: 24px;
  }

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

  .grid-2,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .campaign-row {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 14px;
  }

  .campaign-row > b {
    grid-column: 1 / -1;
    font-size: 12px;
  }

  .detail-title {
    flex-direction: column;
  }

  .detail-title .actions {
    width: 100%;
    justify-content: flex-start;
  }

  .actions .button {
    flex: 1 1 120px;
  }

  .tabs {
    margin-inline: -4px;
    padding-inline: 4px;
  }

  .tab {
    padding-inline: 12px;
  }

  .responsive-table {
    display: block;
    min-width: 0;
    border-collapse: separate;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tbody {
    display: grid;
    gap: 12px;
  }

  .responsive-table tr {
    display: block;
    padding: 4px 13px;
    border: 1px solid #e4e9f0;
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 4px 14px #253b600a;
  }

  .responsive-table td {
    display: grid;
    grid-template-columns: minmax(88px, 34%) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    min-height: 42px;
    padding: 10px 0;
    border-bottom: 1px dashed #e7ebf1;
    text-align: right;
  }

  .responsive-table td:last-child {
    border-bottom: 0;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: #77859a;
    font-size: 11px;
    font-weight: 600;
  }

  .responsive-table td.empty {
    display: block;
    padding: 24px;
    text-align: center;
  }

  .responsive-table td.empty::before,
  .responsive-table td[colspan]::before {
    display: none;
  }

  .responsive-table td[colspan] {
    grid-template-columns: 1fr;
  }

  .responsive-table input,
  .responsive-table select {
    padding: 9px 10px;
  }

  .table-scroll {
    overflow: visible;
  }

  dialog {
    width: calc(100vw - 16px);
    max-width: none;
    max-height: calc(100dvh - 16px);
    border-radius: 16px;
  }

  .dialog-form {
    max-height: calc(100dvh - 16px);
    padding: 18px 15px;
  }

  .dialog-head {
    position: sticky;
    z-index: 2;
    top: -18px;
    margin: -18px -15px 0;
    padding: 16px 15px 12px;
    background: #fff;
    border-bottom: 1px solid #eef1f5;
  }

  .dialog-actions {
    position: sticky;
    z-index: 2;
    bottom: -18px;
    margin: 0 -15px -18px;
    padding: 12px 15px calc(12px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #eef1f5;
  }

  .dialog-actions .button {
    flex: 1;
  }

  #toast {
    z-index: 200;
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-backdrop,
  .drawer-close,
  .menu-toggle span {
    transition-duration: 1ms !important;
  }
}

@media (max-width: 430px) {
  .login-body {
    padding: 12px;
  }

  .login-card {
    padding: 26px 20px;
    border-radius: 17px;
  }

  .login-card h1 {
    font-size: 23px;
  }

  .main {
    padding-inline: 11px;
  }

  .topbar {
    align-items: stretch;
  }

  .topbar > div {
    flex: 1 1 100%;
  }

  .topbar .button {
    width: 100%;
  }

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

  .campaign-row {
    grid-template-columns: 1fr;
  }

  .campaign-row .badge,
  .campaign-row > b {
    grid-column: auto;
    justify-self: start;
  }

  .responsive-table td {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .business-hours-table.responsive-table td {
    width: 75%;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
  }

  .responsive-table td::before {
    margin-bottom: 2px;
  }
}
