/* Eximious Tech ERP — mobile workspace layer
   This file intentionally leaves desktop rules untouched. */

.mobile-brand,
.mobile-bottom-nav,
.mobile-filter-bar,
.mobile-create-grid {
  display: none;
}

.mobile-progress {
  height: 7px;
  margin: -4px 0 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.mobile-progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--production));
}

@media (max-width: 820px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    -webkit-tap-highlight-color: transparent;
  }

  button,
  summary,
  a,
  input,
  select,
  textarea {
    touch-action: manipulation;
  }

  .content {
    width: 100%;
    min-width: 0;
    padding: 22px 16px calc(102px + env(safe-area-inset-bottom));
  }

  .page-head {
    gap: 14px;
    margin-bottom: 18px;
  }

  .page-head > div:first-child,
  .page-head p,
  .card-head > div,
  .record-card-head > div,
  .list-row > div,
  .activity-feed span {
    min-width: 0;
  }

  .page-head h1 {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-size: clamp(26px, 7vw, 32px) !important;
    line-height: 1.08;
  }

  .page-head p {
    max-width: 68ch;
    font-size: 13px;
    line-height: 1.55;
  }

  .breadcrumbs {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
  }

  .breadcrumbs::-webkit-scrollbar,
  .head-actions::-webkit-scrollbar,
  .range-bar::-webkit-scrollbar,
  .saved-view-bar::-webkit-scrollbar {
    display: none;
  }

  .head-actions {
    width: calc(100vw - 32px);
    max-width: 100%;
    padding: 2px 1px 5px;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .head-actions > * {
    flex: 0 0 auto !important;
    scroll-snap-align: start;
  }

  .head-actions .btn {
    min-height: 42px;
    white-space: nowrap;
  }

  .favourite-toggle {
    flex: 0 0 42px !important;
  }

  .card,
  .metric-card,
  .record-card {
    border-radius: 14px;
  }

  .card {
    min-width: 0;
    padding: 16px;
  }

  .card-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .card-head > .btn,
  .card-head > div:last-child:not(:first-child) {
    flex: 0 0 auto;
  }

  .metric-grid,
  .metric-grid-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  .metric-card {
    min-height: 112px;
    padding: 15px;
  }

  .metric-label {
    min-height: 34px;
    font-size: 10px;
    line-height: 1.35;
  }

  .metric-value {
    max-width: 100%;
    margin-top: 5px;
    overflow-wrap: anywhere;
    font-size: clamp(18px, 4.8vw, 25px);
    line-height: 1.08;
  }

  .metric-note {
    line-height: 1.35;
  }

  .dashboard-grid,
  .dashboard-grid-three,
  .detail-grid,
  .report-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .dashboard-widget + .dashboard-widget {
    margin-top: 13px;
  }

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

  .quick-action {
    min-height: 54px;
  }

  .multi-chart {
    min-width: 0;
    padding: 12px 2px 4px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .multi-group {
    flex: 0 0 58px;
  }

  .range-bar,
  .saved-view-bar {
    width: calc(100vw - 32px);
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .range-bar .btn,
  .saved-view-bar > * {
    flex: 0 0 auto;
  }

  .filter-panel {
    padding: 9px !important;
  }

  .mobile-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .mobile-filter-toggle {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 44px;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border: 0;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    text-align: left;
  }

  .mobile-filter-toggle strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-filter-count {
    display: grid;
    min-width: 22px;
    height: 22px;
    margin-left: auto;
    place-items: center;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 10px;
  }

  .filter-chevron {
    color: var(--muted);
    font-size: 18px;
    transition: rotate .18s ease;
  }

  .filters-open .filter-chevron {
    rotate: 180deg;
  }

  .mobile-filter-clear {
    min-height: 44px;
    padding: 8px 10px;
    border: 0;
    background: transparent;
    color: var(--danger);
    font-size: 12px;
    font-weight: 800;
  }

  .filter-panel:not(.filters-open) .filter-content {
    display: none;
  }

  .filter-content {
    padding-top: 12px;
  }

  .filter-content .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px;
    margin-bottom: 5px;
  }

  .filter-panel .field,
  .filter-panel .field:first-child {
    width: auto;
    min-width: 0 !important;
  }

  .filter-panel .field:first-child {
    grid-column: 1 / -1;
  }

  .filter-panel input,
  .filter-panel select {
    min-width: 0;
  }

  .content > .toolbar,
  .report-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  .toolbar .search-box,
  .toolbar select,
  .report-toolbar .field,
  .report-toolbar .btn {
    width: 100%;
    min-width: 0;
  }

  .record-cards {
    gap: 11px;
  }

  .record-card {
    min-width: 0;
    padding: 14px;
    overflow: visible;
  }

  .record-card-head {
    align-items: flex-start;
  }

  .record-card-head strong,
  .record-card-head small,
  .record-card p,
  .record-card dd {
    overflow-wrap: anywhere;
  }

  .record-card-head > .status {
    flex: 0 0 auto;
    max-width: 46%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .record-card dl {
    gap: 8px;
    margin: 12px 0;
  }

  .record-card dl > div {
    min-height: 58px;
    padding: 9px;
  }

  .record-card dd {
    line-height: 1.35;
  }

  .record-card .actions,
  .order-card > .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .record-card .actions > .btn,
  .record-card .actions > details,
  .order-card > .actions > .btn,
  .order-card > .actions > details {
    width: 100%;
    min-width: 0;
  }

  .record-card .actions summary,
  .record-card .actions .btn {
    width: 100%;
    min-height: 42px;
  }

  .action-menu {
    z-index: 3;
  }

  .action-menu > div {
    right: auto;
    left: 0;
    width: min(230px, calc(100vw - 48px));
    max-height: 55dvh;
    overflow-y: auto;
  }

  .audit-device {
    margin: 4px 0 0;
    padding: 9px;
    border-radius: 9px;
    background: var(--surface-2);
    font-size: 11px;
  }

  .table-wrap {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    scrollbar-color: var(--primary) var(--surface-2);
    scrollbar-width: thin;
  }

  .table-wrap:not(.desktop-table) {
    border-radius: 13px;
  }

  .table-wrap:not(.desktop-table) table {
    min-width: 680px;
  }

  .pagination {
    align-items: stretch;
    gap: 10px;
    padding: 4px 0;
    flex-direction: column;
  }

  .pagination > div {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .pagination .btn {
    min-height: 44px;
  }

  .bulk-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .bulk-bar > strong {
    grid-column: 1 / -1;
  }

  .bulk-bar .field,
  .bulk-bar .btn {
    width: 100%;
    min-width: 0;
  }

  .kanban {
    display: flex;
    width: calc(100vw - 16px);
    margin-inline: -8px;
    padding: 0 8px 12px;
    overflow-x: auto;
    scroll-padding-inline: 8px;
    scroll-snap-type: x mandatory;
  }

  .kanban-col {
    flex: 0 0 min(84vw, 330px);
    min-height: 300px;
    scroll-snap-align: start;
  }

  .summary-source,
  .profile-hero,
  .order-detail-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-hero > .btn,
  .order-detail-hero > .btn {
    width: 100%;
  }

  .profile-hero p,
  .order-detail-hero p {
    overflow-wrap: anywhere;
  }

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

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

  .activity-feed > div {
    grid-template-columns: 12px minmax(0, 1fr);
  }

  .activity-feed > div > :last-child:not(:nth-child(2)) {
    grid-column: 2;
    justify-self: start;
  }

  .list-row,
  button.list-row {
    min-width: 0;
  }

  .list-row strong,
  .list-row small {
    overflow-wrap: anywhere;
  }

  .modal {
    position: fixed;
    inset: auto 0 0 !important;
    width: 100vw !important;
    max-width: none;
    max-height: 94dvh;
    margin: 0 !important;
    border-radius: 22px 22px 0 0;
  }

  .modal-inner {
    max-height: 94dvh;
  }

  .modal-head {
    flex: 0 0 auto;
    padding: 16px 16px 13px;
  }

  .modal-head::before {
    position: absolute;
    top: 7px;
    left: 50%;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    content: "";
    translate: -50% 0;
  }

  .modal-head h2 {
    padding-right: 8px;
    overflow-wrap: anywhere;
    font-size: 20px !important;
    line-height: 1.2;
  }

  .modal-head .icon-btn {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
  }

  .modal-body {
    padding: 16px;
    overscroll-behavior: contain;
  }

  .modal-foot {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
  }

  .modal-foot .btn {
    width: 100%;
    min-height: 46px;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 13px;
  }

  .form-grid .span-2,
  .detail-list .span-2 {
    grid-column: auto;
  }

  .field input,
  .field select,
  .field textarea,
  .toolbar input,
  .toolbar select,
  .line-item input,
  .line-item select {
    min-height: 46px;
    font-size: 16px;
  }

  .line-item,
  .invoice-line-item {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
    padding: 12px;
  }

  .line-item > div:first-child {
    grid-column: 1 / -1;
  }

  .line-item > .icon-btn {
    align-self: end;
    justify-self: end;
    width: 44px;
    height: 44px;
  }

  .document-summary {
    padding: 13px;
  }

  .toast-root {
    right: 10px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    left: 10px;
  }

  .toast {
    width: 100%;
    min-width: 0;
  }

  .mobile-bottom-nav {
    position: fixed;
    z-index: 90;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: calc(68px + env(safe-area-inset-bottom));
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    box-shadow: 0 -12px 32px rgba(13, 36, 68, .11);
    backdrop-filter: blur(18px) saturate(1.25);
  }

  .mobile-bottom-nav button {
    position: relative;
    display: grid;
    min-width: 0;
    min-height: 52px;
    place-items: center;
    gap: 1px;
    padding: 3px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
  }

  .mobile-bottom-nav button > span {
    font-size: 20px;
    line-height: 1;
  }

  .mobile-bottom-nav button > small {
    overflow: hidden;
    font-size: 9px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-bottom-nav .mobile-nav-link.active {
    background: var(--blue-soft);
    color: var(--primary);
  }

  .mobile-create-button > span {
    display: grid;
    width: 43px;
    height: 43px;
    margin-top: -22px;
    place-items: center;
    border: 4px solid var(--surface);
    border-radius: 15px;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    box-shadow: 0 8px 20px rgba(23, 105, 224, .28);
    color: #fff;
    font-size: 25px !important;
  }

  .mobile-sheet-intro {
    margin: 0 0 14px;
    color: var(--muted);
  }

  .mobile-create-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .mobile-create-option {
    display: grid;
    min-width: 0;
    min-height: 112px;
    align-content: center;
    justify-items: start;
    gap: 3px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--surface-2);
    color: var(--text);
    text-align: left;
  }

  .mobile-create-option > span {
    display: grid;
    width: 32px;
    height: 32px;
    margin-bottom: 3px;
    place-items: center;
    border-radius: 9px;
    background: var(--blue-soft);
    color: var(--primary);
    font-size: 17px;
  }

  .mobile-create-option small {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.35;
  }

  .mobile-create-option.tone-green > span { background: var(--green-soft); color: var(--success); }
  .mobile-create-option.tone-amber > span { background: var(--amber-soft); color: var(--warning); }
  .mobile-create-option.tone-purple > span { background: var(--purple-soft); color: var(--creative); }
  .mobile-create-option.tone-cyan > span { background: var(--cyan-soft); color: var(--production); }
  .mobile-create-option.tone-red > span { background: var(--red-soft); color: var(--danger); }
}

@media (max-width: 640px) {
  .topbar {
    display: grid !important;
    grid-template-areas:
      "menu brand actions"
      "search search search";
    grid-template-columns: 44px minmax(0, 1fr) auto;
    height: auto !important;
    min-height: calc(112px + env(safe-area-inset-top)) !important;
    padding: calc(8px + env(safe-area-inset-top)) 12px 10px !important;
    gap: 8px 10px !important;
  }

  .menu-toggle {
    grid-area: menu;
    width: 44px;
    height: 44px;
  }

  .mobile-brand {
    display: flex;
    grid-area: brand;
    min-width: 0;
    align-items: center;
    gap: 5px;
    color: var(--text);
    letter-spacing: .05em;
  }

  .mobile-brand strong {
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-brand span {
    padding: 2px 5px;
    border-radius: 5px;
    background: var(--blue-soft);
    color: var(--primary);
    font-size: 8px;
    font-weight: 900;
  }

  .global-search {
    grid-area: search;
    width: 100%;
    max-width: none;
  }

  .global-search input {
    min-height: 44px;
    font-size: 16px !important;
  }

  .top-actions {
    grid-area: actions;
    gap: 6px;
  }

  .top-actions > .icon-btn,
  .profile-summary {
    width: 42px;
    min-width: 42px;
    height: 42px;
  }

  .profile-summary .avatar {
    width: 38px;
    height: 38px;
  }

  .top-menu-panel {
    top: calc(60px + env(safe-area-inset-top));
  }

  .search-results {
    top: calc(108px + env(safe-area-inset-top));
  }

  .content {
    padding-inline: 12px;
  }

  .head-actions,
  .range-bar,
  .saved-view-bar {
    width: calc(100vw - 24px);
  }

  .filter-content .toolbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .filter-panel .field:first-child {
    grid-column: auto;
  }

  .quick-grid-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .bulk-bar {
    grid-template-columns: minmax(0, 1fr);
  }

  .bulk-bar > strong {
    grid-column: auto;
  }

  .section-title {
    align-items: flex-start;
    gap: 5px;
    flex-direction: column;
  }

  .profile-avatar {
    width: 48px;
    height: 48px;
  }
}

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

  .head-actions,
  .range-bar,
  .saved-view-bar {
    width: calc(100vw - 20px);
  }

  .metric-grid,
  .metric-grid-wide {
    gap: 8px;
  }

  .metric-card {
    min-height: 106px;
    padding: 12px;
  }

  .metric-value {
    font-size: clamp(17px, 4.7vw, 21px);
  }

  .record-card dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-card dl > div {
    padding: 8px;
  }

  .mobile-create-grid {
    gap: 8px;
  }

  .mobile-create-option {
    min-height: 106px;
    padding: 11px;
  }
}

@media (max-width: 340px) {
  .metric-grid,
  .metric-grid-wide,
  .profile-metrics,
  .summary-grid,
  .quick-grid-wide {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .mobile-brand {
    display: none;
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 980px) {
  .modal,
  .modal-inner {
    max-height: 100dvh;
  }

  .modal {
    border-radius: 14px 14px 0 0;
  }

  .mobile-bottom-nav {
    min-height: 58px;
    padding-block: 4px;
  }

  .mobile-bottom-nav button {
    min-height: 46px;
  }
}

@media print {
  .mobile-bottom-nav,
  .mobile-filter-bar,
  .mobile-brand {
    display: none !important;
  }
}
