/* ClinicOS mobile workspace — touch-first layout loaded after the desktop styles. */
.mobile-bottom-nav,
.portal-bottom-nav,
.portal-mobile-overlay {
  display: none;
}

@media (hover: none) {
  button,
  a,
  select,
  input[type="checkbox"],
  input[type="radio"] {
    -webkit-tap-highlight-color: transparent;
  }

  button:active,
  a:active {
    transform: scale(.98);
  }
}

@media (max-width: 900px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: 76px;
  }

  body {
    overflow-x: hidden;
    overscroll-behavior-y: contain;
  }

  .sidebar,
  .portal-sidebar {
    width: min(86vw, 320px);
    max-width: 320px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .sidebar {
    z-index: 70;
  }

  .mobile-overlay.show {
    z-index: 64;
  }

  .mobile-close,
  .menu-button,
  .mobile-menu,
  .notification,
  .book-header {
    min-width: 44px;
    min-height: 44px;
  }

  .mobile-bottom-nav,
  .portal-bottom-nav {
    position: fixed;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 10px;
    z-index: 55;
    display: grid;
    grid-template-columns: repeat(var(--mobile-nav-items, 5), minmax(0, 1fr));
    min-height: 66px;
    padding: 7px;
    border: 1px solid rgba(211, 222, 235, .94);
    border-radius: 20px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 15px 38px rgba(15, 42, 75, .2);
    backdrop-filter: blur(18px);
  }

  .mobile-bottom-nav a,
  .mobile-bottom-nav button,
  .portal-bottom-nav a,
  .portal-bottom-nav button {
    min-width: 0;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    border-radius: 14px;
    color: #718198;
    background: transparent;
    text-decoration: none;
    font-weight: 800;
  }

  .mobile-bottom-nav i,
  .portal-bottom-nav i {
    font-size: 19px;
    font-style: normal;
    line-height: 1;
  }

  .mobile-bottom-nav span,
  .portal-bottom-nav span {
    overflow: hidden;
    max-width: 100%;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-bottom-nav a.active,
  .portal-bottom-nav a.active {
    color: #1769e0;
    background: #eaf2ff;
  }

  .page-content,
  .portal-content #portal-view {
    padding-bottom: calc(105px + env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 66px;
    height: auto;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: 8px;
  }

  .global-search {
    min-width: 0;
    height: 44px;
  }

  .global-search input,
  .form-grid input,
  .form-grid select,
  .form-grid textarea,
  .clinical-grid input,
  .clinical-grid select,
  .clinical-grid textarea,
  .vitals-grid input,
  .catalog-search input,
  .plan-item-fields input,
  .plan-item-fields select,
  .portal-form input,
  .portal-form select,
  .portal-form textarea,
  .login-card input,
  .booking-summary textarea,
  .family-switch select {
    font-size: 16px !important;
  }

  .primary,
  .secondary,
  .text-button,
  .select,
  .page-link,
  .record-open-button {
    min-height: 44px;
  }

  .page-stack {
    gap: 14px;
  }

  .welcome {
    gap: 14px;
  }

  .welcome .actions,
  .card-head .actions,
  .table-toolbar {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 3px;
    scrollbar-width: none;
  }

  .welcome .actions::-webkit-scrollbar,
  .card-head .actions::-webkit-scrollbar,
  .table-toolbar::-webkit-scrollbar {
    display: none;
  }

  .welcome .actions > *,
  .card-head .actions > *,
  .table-toolbar > * {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .card-head {
    min-height: 0;
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 15px;
  }

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

  .stat-card {
    min-width: 0;
  }

  .module-stats {
    grid-template-columns: none !important;
    grid-auto-flow: column;
    grid-auto-columns: minmax(76vw, 1fr);
    gap: 11px;
    overflow-x: auto;
    padding: 1px 1px 8px;
    scroll-snap-type: inline mandatory;
    scrollbar-width: none;
  }

  .module-stats::-webkit-scrollbar {
    display: none;
  }

  .module-stat,
  .module-stat:last-child {
    grid-column: auto;
    min-height: 126px;
    scroll-snap-align: start;
  }

  .responsive-table {
    overflow: visible;
  }

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

  .responsive-table .mobile-card-table thead {
    display: none;
  }

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

  .responsive-table .mobile-card-table tbody tr {
    display: grid;
    grid-template-columns: 1fr;
    overflow: hidden;
    border: 1px solid #dfe7f0;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 5px 16px rgba(24, 49, 80, .05);
  }

  .responsive-table .mobile-card-table tbody td {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(88px, .7fr) minmax(0, 1.3fr);
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border: 0;
    border-bottom: 1px solid #edf1f5;
    color: #445971;
    text-align: right;
  }

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

  .responsive-table .mobile-card-table tbody td::before {
    content: attr(data-label);
    color: #8290a2;
    direction: rtl;
    font-size: 11px;
    font-weight: 800;
  }

  .responsive-table .mobile-card-table tbody td[colspan] {
    display: block;
    padding: 30px 16px;
    text-align: center;
  }

  .responsive-table .mobile-card-table tbody td[colspan]::before {
    content: none;
  }

  .responsive-table .mobile-card-table .row-menu,
  .responsive-table .mobile-card-table button,
  .responsive-table .mobile-card-table select,
  .responsive-table .mobile-card-table a.text-button {
    min-height: 40px;
  }

  .mini-progress {
    max-width: 100%;
  }

  .appointment-list {
    padding: 8px 11px 12px;
  }

  .appointment-row {
    min-height: 0;
    grid-template-columns: 62px 3px 40px minmax(0, 1fr) !important;
    grid-template-rows: auto auto auto;
    gap: 8px;
    margin-bottom: 10px;
    padding: 13px;
    border: 1px solid #e1e8f0;
    border-radius: 13px;
    background: #fff;
  }

  .appointment-row:last-child {
    margin-bottom: 0;
  }

  .appointment-row .appointment-time { grid-column: 1; grid-row: 1; }
  .appointment-row .color-line { grid-column: 2; grid-row: 1 / 3; height: 100%; }
  .appointment-row .avatar { grid-column: 3; grid-row: 1; width: 40px; height: 40px; }
  .appointment-row .patient-info { grid-column: 4; grid-row: 1; }
  .appointment-row .doctor-info { display: block !important; grid-column: 3 / 5; grid-row: 2; }
  .appointment-row .status { display: inline-flex !important; grid-column: 1; grid-row: 2; min-width: 0; }

  .appointment-row-actions {
    grid-column: 1 / -1;
    grid-row: 3;
    display: flex;
    justify-content: stretch;
    gap: 7px;
    padding-top: 10px;
    border-top: 1px solid #edf1f5;
  }

  .appointment-row-actions button,
  .appointment-row-actions .appointment-reschedule,
  .appointment-row-actions .row-menu {
    min-height: 42px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
  }

  .appointment-row-actions .appointment-next {
    flex: 1;
  }

  .appointment-row-actions .appointment-reschedule::after {
    content: " تغيير";
  }

  .schedule-toolbar > div,
  .schedule-view-switch {
    width: 100%;
  }

  .schedule-toolbar button,
  .schedule-toolbar input {
    min-height: 44px;
  }

  .schedule-calendar,
  .schedule-calendar.month,
  .week-strip,
  .teeth-canvas,
  .days-strip {
    scroll-snap-type: inline proximity;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .schedule-day,
  .week-strip button,
  .day-card {
    scroll-snap-align: start;
  }

  .dental-workflow-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .workflow-link {
    grid-template-columns: 40px 1fr;
    padding: 14px;
  }

  .workflow-link i {
    width: 40px;
    height: 40px;
  }

  .dental-encounter-tools,
  .clinical-section,
  .odontogram,
  .periodontal-odontogram {
    padding: 13px;
  }

  .teeth-canvas {
    margin-inline: -13px;
    padding-inline: 13px;
    touch-action: pan-x;
  }

  .tooth-button {
    touch-action: manipulation;
  }

  .surface-picker {
    flex-wrap: wrap;
  }

  .surface-picker label {
    width: 42px;
    height: 42px;
  }

  .page-form-actions {
    position: sticky;
    bottom: calc(82px + env(safe-area-inset-bottom));
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    border-color: #cfdceb;
    box-shadow: 0 10px 30px rgba(17, 45, 78, .16);
  }

  .page-form-actions > * {
    width: 100%;
    min-height: 46px;
    margin: 0;
    white-space: normal;
    text-align: center;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .modal-card,
  .modal-card.wide {
    width: 100%;
    max-width: none;
    max-height: min(94dvh, 900px);
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal-head {
    position: sticky;
    top: 0;
    z-index: 3;
    min-height: 76px;
    padding: 14px 16px;
    background: #fff;
  }

  .modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: #fff;
  }

  .modal-actions button {
    width: 100%;
  }

  .form-grid {
    padding: 16px;
  }

  .safe-note {
    margin-inline: 16px;
  }

  .toast,
  .portal-toast {
    right: 14px;
    bottom: calc(88px + env(safe-area-inset-bottom));
    left: 14px;
    justify-content: center;
    text-align: center;
  }

  .print-toolbar {
    position: sticky;
    top: 72px;
    z-index: 12;
    padding: 8px;
    border-radius: 12px;
    background: rgba(244, 247, 251, .96);
  }

  .print-toolbar > * {
    flex: 1;
  }

  .print-sheet {
    overflow-x: auto;
    padding: 20px;
  }

  /* Patient portal drawer and bottom navigation. */
  .portal-mobile-overlay {
    position: fixed;
    inset: 0;
    z-index: 64;
    border: 0;
    background: rgba(8, 27, 50, .54);
    opacity: 0;
    pointer-events: none;
    transition: .2s;
    backdrop-filter: blur(3px);
  }

  .portal-mobile-overlay.show {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .portal-sidebar {
    z-index: 70;
  }

  .portal-content > header {
    min-height: 68px;
    padding-top: max(9px, env(safe-area-inset-top));
  }

  .portal-bottom-nav {
    --mobile-nav-items: 5;
  }

  .portal-content #portal-view {
    padding-bottom: calc(108px + env(safe-area-inset-bottom));
  }

  .portal-card-head,
  .encounter-card > header,
  .prescription-card > header,
  .invoice-card > header,
  .dental-plan-portal-card > header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .quick-actions {
    grid-template-columns: 1fr 1fr !important;
  }

  .quick-actions button {
    min-width: 0;
    min-height: 86px;
    align-items: flex-start;
    padding: 14px;
  }

  .quick-actions i {
    flex: 0 0 42px;
  }

  .portal-list-item {
    align-items: flex-start;
  }

  .appointment-item time {
    width: 100%;
    margin: 3px 58px 0 0;
    text-align: right;
  }

  .appointment-patient-actions {
    width: 100%;
  }

  .appointment-patient-actions button {
    min-height: 42px;
    flex: 1;
  }

  .portal-form button,
  .booking-summary button {
    width: 100%;
    min-height: 48px;
  }

  .family-actions {
    margin-right: 0;
  }

  .family-actions button {
    min-height: 42px;
    flex: 1;
  }

  .portal-document-toolbar {
    top: calc(70px + env(safe-area-inset-top));
  }

  .portal-document-toolbar button {
    min-height: 44px;
  }

  .login-shell,
  .login-view {
    min-height: 100dvh;
  }
}

@media (max-width: 520px) {
  .page-content {
    padding-inline: 10px;
  }

  .top-actions .notification {
    display: none;
  }

  .global-search {
    padding-inline: 10px;
  }

  .global-search input::placeholder {
    color: transparent;
  }

  .stats-grid {
    gap: 8px;
  }

  .stat-card {
    min-height: 105px;
    display: block;
    padding: 12px;
  }

  .stat-icon {
    width: 34px;
    height: 34px;
    margin-bottom: 8px;
  }

  .stat-card strong {
    font-size: 18px;
  }

  .dental-workflow-grid,
  .dental-encounter-tool-grid {
    grid-template-columns: 1fr !important;
  }

  .plan-item-fields,
  .perio-sites-editor,
  .working-day-row,
  .page-form-actions {
    grid-template-columns: 1fr !important;
  }

  .plan-item-notes,
  .working-day-row .day-enabled {
    grid-column: auto !important;
  }

  .page-form-actions {
    max-height: 38dvh;
    overflow-y: auto;
  }

  .record-summary,
  .encounter-vitals,
  .vitals-grid {
    grid-template-columns: 1fr !important;
  }

  .section-title {
    align-items: flex-start;
  }

  .section-title > span {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .portal-content > header {
    padding-inline: 10px;
  }

  .family-switch span {
    display: none;
  }

  .portal-content #portal-view {
    padding-inline: 10px;
  }

  .portal-stats,
  .quick-actions,
  .invoice-totals,
  .print-meta-grid,
  .print-totals-grid,
  .slot-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .portal-stat {
    padding: 12px;
  }

  .portal-stat b {
    font-size: 20px;
  }

  .quick-actions button {
    min-height: 108px;
    flex-direction: column;
  }

  .portal-card,
  .encounter-card,
  .prescription-card,
  .invoice-card,
  .dental-plan-portal-card {
    padding: 14px;
    border-radius: 14px;
  }

  .booking-main,
  .booking-step {
    padding: 12px;
  }

  .booking-progress {
    grid-template-columns: repeat(4, 112px);
  }

  .portal-print-sheet {
    padding: 14px;
  }

  .portal-print-sheet > header,
  .portal-plan-sessions article div {
    flex-direction: column;
  }

  .portal-document-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media print {
  .mobile-bottom-nav,
  .portal-bottom-nav,
  .portal-mobile-overlay {
    display: none !important;
  }
}
