.ct-header__mobile {
  display: none;
}

.ct-mobile-drawer-backdrop {
  display: none;
}

@media (max-width: 540px) and (orientation: portrait) {
  body[data-theme='legacy'] {
    --mobile-header-height: 48px;
    --mobile-drawer-width: min(82vw, 320px);
    --mobile-card-gap: 0.65rem;
    --mobile-card-radius: 10px;
    --mobile-card-border: rgba(110, 135, 168, 0.35);
  }

  body[data-theme='legacy'] .ct-header {
    position: sticky;
    top: 0;
    z-index: 1200;
  }

  body[data-theme='legacy'] .ct-header__inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--mobile-header-height);
    padding: 0.35rem 0.6rem;
  }

  body[data-theme='legacy'] .ct-header__mobile {
    display: contents;
  }

  body[data-theme='legacy'] .ct-header__mobile-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--menu-border);
    background: var(--menu-bg);
    color: var(--menu-text);
    font-size: 20px;
  }

  body[data-theme='legacy'] .ct-header__mobile-title {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--menu-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body[data-theme='legacy'] .ct-header__actions {
    justify-self: end;
    gap: 0.35rem;
  }

  body[data-theme='legacy'] .ct-header__user-name {
    display: none;
  }

  body[data-theme='legacy'] .ct-header__logout {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
  }

  body[data-theme='legacy'] .ct-main-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--mobile-drawer-width);
    max-width: 320px;
    background: var(--menu-bg);
    border-right: 2px solid var(--menu-border);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 1300;
    padding: 0.75rem 0.5rem;
  }

  body.mobile-drawer-open[data-theme='legacy'] .ct-main-nav {
    transform: translateX(0);
  }

  body[data-theme='legacy'] .ct-main-nav__list,
  body[data-theme='legacy'] .main-nav__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    max-height: 100%;
    overflow-y: auto;
    padding-right: 0.25rem;
  }

  body[data-theme='legacy'] .ct-main-nav__item,
  body[data-theme='legacy'] .main-nav__item {
    width: 100%;
  }

  body[data-theme='legacy'] .ct-main-nav__link,
  body[data-theme='legacy'] .main-nav__link,
  body[data-theme='legacy'] .main-nav__sublink {
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.65rem 0.6rem;
    min-height: 44px;
    border-radius: 8px;
  }

  body[data-theme='legacy'] .ct-main-nav__label,
  body[data-theme='legacy'] .main-nav__label {
    display: inline-flex;
    font-size: 0.95rem;
  }

  body[data-theme='legacy'] .ct-main-nav__submenu,
  body[data-theme='legacy'] .dropdown-menu {
    position: static;
    box-shadow: none;
    border: 1px solid var(--menu-border);
    margin-top: 0.35rem;
    padding: 0.35rem;
  }

  body[data-theme='legacy'] .ct-mobile-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1250;
    display: none;
  }

  body.mobile-drawer-open[data-theme='legacy'] .ct-mobile-drawer-backdrop {
    display: block;
  }

  body.mobile-drawer-open[data-theme='legacy'] {
    overflow: hidden;
  }

  body[data-theme='legacy'] .app-header__breadcrumbs,
  body[data-theme='legacy'] .app-breadcrumb {
    padding: 0.25rem 0.6rem;
    overflow: hidden;
  }

  body[data-theme='legacy'] .breadcrumbs__list {
    display: flex;
    flex-wrap: nowrap;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  body[data-theme='legacy'] .breadcrumbs__item:not(:last-child) {
    display: none;
  }

  body[data-theme='legacy'] #toptabs,
  body[data-theme='legacy'] .tabs {
    overflow-x: auto;
    white-space: nowrap;
    padding: 0.2rem 0.4rem;
  }

  body[data-theme='legacy'] #toptabs a,
  body[data-theme='legacy'] .tabs a {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
  }

  body[data-theme='legacy'] #content table[data-layout='form-legacy'],
  body[data-theme='legacy'] #content .params-table {
    width: 100%;
    table-layout: auto;
    border-spacing: 0;
  }

  body[data-theme='legacy'] #content table[data-layout='form-legacy'] tr,
  body[data-theme='legacy'] #content .params-table tr {
    display: block;
    padding: 0.45rem 0.5rem;
    margin-bottom: 0.65rem;
    background: var(--layout-surface-strong, #ffffff);
    border-radius: 10px;
    border: 1px solid var(--mobile-card-border);
  }

  body[data-theme='legacy'] #content table[data-layout='form-legacy'] td,
  body[data-theme='legacy'] #content .params-table td,
  body[data-theme='legacy'] #content table[data-layout='form-legacy'] th,
  body[data-theme='legacy'] #content .params-table th {
    display: block;
    width: 100%;
    padding: 0.2rem 0;
  }

  body[data-theme='legacy'] #content table[data-layout='form-legacy'] td label,
  body[data-theme='legacy'] #content .params-table td label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.2rem;
    text-align: left;
  }

  body[data-theme='legacy'] #content table[data-layout='form-legacy'] td input,
  body[data-theme='legacy'] #content table[data-layout='form-legacy'] td select,
  body[data-theme='legacy'] #content table[data-layout='form-legacy'] td textarea,
  body[data-theme='legacy'] #content .params-table td input,
  body[data-theme='legacy'] #content .params-table td select,
  body[data-theme='legacy'] #content .params-table td textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  body[data-theme='legacy'] .page-content__actions ul {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    width: 100%;
  }

  body[data-theme='legacy'] .page-content__actions .button,
  body[data-theme='legacy'] .page-content__actions button,
  body[data-theme='legacy'] .page-content__actions input[type='submit'],
  body[data-theme='legacy'] .page-content__actions input[type='button'] {
    width: 100%;
    text-align: center;
  }

  body[data-theme='legacy'] .table-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  body[data-theme='legacy'] table.mobile-card-table thead {
    display: none;
  }

  body[data-theme='legacy'] table.mobile-card-table tbody,
  body[data-theme='legacy'] table.mobile-card-table tr {
    display: block;
  }

  body[data-theme='legacy'] table.mobile-card-table tr {
    border: 1px solid var(--mobile-card-border);
    border-radius: var(--mobile-card-radius);
    padding: 0.5rem 0.6rem;
    margin-bottom: var(--mobile-card-gap);
    background: var(--layout-surface-strong, #ffffff);
  }

  body[data-theme='legacy'] table.mobile-card-table td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.2rem 0;
    border: none;
  }

  body[data-theme='legacy'] table.mobile-card-table td::before {
    content: attr(data-mobile-label);
    font-weight: 600;
    color: var(--layout-muted, #4b5563);
    flex: 0 0 45%;
    max-width: 45%;
  }

  body[data-theme='legacy'] table.mobile-card-table td[data-mobile-label='']::before {
    content: '';
  }

  body[data-theme='legacy'] table.mobile-card-table td.col-actions {
    display: block;
  }

  body[data-theme='legacy'] table.mobile-card-table td.col-actions::before {
    content: '';
  }

  body[data-theme='legacy'] table.mobile-card-table td.col-actions .table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-start;
  }
}
