/* ===========================================================================
   Global Responsive / Touch-friendly Base Styles
   =========================================================================== */

@media (max-width: 1366px) {
  button, a, select,
  input[type="text"], input[type="number"],
  input[type="password"], input[type="email"] {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
}

@media (max-width: 431px) {
  button {
    min-height: 44px;
  }
  input[type="text"], input[type="number"], input[type="password"],
  input[type="email"], select, textarea {
    font-size: 16px !important;
    min-height: 44px;
  }

  /* Hide desktop header on mobile */
  .app-shell-header {
    display: none !important;
  }

  /* Main content padding for top/bottom bars with safe-area */
  #appShellContent {
    padding-top: calc(48px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  #queryAppContainer {
    padding-top: calc(48px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

  /* ---- Admin Modal: full-screen on mobile ---- */
  #adminModal {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
    transform: none !important;
    border-radius: 0 !important;
    resize: none !important;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 8px calc(8px + env(safe-area-inset-bottom, 0px)) 8px;
    box-sizing: border-box;
  }

  #adminHeader {
    cursor: default;
    flex-shrink: 0;
  }
  #adminHeader h3 {
    font-size: 15px;
  }
  #adminClose {
    min-height: 40px;
    min-width: 60px;
    font-size: 13px;
  }

  /* Tabs: horizontal scroll, no wrap */
  .adminToolbar {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 4px;
    scrollbar-width: none;
  }
  .adminToolbar::-webkit-scrollbar {
    display: none;
  }
  .adminTab {
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 11px;
    white-space: nowrap;
    min-height: 38px;
  }
  .adminTab svg {
    width: 13px !important;
    height: 13px !important;
  }

  /* Breadcrumb */
  .adminBreadcrumb {
    font-size: 11px;
    padding: 3px 4px;
  }

  /* Content area */
  .adminContent {
    padding: 8px;
    border-radius: 8px;
  }

  /* Form rows: stack vertically */
  .adminRow {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  .adminRow label {
    font-size: 12px;
  }
  .adminRow input,
  .adminRow select,
  .adminRow textarea {
    width: 100%;
    box-sizing: border-box;
    font-size: 14px !important;
    min-height: 40px;
  }

  /* Tables: horizontal scroll */
  .adminContent > .adminPane,
  .adminContent > div {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .adminTable {
    font-size: 11px;
    min-width: 500px;
  }
  .adminTable th,
  .adminTable td {
    padding: 6px 4px;
  }

  /* Action buttons */
  .adminActions {
    flex-wrap: wrap;
    gap: 4px;
  }
  .adminActions button,
  .adminActions .btn {
    min-height: 38px;
    font-size: 12px;
    padding: 4px 8px;
  }

  /* Handsontable grids inside admin */
  #adminModal .ht_master {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* App permissions add-user modal */
  #appPermsAddUserModal {
    width: 90vw !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    top: 5% !important;
    bottom: 5% !important;
  }
}

/* ===========================================================================
   Mobile Top Bar
   =========================================================================== */

.mobile-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(48px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff3e0;
  border-bottom: 1px solid #e0e0e0;
  z-index: 200;
  font-family: 'Segoe UI', Arial, sans-serif;
  box-sizing: border-box;
}

.mobile-topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: #333;
  letter-spacing: 0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80%;
  text-align: center;
}

/* ===========================================================================
   Mobile Bottom Navigation
   =========================================================================== */

.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  z-index: 200;
  font-family: 'Segoe UI', Arial, sans-serif;
  box-sizing: border-box;
}

.mobile-nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: #888;
  font-size: 10px;
  cursor: pointer;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  min-height: 56px;
}

.mobile-nav-tab.active {
  color: #1565c0;
}

.mobile-nav-tab:active {
  background: rgba(21, 101, 192, 0.06);
}

.mobile-nav-tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}
.mobile-nav-tab[data-tab-id="home"] .mobile-nav-tab-label {
  color: #BF360C;
  font-weight: 700;
}

.mobile-nav-tab-label {
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

/* ===========================================================================
   Mobile Action Sheet
   =========================================================================== */

.mobile-action-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 300;
}

.mobile-action-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 14px 14px 0 0;
  z-index: 301;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-action-sheet--visible {
  transform: translateY(0);
}

.mobile-action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  background: transparent;
  color: #333;
  font-size: 15px;
  font-family: 'Segoe UI', Arial, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}

.mobile-action-row:active {
  background: #f5f5f5;
}

.mobile-action-row-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: #555;
}

.mobile-action-row-label {
  font-weight: 500;
}

.mobile-action-cancel {
  margin-top: 4px;
  border-top: 1px solid #e0e0e0;
  color: #c62828;
}

.mobile-action-cancel .mobile-action-row-icon {
  color: #c62828;
}

/* ===========================================================================
   Mobile Profile Card
   =========================================================================== */

.mobile-profile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 300;
}

.mobile-profile-card {
  position: fixed;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  left: 16px;
  right: 16px;
  background: #fff;
  border-radius: 14px;
  padding: 24px 20px;
  z-index: 301;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  font-family: 'Segoe UI', Arial, sans-serif;
}

.mobile-profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1565c0;
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.mobile-profile-name {
  font-size: 17px;
  font-weight: 700;
  color: #333;
  margin-bottom: 4px;
}

.mobile-profile-email {
  font-size: 13px;
  color: #777;
}

/* ===========================================================================
   Mobile Home Screen Icon Grid
   =========================================================================== */

.mobile-app-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px 16px;
  padding: 28px 24px;
  justify-items: center;
}

.mobile-app-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.1s;
}

.mobile-app-icon:active {
  transform: scale(0.9);
}

.mobile-app-icon-img {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.mobile-app-icon-img svg {
  width: 30px;
  height: 30px;
}

.mobile-app-label {
  font-size: 12px;
  font-weight: 500;
  color: #333;
  text-align: center;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Segoe UI', Arial, sans-serif;
}

/* ===========================================================================
   Tablet Adjustments
   =========================================================================== */

@media (min-width: 432px) and (max-width: 1024px) {
  .app-shell-home-btn {
    width: 44px;
    height: 44px;
  }
  .app-shell-btn {
    min-height: 40px;
    padding: 0 14px;
  }
  .app-shell-logout-btn {
    min-height: 40px;
    padding: 0 14px;
  }

  /* Object Studio — mobile padding */
  #objectStudioAppContainer {
    padding-top: calc(48px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }
  #objectStudioAppContainer .toolbar {
    flex-wrap: wrap;
    gap: 4px;
  }
  #objectStudioAppContainer .toolbar label {
    display: none;
  }
  #osSearchInput {
    min-width: 0;
    flex: 1;
  }
}
