@media screen {
  .sidebar-backdrop { display: none; }

  .sidebar { overflow-y: auto; scrollbar-width: none; }

  .role-entry-main > .brand { color: var(--primary); }

  .table-wrap { container-type: inline-size; }

  @container (width < 760px) {
    .table-wrap table,
    .table-wrap td { display: block !important; }

    .table-wrap table { width: 100%; min-width: 0 !important; }
    .table-wrap thead { display: none; }

    .table-wrap tbody,
    .table-wrap tfoot {
      display: grid;
      gap: 10px;
      padding: 12px;
    }

    .table-wrap tfoot { padding-top: 0; }

    .table-wrap tr {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px 14px;
      padding: 14px;
      border: 1px solid var(--line);
      border-radius: 12px;
      background: var(--surface);
    }

    .table-wrap tr:hover { background: var(--surface); }

    .table-wrap td {
      width: auto !important;
      min-width: 0 !important;
      padding: 0 !important;
      border: 0 !important;
      background: transparent;
      font-size: 14px;
      text-align: left !important;
      white-space: normal !important;
      overflow-wrap: anywhere;
    }

    .table-wrap td:empty { display: none; }

    .table-wrap td[data-label]::before {
      content: attr(data-label);
      display: block;
      margin-bottom: 2px;
      color: var(--muted);
      font-size: 12px;
      font-weight: 500;
      line-height: 1.4;
    }

    .table-wrap td:first-child,
    .table-wrap td:not([data-label]),
    .table-wrap td[data-label^="Действи"] { grid-column: 1 / -1; }

    .table-wrap td[data-label^="Действи"]::before { display: none; }

    .table-wrap td:first-child { font-weight: 600; }
    .table-wrap td:first-child::before { display: none; }

    .table-wrap td .btn { min-height: 44px; }

    .table-wrap td .pill { white-space: normal; }

    .table-wrap td :is(select, textarea, input:not([type="checkbox"], [type="radio"])) {
      width: 100%;
      max-width: 100%;
      min-height: 44px;
    }

    .table-wrap td:not([data-label]) > .btn,
    .table-wrap td:not([data-label]) > .row > .btn,
    .table-wrap td[data-label^="Действи"] > .btn,
    .table-wrap .reg-row-actions > .btn { flex: 1 1 auto; }

    .table-wrap td > strong:first-child:not(:only-child),
    .table-wrap td > small { display: block; }

    .table-wrap td:not([data-label]) > .btn:only-child { width: 100%; }

    .table-wrap td > .row,
    .table-wrap .reg-row-actions {
      flex-wrap: wrap;
      justify-content: flex-start;
    }
  }

  @container (520px <= width < 760px) {
    .table-wrap tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  }
}

@media screen and (max-width: 1000px) {
  :root {
    --sidebar: 0px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
  }

  body:has(.sidebar.open) { overflow: hidden; }

  .shell { display: block; }
  .skip-link { left: 12px; }

  .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 84vw);
    height: 100dvh;
    padding: calc(20px + var(--safe-top)) max(12px, var(--safe-left)) calc(14px + var(--safe-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 60;
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.32, .72, 0, 1), visibility 0s .26s;
    box-shadow: 0 0 60px rgb(0 0 0 / 30%);
  }

  .sidebar.open {
    visibility: visible;
    transform: none;
    transition: transform .26s cubic-bezier(.32, .72, 0, 1), visibility 0s;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 59;
    padding: 0;
    background: rgb(9 26 22 / 55%);
    opacity: 0;
    pointer-events: none;
    transition: opacity .26s;
  }

  .sidebar.open + .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar .brand { padding-bottom: 18px; font-size: 25px; }
  .sidebar .clinic-label { padding-bottom: 14px; }
  .sidebar .nav { gap: 4px; }
  .sidebar .nav button { min-height: 48px; font-size: 16px; }
  .sidebar-bottom { padding-top: 18px; }

  .topbar .btn.mobile-menu {
    display: inline-flex;
    flex: none;
    width: 44px;
    min-height: 44px;
    padding: 0;
    color: var(--ink);
  }

  .topbar .mobile-menu .ico { width: 22px; height: 22px; }

  .page-heading > * { min-width: 0; }
  .heading-actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media screen and (max-width: 760px) {
  :root { --topbar: 60px; }

  html { scroll-padding-top: calc(var(--topbar) + var(--safe-top) + 12px); }

  body { overflow-wrap: break-word; }

  input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"]),
  select,
  textarea { font-size: 16px !important; }

  h1 { font-size: 23px; letter-spacing: -.5px; text-wrap: balance; }
  h2 { font-size: 18px; text-wrap: balance; }

  .topbar {
    flex-wrap: nowrap;
    height: calc(var(--topbar) + var(--safe-top));
    padding: var(--safe-top) max(12px, var(--safe-right)) 0 max(6px, var(--safe-left));
    gap: 6px;
  }

  .topbar .global-search {
    position: static;
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  .global-search input {
    height: 44px;
    min-height: 44px;
    padding-left: 40px;
    padding-right: 10px;
    text-overflow: ellipsis;
  }

  .global-search .searchbox > .ico { left: 12px; }

  .search-results {
    left: 8px;
    right: 8px;
    top: calc(100% + 6px);
    max-height: calc(100dvh - var(--topbar) - var(--safe-top) - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .header-controls { gap: 4px; }
  .header-clock,
  .header-controls .comfort-btn,
  .staff-chevron { display: none; }

  .staff-trigger { padding: 3px; }
  .staff-menu { position: static; }
  .staff-dropdown { top: calc(100% + 4px); right: 8px; width: min(320px, calc(100vw - 16px)); }
  .staff-dropdown-actions .btn { min-height: 46px; }
  .theme-picker { min-height: 44px; }

  .workspace {
    min-height: calc(100dvh - var(--topbar) - var(--safe-top));
    padding: 16px max(12px, var(--safe-right)) calc(28px + var(--safe-bottom)) max(12px, var(--safe-left));
  }

  .page-heading { gap: 12px; margin-bottom: 16px; }
  .heading-actions { justify-content: flex-start; }
  .heading-actions > .btn { flex: 1 1 auto; }

  .card { border-radius: 12px; }
  .card-head { flex-wrap: wrap; min-height: 56px; padding: 12px 14px; }
  .card-body { padding: 14px; }
  .card-body.compact { padding: 12px 14px; }

  .btn { min-height: 46px; }
  .btn.sm { min-height: 44px; }
  .link-btn, .chip { min-height: 44px; }
  .close-x { width: 44px; height: 44px; }

  .row.wrap, .toolbar { gap: 10px; }
  .toolbar { padding: 12px 14px; }
  .toolbar .searchbox { flex-basis: 100%; min-width: 0; }
  .toolbar input.search { min-width: 0; min-height: 46px; height: 46px; }
  .toolbar > .field { flex: 1 1 140px; }
  .toolbar > .chips { flex-basis: 100%; }
  .toolbar .field select, .toolbar .field input { width: 100%; }

  .tabs,
  .queue-tabs,
  .setting-menu {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scroll-padding-inline: 24px;
  }

  .tabs > button,
  .queue-tabs > button,
  .setting-menu > button { flex: none; }

  .tabs button { min-height: 48px; font-size: 14px; }

  .reference-record { --record-top: calc(var(--topbar) + var(--safe-top)); }
  .clinical-dock, .profile-edit-heading { top: calc(var(--topbar) + var(--safe-top)); }

  .record-tab-strip { grid-template-columns: minmax(0, 1fr); padding: 8px; }
  .record-tab-arrow { display: none; }
  .record-tabs button { min-height: 40px; font-size: 14px; }

  .record-dock.detail-dock { position: static; }
  .record-detail .record-patient-episode { top: calc(var(--record-top) + 6px); }
  .record-patient-episode::before { top: -7px; height: 6px; }

  .reference-exam-actions {
    bottom: calc(8px + var(--safe-bottom));
    gap: 6px;
    padding: 8px;
  }

  .reference-exam-actions .btn {
    flex: 1 1 calc(33.333% - 6px);
    min-height: 44px;
    padding: 6px;
    line-height: 1.2;
    white-space: normal;
  }

  .table-footer {
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 12px 14px;
  }

  .stats,
  .stats.three { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
  .stat { min-width: 0; padding: 13px 14px; }
  .stat .value { font-size: 22px; margin-top: 8px; overflow-wrap: anywhere; }

  .step-strip {
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
  }

  .step-line { flex: 1 1 12px; min-width: 12px; width: auto; }

  .provider-day-cards {
    flex-wrap: nowrap;
    gap: 10px;
    margin: 0 -12px 14px;
    padding: 0 12px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 12px;
    scrollbar-width: none;
  }

  .provider-day-card {
    flex: 0 0 min(230px, 68vw);
    gap: 4px;
    padding: 13px 14px;
    scroll-snap-align: start;
  }

  .reg-schedule-scroll { max-height: 72dvh; }

  .reg-schedule-grid .time,
  .reg-schedule-grid .doctor-name:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
  }

  .reg-schedule-grid .doctor-name:first-child {
    z-index: 3;
    background: var(--theme-raised, #f4f8f1);
  }

  .settings-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .setting-menu { padding: 6px; }

  .sticky-actions { bottom: calc(8px + var(--safe-bottom)); flex-wrap: wrap; }

  .empty { min-height: 160px; padding: 28px 16px; }

  .success-card { margin: 12px auto; padding: 22px 16px; }
  .success-card h2 { font-size: 22px; }

  .price-large { font-size: 32px; letter-spacing: -1px; }

  .progress-row { grid-template-columns: minmax(0, 96px) minmax(0, 1fr) auto; }
  .chart { gap: 8px; padding-inline: 4px; }

  dialog,
  dialog.wide {
    width: 100vw;
    max-width: 100vw;
    max-height: calc(100dvh - var(--safe-top) - 20px);
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
    overscroll-behavior: contain;
  }

  dialog.drawer {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  dialog[open] { animation: sheet-in .28s cubic-bezier(.32, .72, 0, 1); }

  .dialog-head {
    position: sticky;
    top: 0;
    z-index: 3;
    align-items: flex-start;
    padding: 14px 10px 12px 16px;
    background: var(--surface);
  }

  .drawer .dialog-head { padding-top: calc(14px + var(--safe-top)); }
  .dialog-head h2 { font-size: 18px; }
  .dialog-body, .drawer .dialog-body { padding: 16px; }

  .dialog-foot,
  .drawer .dialog-foot {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px calc(12px + var(--safe-bottom));
  }

  .dialog-foot > .btn { flex: 1 1 auto; }
  .editor-menubar { position: relative; }
  .editor-menu { position: static; }
  .editor-menu > summary { padding: 10px 8px; font-size: 13px; }
  .editor-menu > div { left: 8px; right: 8px; }
  .editor-menu > div .btn { white-space: normal; }

  .drawer .service-list { max-height: none; }
  .service-list { max-height: min(460px, 60dvh); }

  #toast {
    inset: auto max(12px, var(--safe-right)) calc(12px + var(--safe-bottom)) max(12px, var(--safe-left));
    max-width: none;
    padding: 13px 16px;
  }

  .tour-progress { bottom: calc(10px + var(--safe-bottom)); }

  .role-entry-main { padding-bottom: calc(28px + var(--safe-bottom)); }
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(28px);
  }
}
