/*
 * Tablet specific stylesheet for FireDoorApp
 *
 * Loaded only for 769px–1366px viewports. Tablet should behave like mobile:
 * - Off-canvas nav with hamburger trigger
 * - Mobile-like layout density
 * - Tables scroll with visible affordance
 * - Modals use a single scroll region + safe-area padding
 */

@media (min-width: 769px) and (max-width: 1366px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  :where(html, body) {
    overflow-x: hidden;
  }

  /* Tablet should keep a clean, neutral page background (avoid the blue-tinted gradient). */
  body {
    background: var(--background, #f6f6f6);
    background-attachment: scroll;
  }

  /* Remove the page gradient overlay on tablet for a cleaner, whiter UI. */
  .content::before {
    display: none;
  }

  .top-bar {
    background: #ffffff;
    backdrop-filter: none;
  }

  html[data-theme="dark"] .top-bar {
    background: rgba(2, 6, 23, 0.66);
    border-color: rgba(148, 163, 184, 0.22);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  }

  /* Prevent iOS Safari form-field zoom (must be >= 16px). */
  :where(input, select, textarea) {
    font-size: 16px;
  }

  :where(.content, .admin-shell) {
    overflow-wrap: anywhere;
  }

  :where(.content, .admin-shell, .modal__dialog) :where(input, select, textarea) {
    max-inline-size: 100%;
  }

  .show-on-mobile {
    display: block !important;
  }

  .show-on-mobile.btn,
  .show-on-mobile.btn-primary-modern,
  .show-on-mobile.btn-secondary-outline,
  .show-on-mobile.btn-sm-modern,
  .show-on-mobile.btn-small {
    display: inline-flex !important;
  }

	  /* === Tablet nav behaves like mobile === */

	  .mobile-nav-trigger {
	    position: relative;
	    top: auto;
	    right: auto;
	    width: 38px;
	    height: 38px;
	    border-radius: 10px;
	    border: 1px solid var(--rule-strong);
	    background: var(--surface-card);
	    display: flex;
	    align-items: center;
	    justify-content: center;
	    flex-direction: column;
	    gap: 4px;
	    z-index: 1200;
	    cursor: pointer;
	    padding: 0;
	    box-shadow: var(--shadow-sm);
	  }

	  .mobile-nav-trigger span {
	    width: 18px;
	    height: 1.75px;
	    background: var(--ink-2);
	  }

	  .mobile-nav-overlay {
	    inset: 0;
	  }


  body.mobile-nav-open {
    overflow: hidden;
  }




  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    min-height: 56px;
  }

  .logo-image {
    max-width: 140px;
  }

  .tb-search {
    flex: 1 1 260px;
    max-width: none;
    min-width: 180px;
  }

  .tb-nav {
    gap: 4px;
  }

  .tb-uname {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar {
    --sidebar-link-padding: 8px 10px;
    --sidebar-padding-x: 12px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: min(78vw, 320px);
    padding: 18px 12px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-110%);
    transition: transform 0.3s ease;
    z-index: 1150;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid var(--rule);
    background: var(--surface-card);
    color: var(--ink-2);
    box-shadow: 0 24px 40px rgba(26, 24, 21, 0.14);
  }

  body.mobile-nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-brand {
    display: none;
  }

  .sidebar-nav__link,
  .sb-item {
    font-size: 0.96rem;
    border-radius: 10px;
    min-block-size: 42px;
  }

  .content {
    padding: 16px;
  }

  /* Tablet header: single row when possible, wrap only as fallback. */
  .top-bar {
    margin: -16px -16px 16px;
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }

  @media (max-width: 980px) {
    .tb-search {
      max-width: 280px;
    }

    .tb-btn span {
      display: none;
    }

    .tb-divider--compact {
      display: none;
    }
  }

  .top-bar-left {
    flex: 1 1 100%;
    min-width: 0;
  }

  .top-bar-right {
    flex: 1 1 100%;
    min-width: 0;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .top-bar-search {
    flex: 1 1 280px;
    max-width: none;
    min-width: 200px;
  }

  .top-bar-link {
    flex: 0 0 auto;
  }

  .top-bar-user {
    max-width: 200px;
  }

  :where(.top-bar-search input) {
    min-width: 0;
    width: 100%;
    font-size: 16px;
  }

  .top-bar-actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    white-space: nowrap;
  }

  /* Narrow tablets: prioritise layout stability over single-row density. */
  @media (max-width: 980px) {
  .top-bar-right {
    justify-content: flex-start;
  }

  .top-bar-search {
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
    order: 2;
  }

  .top-bar-actions {
    order: 3;
  }

  .top-bar-link__label {
    display: none;
  }

  .top-bar-user {
    max-width: 160px;
  }
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

	  .page-header__actions {
	    width: 100%;
	    justify-content: flex-start;
	    flex-wrap: wrap;
	    gap: 8px;
	  }

		  /* === Tablet tables behave like mobile === */
		  :where(
	    .table-wrapper,
	    .table-responsive,
	    .asset-door-table-wrapper,
    .asset-component-table-wrapper,
    .rem-board-table-wrapper
    
  ) {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    max-inline-size: 100%;
  }

  :where(
    .table-wrapper,
    .table-responsive,
    .asset-door-table-wrapper,
    .asset-component-table-wrapper,
    .rem-board-table-wrapper
    
  )::before,
  :where(
    .table-wrapper,
    .table-responsive,
    .asset-door-table-wrapper,
    .asset-component-table-wrapper,
    .rem-board-table-wrapper
    
  )::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 18px;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  :where(
    .table-wrapper,
    .table-responsive,
    .asset-door-table-wrapper,
    .asset-component-table-wrapper,
    .rem-board-table-wrapper
    
  )::before {
    left: 0;
    background: linear-gradient(90deg, rgba(15, 23, 42, 0.14), rgba(15, 23, 42, 0));
  }

  :where(
    .table-wrapper,
    .table-responsive,
    .asset-door-table-wrapper,
    .asset-component-table-wrapper,
    .rem-board-table-wrapper
    
  )::after {
    right: 0;
    background: linear-gradient(270deg, rgba(15, 23, 42, 0.14), rgba(15, 23, 42, 0));
  }

  :where(
    .table-wrapper,
    .table-responsive,
    .asset-door-table-wrapper,
    .asset-component-table-wrapper,
    .rem-board-table-wrapper
    
  ).table-scroll-hints--left::before {
    opacity: 0.9;
  }

  :where(
    .table-wrapper,
    .table-responsive,
    .asset-door-table-wrapper,
    .asset-component-table-wrapper,
    .rem-board-table-wrapper
    
  ).table-scroll-hints--right::after {
    opacity: 0.9;
  }

  :where(
    .table-wrapper table,
    .table-responsive table,
    .asset-door-table-wrapper table,
    .asset-component-table-wrapper table,
    .rem-board-table-wrapper table
  ) {
    inline-size: max-content;
    min-inline-size: 100%;
    max-inline-size: none;
  }

  /* === Tablet modals behave like mobile === */
  body.modal-open {
    overflow: hidden;
  }

  .modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

	  .modal__dialog {
	    position: relative;
	    z-index: 1;
	    background: var(--card);
	    border-radius: 16px;
	    width: min(720px, 100%);
	    max-block-size: 100%;
	    overflow: hidden;
	    display: flex;
	    flex-direction: column;
	    box-shadow: 0 25px 65px rgba(9, 41, 57, 0.18);
	  }

	  .modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 14px 16px;
    margin: 0;
	    border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
	    background: var(--card);
	    position: sticky;
	    top: 0;
	    z-index: 2;
	  }

  .modal__close {
    inline-size: 44px;
    block-size: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .modal__body {
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    min-block-size: 0;
  }

  .modal__body:not(form) {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

	  .modal__footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
	    border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
	    background: var(--card);
	    flex: 0 0 auto;
	  }

  /* Component inspection guide modal (opened via the "i" buttons). */
  .component-guide-modal {
    align-items: center;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .component-guide-modal__dialog {
    border-radius: 16px;
    width: min(720px, 100%);
    max-height: 100%;
    box-shadow: 0 25px 65px rgba(9, 41, 57, 0.18);
  }

  .component-guide-modal__header {
    padding: 14px 16px 12px;
  }

  .component-guide-modal__body {
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .component-guide-modal__close {
    top: 10px;
    right: 10px;
    inline-size: 44px;
    block-size: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

	  body.modal-open .mobile-nav-trigger,
	  body.modal-open .mobile-nav-overlay {
	    pointer-events: none;
	    opacity: 0;
	  }

  .modal :where(input[type="checkbox"], input[type="radio"]) {
    inline-size: 20px;
    block-size: 20px;
    min-inline-size: 20px;
    min-block-size: 20px;
    accent-color: var(--brand, #0052cc);
  }

  .modal :where(label > input[type="checkbox"], label > input[type="radio"]) {
    vertical-align: middle;
    margin-right: 10px;
  }

  /* === Invoices page: tablet optimisation === */
  /* Tables: stack `.table-stack-mobile` rows into cards on tablet for consistency. */
  .table-stack-mobile thead {
    display: none;
  }

  .table-stack-mobile tbody,
  .table-stack-mobile tr,
  .table-stack-mobile td {
    display: block;
    width: 100%;
  }

	  .table-stack-mobile tr {
	    margin-bottom: 12px;
	    border-radius: 12px;
	    background: var(--card);
	    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
	    overflow: visible;
	  }

	  .table-stack-mobile td {
	    border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
	    padding: 10px 14px;
	    position: relative;
	    font-size: 0.95rem;
	  }

  .table-stack-mobile td:last-child {
    border-bottom: none;
  }

	  .table-stack-mobile td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
	    color: var(--text-muted, #9ca3af);
	    margin-bottom: 2px;
	  }

  .table-stack-mobile td:not([data-label])::before,
  .table-stack-mobile td[data-label=""]::before {
    display: none;
  }

  .table-stack-mobile td[data-label="Actions"]::before {
    display: none;
  }

  .table-stack-mobile td[data-label="Actions"],
  .table-stack-mobile td[data-label=""] {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
  }

  .table--compact.table-stack-mobile td {
    padding: 10px 12px;
  }

  .table-wrapper--sticky {
    max-height: min(70vh, 720px);
    overflow: auto;
  }

  .table-wrapper--sticky thead th {
    position: sticky;
    top: 0;
    z-index: 5;
  }

		  /* === Layout exceptions for tablet === */
	  .layout-columns-2 {
	    grid-template-columns: minmax(0, 1fr);
	  }

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

.guided-tour {
  right: 16px;
  bottom: 16px;
  width: min(420px, calc(100vw - 32px));
}
