/* Mobile layout only: keep data, permissions and existing form actions intact. */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
a, button, summary, label, [role="button"], .btn, .nav-item, .rex-ico, .mobile-nav a, .mobile-nav button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.shell, .content, .card, .field, .form, .form-grid, .list-main, .client-card { min-width: 0; }
.content { max-width: 100%; }
.form-grid { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.field input, .field select, .field textarea, .quick-search input { width: 100%; min-width: 0; max-width: 100%; }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea { max-width: 100%; }
.brand-name, .page-title, .page-sub, .card-title, .card-note, .list-title, .list-sub,
.kv > *, .pill, .btn-label, .tile-value, .stat-value, .alert, .delivery, .bubble p { overflow-wrap: anywhere; }
.message-body, .copy-block, .secret, .fields { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; max-width: 100%; }
.btn { max-width: 100%; white-space: normal; text-align: center; }
.btn svg { flex-shrink: 0; }
.row-actions > form, .actions > form, details.more { min-width: 0; max-width: 100%; }
.card > .data-table:not(.mobile-card-table) { display: block; max-width: 100%; overflow-x: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.mobile-header, .drawer-close, .drawer-backdrop { display: none; }

@media (max-width: 860px) {
  .shell { width: 100%; display: block; }
  body.drawer-open { overflow: hidden; }
  .mobile-header { display: flex; position: sticky; top: 0; z-index: 30; background: var(--bg); padding-block: 8px; align-items: center; gap: 12px; margin-bottom: 20px; min-width: 0; }
  .mobile-header > span { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; min-width: 0; }
  .mobile-header .btn { flex-shrink: 0; min-height: 44px; }
  .drawer-close { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
  .shell .sidebar { display: none; }
  .shell.mobile-menu-open .sidebar,
  .shell.mobile-nav-on.mobile-menu-open .sidebar {
    display: flex; position: fixed; z-index: 80; inset: 0 auto 0 0;
    width: min(320px, calc(100vw - 36px)); max-width: calc(100vw - 36px); height: 100dvh;
    overflow-y: auto; overscroll-behavior: contain; border-right: 1px solid var(--sidebar-border);
    padding: calc(16px + env(safe-area-inset-top, 0px)) 14px calc(28px + env(safe-area-inset-bottom, 0px));
  }
  .shell.mobile-menu-open .drawer-backdrop { display: block; position: fixed; z-index: 70; inset: 0; background: rgb(0 0 0 / 60%); border: 0; cursor: pointer; }
  .shell.mobile-menu-open .mobile-nav { visibility: hidden; pointer-events: none; }
  .mobile-header {
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
  .content { width: 100%; flex-basis: auto; }
  .shell.sidebar-collapsible.sidebar-collapsed .sidebar { flex-basis: auto; }
  .shell.sidebar-collapsible.sidebar-collapsed .profile-text { font-size: 13px; }
  .shell.sidebar-collapsible.sidebar-collapsed .nav-label { font-size: 10.5px; }
  .shell.sidebar-collapsible.sidebar-collapsed .quick-search,
  .shell.sidebar-collapsible.sidebar-collapsed .nav-item { font-size: 13.5px; }
  .profile-name { white-space: normal; overflow-wrap: anywhere; }
  .row > .card { flex-basis: 100%; }
}

@media (max-width: 760px) {
  .content, .shell.mobile-nav-on .content { padding: 18px 12px calc(104px + env(safe-area-inset-bottom, 0px)); }
  .shell.mobile-nav-off .content { padding-bottom: 32px; }
  .card { padding: 18px 14px; gap: 14px; border-radius: 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .field input, .field select, .field textarea, .quick-search input { font-size: 16px; }
  .topbar, .stack-3, .list-main { max-width: 100%; min-width: 0; }
  .page-title { font-size: 22px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { min-width: 0; padding: 14px 12px; }
  .tile-value { font-size: 21px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kv { align-items: flex-start; flex-wrap: wrap; }
  .kv > :last-child { min-width: 0; max-width: 100%; text-align: left; }
  .input-suffix { flex-wrap: wrap; }
  .input-suffix input { flex-basis: 100%; }
  .input-suffix span { white-space: normal; overflow-wrap: anywhere; }
  .row-actions, .actions { gap: 8px; }
  .row-actions > form, .actions > form { flex: 1 1 140px; }
  .row-actions > .btn, .actions > .btn { flex: 1 1 140px; }
  .row-actions form .btn, .actions form .btn { width: 100%; }
  .row-actions label { display: block; overflow-wrap: anywhere; }
  .row-actions input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]) { min-width: 0; width: 100%; font-size: 16px; min-height: 44px; }
  .row-actions details.more { flex: 1 1 100%; }
  details.more > summary { min-height: 44px; }
  .bubble { max-width: 100%; min-width: 0; }
  .public-bar, .public-footer { flex-wrap: wrap; padding: 16px 12px; }
  .auth-card { padding: 24px 16px; min-width: 0; }
  .shell.mobile-nav-on .mobile-nav { height: calc(72px + env(safe-area-inset-bottom, 0px)); }
  .shell.mobile-nav-on .mobile-nav a, .shell.mobile-nav-on .mobile-nav button { min-height: 44px; }
  .mobile-card-table { display: block; max-width: 100%; border-collapse: separate; }
  .mobile-card-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .mobile-card-table tbody { display: grid; gap: 12px; }
  .mobile-card-table tr { display: block; min-width: 0; border: 1px solid var(--border-strong); border-radius: 12px; overflow-wrap: anywhere; }
  .mobile-card-table td { display: grid; grid-template-columns: minmax(76px, 34%) minmax(0, 1fr); align-items: start; gap: 10px; min-width: 0; padding: 10px; overflow-wrap: anywhere; }
  .mobile-card-table td::before { content: attr(data-label); color: var(--text-dim); font-weight: 600; }
  .mobile-card-table td[colspan] { display: block; }
  .mobile-card-table td[colspan]::before { content: none; }
  .mobile-card-table td > * { min-width: 0; max-width: 100%; }
  .mobile-card-table td > form { grid-column: 1 / -1; width: 100%; }
  .mobile-card-table td select { width: 100%; min-width: 0; font-size: 16px; }
  dialog.playlist-dialog:not([open]) {
    display: none !important;
  }
  dialog.playlist-dialog[open] {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding: 14px;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }
  dialog.playlist-dialog[open] .delivery-access-card {
    max-height: calc(100dvh - 230px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow: auto;
  }
  dialog.playlist-dialog[open] .playlist-body { max-height: none; }
  dialog.playlist-dialog[open] .row-actions {
    position: static;
    bottom: auto;
    z-index: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: var(--surface);
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }
  dialog.playlist-dialog[open] .row-actions > .btn,
  dialog.playlist-dialog[open] .row-actions > a.btn { width: 100%; min-height: 44px; margin: 0; }
}

@media (max-width: 360px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
}
