/* Mobile-only layout layer (keeps desktop untouched) */
@media (max-width: 768px) {
  /* Layout: give content full width */
  .app-container {
    width: 100%;
  }

  .main-content {
    width: 100%;
    background: #f8fafc;
  }

  .view {
    /* Top padding leaves room for the floating mobile menu button */
    padding: 64px 14px 22px;
    background: #f8fafc;
  }

  /* Header: compact */
  .top-header {
    height: auto;
    min-height: 56px;
    padding: 10px 12px;
    gap: 10px;
  }

  .top-header-center {
    width: 100%;
  }

  .top-header-search input {
    font-size: 0.92rem;
  }

  .top-header-user {
    padding: 8px 10px;
    gap: 10px;
  }

  /* Mobile: hide the entire workspace/header bar across ALL tabs */
  .top-header,
  .breadcrumbs,
  #header-module-pill {
    display: none !important;
  }

  /* Mobile Drawer: sleek app-style sidebar (desktop untouched) */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 340px);
    z-index: 1900;
    transform: translateX(0);
    transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    border-top-right-radius: 22px;
    border-bottom-right-radius: 22px;
    box-shadow: 18px 0 45px rgba(15, 23, 42, 0.18);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Remove decorative desktop flourishes inside the mobile drawer */
  .sidebar::before,
  .sidebar::after {
    display: none !important;
  }

  .sidebar-shell {
    padding: 12px 12px 14px;
    gap: 12px;
  }

  .logo {
    padding: 8px 4px 4px;
    margin-bottom: 6px;
    gap: 10px;
    text-align: left;
    align-items: stretch;
  }

  .logo-topbar {
    justify-content: flex-end;
  }

  .sidebar-toggle-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border-color: #e2e8f0;
    background: #ffffff;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.06);
  }

  .logo-lockup {
    padding: 12px;
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #f1f5f9;
    box-shadow: none;
  }

  .logo-mark {
    height: 46px;
    max-width: 78px;
    filter: none;
  }

  .logo-caption {
    color: #475569;
    letter-spacing: 0.14em;
  }

  .logo-subcaption {
    color: #0f172a;
  }

  .nav-menu {
    padding: 0;
    gap: 12px;
  }

  .nav-section {
    margin: 0;
    padding: 10px 10px 8px;
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
    backdrop-filter: none;
  }

  .nav-header {
    color: #64748b;
  }

  .nav-section-line {
    background: linear-gradient(90deg, rgba(148, 163, 184, 0.6), rgba(148, 163, 184, 0));
  }

  .nav-item a {
    padding: 12px 12px;
    min-height: 46px;
    border-radius: 16px;
    justify-content: flex-start;
    color: #0f172a;
    font-weight: 700;
    background: transparent;
    border: 1px solid transparent;
    transform: none;
    box-shadow: none;
  }

  .nav-item a::before,
  .nav-item a::after {
    display: none !important;
  }

  /* style.css hides labels under 860px; on mobile we want icon + label in the drawer */
  .sidebar .nav-item-label {
    display: inline-block !important;
    opacity: 1 !important;
    width: auto !important;
    max-width: none !important;
    white-space: normal;
  }

  .nav-item-icon {
    color: #475569;
    flex: 0 0 1.15rem;
  }

  .nav-item.active a {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
    box-shadow: none;
  }

  .nav-item:hover a {
    transform: none;
    box-shadow: none;
    background: #f8fafc;
    border-color: #e2e8f0;
  }

  /* Mobile priority: keep only core modules visible until "More" is expanded */
  .nav-list-modules .nav-item:not([data-mobile-primary="true"]):not([data-mobile-more-toggle="true"]) {
    display: none;
  }

  /* Web-only modules stay hidden in mobile scope. */
  .nav-list-modules .nav-item[data-mobile-web-only="true"] {
    display: none !important;
  }

  body.mobile-sidebar-more-open .nav-list-modules .nav-item {
    display: list-item;
  }

  .nav-item-mobile-more {
    display: list-item !important;
  }

  .mobile-more-toggle {
    width: 100%;
    min-height: 46px;
    padding: 12px 12px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #0f172a;
    font: inherit;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
  }

  .mobile-more-toggle:active {
    transform: translateY(0);
  }

  .mobile-more-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
  }

  .sidebar-profile-card {
    border-radius: 18px;
    border-color: #e2e8f0;
    background: #ffffff;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
  }

  .sidebar-profile-copy {
    display: flex !important;
    flex-direction: column;
    gap: 2px;
  }

  .sidebar-profile-copy span {
    color: #64748b !important;
    font-size: 0.76rem;
    font-weight: 700;
  }

  .sidebar-profile-copy strong {
    color: #0f172a !important;
  }

  .sidebar-profile-copy small {
    color: #475569 !important;
  }

  body.sidebar-collapsed .sidebar {
    width: min(86vw, 340px);
    transform: translateX(-105%);
  }

  /* Backdrop when sidebar is open (mobile only) */
  .main-content::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
    z-index: 1800;
  }

  body.mobile-sidebar-open .main-content::before {
    opacity: 1;
    pointer-events: auto;
  }

  /* Lock background scroll while the drawer is open */
  body.mobile-sidebar-open .main-content {
    overflow: hidden !important;
  }

  /* Floating mobile menu button (replaces hidden header hamburger) */
  .mobile-fab-menu {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    left: 12px;
    z-index: 2100;
    width: 46px;
    height: 46px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    background: rgba(255, 255, 255, 0.96);
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
    cursor: pointer;
    backdrop-filter: blur(10px);
  }

  body.mobile-sidebar-open .mobile-fab-menu {
    opacity: 0.7;
  }

  /* Cards/sections stack cleanly */
  .dashboard-grid,
  .dashboard-stat-strip,
  .dashboard-admin-main-grid,
  .dashboard-admin-secondary-grid,
  .dashboard-admin-bottom-grid,
  .dashboard-admin-table-grid,
  .sales-portal-grid {
    grid-template-columns: 1fr !important;
  }

  /* Dashboard: mobile field shell */
  #view-dashboard #dashboard-mobile-shell {
    display: block !important;
  }

  /* Dashboard: hide the desktop header chrome (search/bell/icons) on mobile only */
  body[data-active-view="dashboard"] .top-header {
    display: none !important;
  }

  body[data-active-view="dashboard"] .top-header-center,
  body[data-active-view="dashboard"] .top-header-user,
  body[data-active-view="dashboard"] .breadcrumbs,
  body[data-active-view="dashboard"] #header-module-pill {
    display: none !important;
  }

  body[data-active-view="dashboard"] .top-header-left {
    width: 100%;
    justify-content: flex-start;
  }

  body[data-active-view="dashboard"] .top-header-left .sidebar-toggle-btn-header {
    margin-right: 8px;
  }

  #view-dashboard .dashboard-admin-shell {
    gap: 10px;
  }

  /* Keep only the welcome user line in the dashboard header area */
  #view-dashboard .dashboard-welcome-banner {
    padding: 4px 2px 2px;
    min-height: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  #view-dashboard .dashboard-welcome-kicker,
  #view-dashboard .dashboard-welcome-copy p,
  #view-dashboard .dashboard-welcome-meta {
    display: none !important;
  }

  #view-dashboard .dashboard-welcome-copy {
    width: 100%;
  }

  #view-dashboard .dashboard-welcome-copy h2 {
    margin: 0;
    font-size: 1.15rem;
    line-height: 1.25;
    color: #0f172a;
    letter-spacing: 0;
  }

  #view-dashboard .dashboard-mobile-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 6px;
  }

  #view-dashboard .dashboard-mobile-actions .btn {
    flex: 1;
    min-width: 120px;
    min-height: 42px;
  }

  /* Keep form controls legible on light mobile cards */
  .form-control {
    color: #0f172a;
    background-color: #ffffff;
    border-color: #e2e8f0;
  }

  .form-control::placeholder {
    color: #64748b;
  }

  #view-dashboard .dashboard-mobile-grid {
    margin-top: 12px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  #view-dashboard .dashboard-mobile-card {
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
    padding: 14px 14px 12px;
    overflow: hidden;
  }

  #view-dashboard .dashboard-mobile-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
  }

  #view-dashboard .dashboard-mobile-card-head strong {
    color: #0f172a;
    font-weight: 900;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
  }

  #view-dashboard .dashboard-mobile-list {
    display: grid;
    gap: 8px;
  }

  #view-dashboard .dashboard-mobile-item {
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    background: #f1f5f9;
    padding: 10px 10px;
    display: grid;
    gap: 6px;
  }

  #view-dashboard .dashboard-mobile-item-title {
    color: #0f172a;
    font-weight: 800;
    font-size: 0.9rem;
    line-height: 1.2;
    word-break: break-word;
  }

  #view-dashboard .dashboard-mobile-item-sub {
    color: #475569;
    font-size: 0.82rem;
    line-height: 1.35;
  }

  #view-dashboard .dashboard-mobile-item-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  /* Hide heavy desktop dashboard sections on mobile (desktop remains unchanged) */
  #view-dashboard .dashboard-stat-strip,
  #view-dashboard .dashboard-admin-main-grid,
  #view-dashboard .dashboard-admin-secondary-grid,
  #view-dashboard .dashboard-admin-bottom-grid,
  #view-dashboard .dashboard-admin-table-grid {
    display: none !important;
  }

  .jobs-tech-filter-bar,
  .map-planner-controls {
    gap: 10px;
  }

  .btn,
  .btn.btn-primary {
    max-width: 100%;
  }

  /* Modals: near full screen */
  .modal-overlay {
    padding: 10px;
  }

  .modal-content {
    width: 100% !important;
    max-width: none !important;
    max-height: 94vh;
    border-radius: 16px;
    padding: 18px;
  }

  /* Tables: safe scroll */
  .jobs-tech-table-wrap,
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Jobs & Techs: replace kanban/ledger with mobile cards */
  #view-jobs .jobs-command-deck,
  #view-jobs .jobs-summary-grid,
  #view-jobs .jobs-board-shell,
  #view-jobs .jobs-tech-table-card,
  #view-jobs .jobs-tech-filter-bar {
    display: none !important;
  }

  /* Mobile uses its own filters/search; desktop tab strip is redundant here */
  #view-jobs .jobs-tab-strip {
    display: none !important;
  }

  #view-jobs .jobs-mobile-cards {
    display: block !important;
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .jobs-mobile-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .jobs-mobile-searchbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.06);
  }

  .jobs-mobile-searchbar i {
    color: #64748b;
  }

  .jobs-mobile-searchbar .jobs-mobile-search-input {
    flex: 1;
    min-width: 0;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
  }

  .jobs-mobile-search-clear {
    width: 38px;
    height: 38px;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .jobs-mobile-filterbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .jobs-mobile-filterbar .btn {
    min-height: 40px;
    padding: 8px 10px;
  }

  .jobs-mobile-filterbar .btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #ffffff;
  }

  .jobs-mobile-groups {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .jobs-mobile-group {
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
    overflow: hidden;
  }

  .jobs-mobile-group-summary {
    list-style: none;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
  }

  .jobs-mobile-group-summary::-webkit-details-marker {
    display: none;
  }

  .jobs-mobile-group-left {
    display: inline-flex;
    align-items: center;
    gap: 10px;
  }

  .jobs-mobile-group-count {
    min-width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.82rem;
    padding: 0 8px;
  }

  .jobs-mobile-group-chevron {
    color: #64748b;
    transition: transform 0.18s ease;
  }

  .jobs-mobile-group[open] .jobs-mobile-group-chevron {
    transform: rotate(180deg);
  }

  .jobs-mobile-group-body {
    padding: 12px 12px 2px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .jobs-mobile-card {
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
    padding: 14px 14px 12px;
  }

  .jobs-mobile-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
  }

  .jobs-mobile-title {
    font-weight: 800;
    color: #0f172a;
    font-size: 0.98rem;
    line-height: 1.25;
  }

  .jobs-mobile-sub {
    color: #475569;
    font-size: 0.82rem;
    margin-top: 6px;
    line-height: 1.35;
  }

  .jobs-mobile-grid {
    margin-top: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .jobs-mobile-field {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 10px 10px;
    min-width: 0;
  }

  .jobs-mobile-field span {
    display: block;
    color: #475569;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 6px;
  }

  .jobs-mobile-field strong {
    display: block;
    color: #0f172a;
    font-size: 0.86rem;
    font-weight: 700;
    word-break: break-word;
  }

  .jobs-mobile-notes {
    margin-top: 10px;
    color: #475569;
    font-size: 0.82rem;
    line-height: 1.45;
  }

  .jobs-mobile-notes-label {
    color: #0f172a;
  }

  .jobs-mobile-actions {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .jobs-mobile-actions .btn {
    min-height: 40px;
  }

  /* Smaller phones: handled by the top-level 520px media query at the end of this file. */

  /* SLA Management: hide register table only (keep events table visible) */
  #sla-register-card .jobs-tech-table-wrap {
    display: none !important;
  }

  #view-sla-management .sla-mobile-cards {
    display: flex !important;
    flex-direction: column;
    gap: 12px;
    padding: 0 14px 14px;
  }

  .sla-mobile-card {
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
    padding: 14px 14px 12px;
  }

  .sla-mobile-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
  }

  .sla-mobile-title {
    font-weight: 800;
    font-size: 0.98rem;
    line-height: 1.25;
    color: #0f172a;
  }

  .sla-mobile-sub {
    color: #475569;
    font-size: 0.82rem;
    margin-top: 4px;
  }

  .sla-mobile-chiprow {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
  }

  .sla-mobile-dues {
    margin-top: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .sla-mobile-duebox {
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 10px 10px;
    background: #f1f5f9;
    display: grid;
    gap: 8px;
  }

  .sla-mobile-duebox strong {
    font-size: 0.82rem;
    color: #0f172a;
  }

  .sla-mobile-actions {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* Work Planner: mobile grouped list */
  /* Use the dedicated mobile upcoming list on mobile (cards grouped by date). */
  #view-planner #planner-calendar-shell {
    display: none !important;
  }

  #view-planner #planner-mobile-shell {
    display: block !important;
  }

  #view-planner #planner-list-shell {
    display: none !important;
  }

  #view-planner .planner-view-toggle {
    display: none !important;
  }

  .planner-mobile-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
  }

  .planner-mobile-container {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .planner-mobile-day {
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
    overflow: hidden;
  }

  .planner-mobile-day-head {
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e2e8f0;
  }

  .planner-mobile-day-head strong {
    color: #0f172a;
    font-size: 0.95rem;
  }

  .planner-mobile-day-head span {
    color: #475569;
    font-size: 0.78rem;
    font-weight: 700;
  }

  .planner-mobile-job {
    padding: 12px 16px;
    display: grid;
    gap: 6px;
    border-top: 1px solid #e2e8f0;
  }

  .planner-mobile-job-title {
    color: #0f172a;
    font-weight: 800;
    font-size: 0.92rem;
    line-height: 1.25;
  }

  .planner-mobile-job-meta {
    color: #475569;
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .planner-mobile-job-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
  }

  /* Auth: mobile-friendly sign-in/sign-up layout */
  #auth-shell.auth-shell-visible {
    align-items: flex-start;
    justify-content: center;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    height: 100svh;
    background: #f8fafc;
  }

  #auth-shell .auth-shell-panel {
    width: 100%;
    max-width: 560px;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 0;
  }

  #auth-shell .auth-brand-block {
    display: none;
  }

  #auth-shell .auth-card {
    width: 100%;
    max-width: none;
    padding: 16px !important;
    border-radius: 18px !important;
  }

  #auth-shell .auth-card::before {
    content: none !important;
  }

  #auth-shell .auth-tabs {
    width: 100%;
    gap: 6px;
    position: sticky;
    top: 0;
    z-index: 2;
  }

  #auth-shell .auth-tab {
    flex: 1;
    width: auto;
    min-height: 48px;
    text-align: center;
  }

  #auth-shell .auth-form .form-row {
    flex-direction: column;
  }

  #auth-shell .auth-form .form-group {
    width: 100%;
    min-width: 0;
  }

  #auth-shell .auth-submit-btn,
  #auth-shell .btn {
    width: 100%;
  }

  #auth-shell input,
  #auth-shell select,
  #auth-shell button {
    max-width: 100%;
  }

  #auth-shell .auth-card-footer {
    margin-top: 12px !important;
  }

}

@media (max-width: 520px) {
  /* Jobs & Techs mobile cards */
  .jobs-mobile-grid {
    grid-template-columns: 1fr;
  }

  /* SLA mobile cards */
  .sla-mobile-dues {
    grid-template-columns: 1fr;
  }
}
