:root {
  --tablet-page-gutter: 24px;
  --mobile-page-gutter: 16px;
  --touch-target: 44px;
}

.container,
.main,
:is(#dashboard, #rooms, #faculty, #students, #settings),
#workspaceLandingView {
  min-width: 0;
}

@media (min-width: 700px) and (max-width: 1099px) {
  .sidebar {
    width: 76px !important;
    padding: 14px 8px !important;
  }

  .sidebar-brand {
    margin-bottom: 12px !important;
    padding: 4px 2px 14px !important;
  }

  .sidebar .sidebar-btn {
    justify-content: center !important;
    min-height: var(--touch-target);
    padding: 9px 6px !important;
    font-size: 0 !important;
  }

  .sidebar .sidebar-btn::before {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    font-size: 12px;
    font-weight: 750;
    line-height: 1;
  }

  .sidebar .sidebar-btn[data-nav-page="dashboard"]::before,
  .sidebar .sidebar-btn[data-nav-page="faculty-home"]::before {
    content: "D";
  }

  .sidebar .sidebar-btn[data-nav-page="rooms"]::before {
    content: "R";
  }

  .sidebar .sidebar-btn[data-nav-page="faculty"]::before {
    content: "F";
  }

  .sidebar .sidebar-btn[data-nav-page="students"]::before {
    content: "ST";
  }

  .sidebar .sidebar-btn[data-nav-page="workspaces"]::before,
  .sidebar .sidebar-btn[data-nav-page="faculty-current-workspace"]::before {
    content: "W";
  }

  .sidebar .sidebar-btn[data-nav-page="settings"]::before,
  .sidebar .sidebar-btn[data-nav-page="faculty-settings"]::before {
    content: "SE";
  }

  .sidebar-footer {
    display: flex;
    padding-top: 10px;
  }

  .sidebar-identity {
    display: none;
  }

  .sidebar .sidebar-logout-btn {
    min-height: var(--touch-target);
    padding: 8px 4px;
    font-size: 0;
  }

  .sidebar .sidebar-logout-btn::before {
    content: "Exit";
    font-size: 11px;
    font-weight: 700;
  }

  .main {
    max-width: none;
    padding: var(--tablet-page-gutter);
    overflow-x: hidden;
  }

  :is(#dashboard, #rooms, #faculty, #students, #settings) .controls,
  #workspaceLandingView :is(.workspace-header-actions, .workspace-selection-controls) {
    align-items: center;
    flex-wrap: wrap;
  }

  :is(#dashboard, #rooms, #faculty, #students, #settings) :is(
      button,
      .btn,
      .file-label,
      input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
      select
    ),
  #workspaceLandingView :is(
      button,
      .btn,
      input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
      select
    ),
  #workspaceLandingView :is(.workspace-year-summary, .workspace-filter-pill),
  #students :is(.school-card-header, .students-year-toggle) {
    min-height: var(--touch-target);
  }

  :is(#rooms, #faculty) .card-action-trigger {
    width: var(--touch-target);
    height: var(--touch-target);
  }

  .dashboard-page.active {
    display: block !important;
  }

  .dashboard-page .stats {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  :is(#rooms, #faculty) table {
    table-layout: fixed;
  }

  :is(#rooms, #faculty) :is(th, td) {
    padding: 9px 8px !important;
    overflow-wrap: anywhere;
  }

  #rooms :is(th, td):nth-child(1) {
    width: 44px;
  }

  #rooms :is(th, td):nth-child(2) {
    width: 46px;
  }

  #rooms :is(th, td):nth-child(3) {
    width: 11%;
  }

  #rooms :is(th, td):nth-child(4),
  #rooms :is(th, td):nth-child(8) {
    width: 9%;
  }

  #rooms :is(th, td):nth-child(5),
  #rooms :is(th, td):nth-child(6) {
    width: 17%;
  }

  #rooms :is(th, td):nth-child(7) {
    width: 15%;
  }

  #rooms :is(th, td):nth-child(9),
  #faculty :is(th, td):last-child {
    width: 56px;
  }

  #faculty :is(th, td):nth-child(1) {
    width: 44px;
  }

  #faculty :is(th, td):nth-child(4) {
    width: 90px;
  }

  #workspaceLandingView .workspace-library-controls {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(260px, auto);
  }

  #workspaceLandingView .workspace-search-field {
    max-width: none;
  }

  #workspaceLandingView .workspace-state-filter {
    grid-column: 1 / -1;
  }
}

@media (max-width: 699px) {
  .container.show {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    flex: 0 0 auto;
    gap: 8px 12px;
    width: 100% !important;
    max-height: none;
    padding: 8px var(--mobile-page-gutter) 10px !important;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-line);
  }

  .sidebar-brand {
    align-self: center;
    width: 112px !important;
    margin: 0 !important;
    padding: 2px 0 !important;
    border: 0 !important;
  }

  .app-brand-image {
    max-width: 112px;
    max-height: 34px;
  }

  .sidebar ul {
    grid-column: 1 / -1;
    grid-row: 2;
    flex: none;
    flex-direction: row !important;
    gap: 4px !important;
    width: 100%;
    margin: 0 !important;
    padding: 0 0 2px !important;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .sidebar ul::-webkit-scrollbar {
    display: none;
  }

  .sidebar li {
    flex: 0 0 auto;
  }

  .sidebar .sidebar-btn {
    min-height: var(--touch-target);
    width: auto;
    justify-content: center !important;
    padding: 9px 13px !important;
    font-size: 12.5px !important;
    white-space: nowrap;
  }

  .sidebar .sidebar-btn::before {
    content: none !important;
  }

  .sidebar .sidebar-btn.active {
    box-shadow: inset 0 -3px 0 #60a5fa !important;
  }

  .sidebar-footer {
    display: flex;
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .sidebar-identity {
    display: none;
  }

  .sidebar .sidebar-logout-btn {
    width: auto;
    min-height: var(--touch-target);
    padding: 8px 12px;
    font-size: 12px;
  }

  .sidebar-status-notices {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: 0;
  }

  .main {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 18px var(--mobile-page-gutter) 28px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  :is(#dashboard, #rooms, #faculty, #students, #settings),
  #workspaceLandingView {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  :is(#dashboard, #rooms, #faculty, #students, #settings) > h2,
  #workspaceLandingView > .workspace-header h2 {
    margin-bottom: 16px;
    padding-bottom: 10px;
    font-size: 22px;
  }

  :is(#dashboard, #rooms, #faculty, #students, #settings) .controls {
    align-items: stretch;
    gap: 8px;
  }

  :is(#rooms, #faculty, #students) .controls > :is(.btn, select, .file-input-wrapper),
  #settings .controls > .btn {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    margin-left: 0 !important;
  }

  :is(#rooms, #faculty, #students) .file-input-wrapper > :is(.btn, label),
  #students .controls > label.btn {
    width: 100%;
    justify-content: center;
  }

  :is(#dashboard, #rooms, #faculty, #students, #settings) :is(
      button,
      .btn,
      .file-label,
      input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
      select
    ),
  #workspaceLandingView :is(
      button,
      .btn,
      input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
      select
    ),
  #workspaceLandingView :is(.workspace-year-summary, .workspace-filter-pill),
  #students :is(.school-card-header, .students-year-toggle) {
    min-height: var(--touch-target);
  }

  .dashboard-page.active {
    display: block !important;
  }

  .dashboard-page .stats {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px;
  }

  .dashboard-page .stat-card {
    min-height: 92px;
    padding: 16px !important;
  }

  #dashboardCampusMapSection {
    padding: 14px !important;
  }

  .dashboard-page .campus-map-box {
    height: clamp(300px, 52vh, 420px) !important;
    min-height: 300px !important;
  }

  :is(#rooms, #faculty) table {
    display: block;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  :is(#rooms, #faculty) thead {
    display: none;
  }

  :is(#rooms, #faculty) tbody {
    display: grid;
    gap: 12px;
  }

  :is(#rooms, #faculty) tbody tr {
    display: block;
    overflow: visible;
    border: 1px solid var(--line-soft) !important;
    border-radius: var(--radius-md);
    background: var(--panel-bg);
    box-shadow: var(--shadow-xs);
  }

  :is(#rooms, #faculty) tbody tr.row-selected {
    border-color: #93b4d8 !important;
    background: var(--accent-soft);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
  }

  :is(#rooms, #faculty) tbody td:not(.multi-col) {
    display: grid;
    grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    width: 100% !important;
    min-height: var(--touch-target);
    padding: 9px 12px !important;
    border-bottom: 1px solid #e8edf2;
    text-align: left;
    overflow-wrap: anywhere;
  }

  :is(#rooms, #faculty) tbody td:not(.multi-col)::before {
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.045em;
    text-transform: uppercase;
  }

  :is(#rooms, #faculty) tbody td.multi-col {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: var(--touch-target);
    padding: 8px 12px !important;
    border-bottom: 1px solid #e8edf2;
  }

  :is(#rooms, #faculty) tbody td.multi-col::after {
    content: "Select record";
    margin-left: 10px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 650;
  }

  :is(#rooms, #faculty) tbody td:last-child {
    border-bottom: 0;
  }

  :is(#rooms, #faculty) tbody td[colspan] {
    display: block;
    padding: 18px 14px !important;
    color: var(--text-muted);
    text-align: center;
  }

  :is(#rooms, #faculty) tbody td[colspan]::before {
    content: none;
  }

  #rooms tbody td:nth-child(2)::before {
    content: "S No";
  }

  #rooms tbody td:nth-child(3)::before {
    content: "Number";
  }

  #rooms tbody td:nth-child(4)::before {
    content: "Capacity";
  }

  #rooms tbody td:nth-child(5)::before {
    content: "Location";
  }

  #rooms tbody td:nth-child(6)::before {
    content: "Primary School";
  }

  #rooms tbody td:nth-child(7)::before {
    content: "Type";
  }

  #rooms tbody td:nth-child(8)::before {
    content: "Projector";
  }

  #rooms tbody td:nth-child(9)::before,
  #faculty tbody td:nth-child(6)::before {
    content: "Actions";
  }

  #faculty tbody td:nth-child(2)::before {
    content: "Name";
  }

  #faculty tbody td:nth-child(3)::before {
    content: "Email";
  }

  #faculty tbody td:nth-child(4)::before {
    content: "On Campus";
  }

  #faculty tbody td:nth-child(5)::before {
    content: "Address";
  }

  #rooms tbody td[colspan]::before,
  #faculty tbody td[colspan]::before {
    content: none;
  }

  :is(#rooms, #faculty) .card-action-trigger {
    width: var(--touch-target);
    height: var(--touch-target);
  }

  #students .students-master-detail {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  #students .school-card-actions {
    opacity: 1;
    pointer-events: auto;
  }

  #students :is(.school-card-header, .students-school-detail-header) {
    flex-direction: column;
  }

  #students :is(.school-card-actions, .students-school-detail-actions) {
    width: 100%;
    justify-content: flex-start;
  }

  #students .students-cohort-item {
    align-items: flex-start;
    flex-direction: column;
  }

  #workspaceLandingView > .workspace-header {
    align-items: stretch;
    flex-direction: column;
  }

  #workspaceLandingView .workspace-header-actions,
  #workspaceLandingView .workspace-selection-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  #workspaceLandingView :is(.workspace-header-actions, .workspace-selection-controls) .btn {
    width: 100%;
  }

  #workspaceLandingView .workspace-library-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 14px;
  }

  #workspaceLandingView :is(.workspace-search-field, .workspace-state-filter, .workspace-state-filter select) {
    width: 100%;
    max-width: none;
  }

  #workspaceLandingView .workspace-timeline-filter {
    width: 100%;
  }

  #workspaceLandingView .workspace-filter-pills {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #workspaceLandingView .workspace-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #workspaceLandingView :is(.workspace-year-summary, .workspace-year-content) {
    padding-left: 12px;
    padding-right: 12px;
  }

  #workspaceLandingView .workspace-card {
    min-height: 0;
    padding: 14px;
  }

  #settings :is(.page-intro, .settings-section) {
    padding: 16px !important;
  }

  #settings .settings-section .form-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  #settings .form-row > .form-group {
    display: grid !important;
    align-items: stretch !important;
    gap: 8px !important;
    min-width: 0;
  }

  #settings .form-row .btn {
    width: 100%;
  }

  #settings .settings-visibility-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #settings .settings-visibility-item {
    min-height: var(--touch-target);
  }

  #settings .settings-branding-preview {
    max-width: 100%;
  }

  .modal-footer .btn,
  .pascal-modal__footer .btn {
    min-height: var(--touch-target);
  }

}

@media (max-width: 699px) and (hover: none) {
  :is(.stat-card, #workspaceLandingView .workspace-card, #students .school-card):hover {
    transform: none !important;
  }
}
