/*
  Gigamach OS adaptive layout layer.
  UI only: do not place business, pricing, numbering, or PDF rules here.
*/

:root {
  --mobile-brand: #b94b24;
  --mobile-ink: #17202a;
  --mobile-muted: #667085;
  --mobile-line: #d7dde5;
  --mobile-surface: #ffffff;
  --mobile-soft: #f5f7fa;
  --minimal-bg: #f4f6f8;
  --minimal-card: #ffffff;
  --minimal-ink: #18202c;
  --minimal-muted: #667085;
  --minimal-line: #d9dee8;
  --minimal-brand: #b94b24;
  --minimal-shadow: 0 12px 28px rgba(24, 32, 44, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--mobile-line);
  border-radius: 999px;
  background: var(--mobile-surface);
  color: var(--mobile-ink);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button-link:hover {
  border-color: #aeb9c8;
  background: var(--mobile-soft);
}

.button-link.primary {
  border-color: #245986;
  background: #245986;
  color: #ffffff;
}

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

:where(button, input, select, textarea) {
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
}

:where(
  .fields,
  .grid,
  .form-grid,
  .search-box,
  .site-field-grid,
  .resource-chip-grid,
  .machine-compact-row,
  .machine-dimension-row,
  .inline-field,
  .source-search
) > * {
  min-width: 0;
}

body.minimal-app-ui {
  background: var(--minimal-bg);
}

html.gigamach-embedded,
body.gigamach-embedded {
  min-height: 100%;
}

body.gigamach-embedded .global-nav,
body.gigamach-embedded .mobile-nav-shell,
body.gigamach-embedded .mobile-app-topbar,
body.gigamach-embedded .mobile-bottom-tabs,
body.gigamach-embedded .mobile-fab,
body.gigamach-embedded .mobile-context-actions,
body.gigamach-embedded .mobile-install-prompt,
body.gigamach-embedded .mobile-stepper {
  display: none !important;
}

body.minimal-app-ui .global-nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 7px max(14px, env(safe-area-inset-right)) 7px max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--minimal-line);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 8px 20px rgba(24, 32, 44, 0.05);
  backdrop-filter: blur(10px);
  overflow-x: auto;
}

body.minimal-app-ui .global-nav a,
body.minimal-app-ui .global-nav button,
body.minimal-app-ui .global-nav summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--minimal-muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

body.minimal-app-ui .global-nav a[aria-current="page"] {
  border-color: rgba(185, 75, 36, 0.22);
  background: rgba(185, 75, 36, 0.09);
  color: var(--minimal-brand);
}

body.minimal-app-ui .global-nav a:hover,
body.minimal-app-ui .global-nav a:focus-visible,
body.minimal-app-ui .global-nav button:hover,
body.minimal-app-ui .global-nav button:focus-visible {
  border-color: var(--minimal-line);
  background: var(--minimal-bg);
  color: var(--minimal-ink);
  outline: none;
}

body.minimal-app-ui .module,
body.minimal-app-ui .module-card,
body.minimal-app-ui .panel,
body.minimal-app-ui .card,
body.minimal-app-ui .sq-panel,
body.minimal-app-ui .workflow-kpi,
body.minimal-app-ui .sq-kpi {
  border-radius: 8px;
}

@media (max-width: 1199px) {
  .page,
  .app {
    max-width: 100% !important;
  }

  .layout,
  .grid,
  .module-grid,
  .quick-grid,
  .dashboard-grid,
  .settings-grid,
  .content-grid {
    grid-template-columns: 1fr !important;
  }

  .topbar,
  header {
    gap: 12px;
  }
}

@media (max-width: 767px) {
  .mobile-only {
    display: flex !important;
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    font-size: 15px;
    overflow-x: clip;
    padding: var(--safe-top) var(--safe-right) calc(76px + var(--safe-bottom)) var(--safe-left);
    background: #eef2f6;
  }

  .page,
  .app,
  .layout,
  .shell,
  .role-shell,
  .container,
  main,
  section,
  article,
  aside {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .page,
  .app {
    padding: 12px !important;
  }

  .app,
  .layout {
    display: block !important;
  }

  .editor,
  .panel,
  .paper-wrap,
  .preview-wrap,
  .table-wrap,
  .machine-table-wrap,
  .history-results {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .editor {
    padding: 12px !important;
  }

  .paper,
  .preview,
  .doc-paper {
    max-width: 100% !important;
    overflow-x: auto;
  }

  img,
  video,
  canvas,
  svg {
    max-width: 100%;
    height: auto;
  }

  .global-nav {
    display: none !important;
  }

  .mobile-nav-shell {
    display: block !important;
    height: 0;
    overflow: visible;
    pointer-events: none;
  }

  .mobile-nav-shell > .mobile-nav-toggle {
    display: none !important;
  }

  .mobile-app-topbar {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 2000;
    margin: calc(-1 * var(--safe-top)) calc(-1 * var(--safe-right)) 10px calc(-1 * var(--safe-left));
    padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 8px calc(10px + var(--safe-left));
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid var(--mobile-line);
    box-shadow: 0 8px 18px rgba(24, 32, 44, 0.06);
    backdrop-filter: blur(10px);
    pointer-events: auto;
    isolation: isolate;
  }

  .mobile-app-icon-button,
  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    width: 44px;
    border: 1px solid var(--mobile-line);
    border-radius: 999px;
    background: var(--mobile-surface);
    color: var(--mobile-ink);
    font-weight: 800;
    cursor: pointer;
    position: relative;
    z-index: 2002;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-app-title {
    min-width: 0;
    text-align: left;
  }

  .mobile-app-title strong,
  .mobile-app-title span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-app-title strong {
    color: var(--mobile-ink);
    font-size: 15px;
  }

  .mobile-app-title span {
    color: var(--mobile-muted);
    font-size: 11px;
  }

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

  .mobile-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2001;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(15, 23, 42, 0.28);
    backdrop-filter: blur(2px);
  }

  .mobile-nav-panel {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 2003;
    width: min(320px, 86vw);
    display: grid;
    align-content: start;
    gap: 5px;
    padding: calc(14px + var(--safe-top)) 12px calc(18px + var(--safe-bottom));
    border: 0;
    border-right: 1px solid var(--mobile-line);
    border-radius: 0 18px 18px 0;
    background: var(--mobile-surface);
    box-shadow: 20px 0 44px rgba(15, 23, 42, 0.16);
    overflow-y: auto;
    visibility: hidden;
    opacity: 0;
    transform: translateX(-102%);
    transition: transform 180ms ease, opacity 180ms ease, visibility 180ms ease;
    pointer-events: none;
  }

  .mobile-more-panel {
    display: none;
    position: fixed;
    left: auto;
    right: 12px;
    top: calc(62px + var(--safe-top));
    z-index: 2003;
    width: min(270px, calc(100vw - 24px));
    padding: 6px;
    border: 1px solid var(--mobile-line);
    border-radius: 12px;
    background: var(--mobile-surface);
    box-shadow: 0 14px 32px rgba(16, 24, 40, 0.16);
  }

  .mobile-nav-shell.is-nav-open .mobile-nav-backdrop {
    display: block;
    pointer-events: auto;
  }

  .mobile-nav-shell.is-nav-open .mobile-nav-panel {
    visibility: visible;
    opacity: 1;
    transform: translateX(0);
    gap: 6px;
    pointer-events: auto;
  }

  .mobile-nav-shell.is-more-open .mobile-more-panel {
    display: grid;
    gap: 6px;
    pointer-events: auto;
  }

  .mobile-drawer-header {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 36px;
    align-items: center;
    gap: 9px;
    min-height: 54px;
    margin-bottom: 7px;
    padding: 4px 2px 11px;
    border-bottom: 1px solid var(--mobile-line);
  }

  .mobile-drawer-header img {
    width: 38px;
    height: 38px;
    display: block;
    object-fit: contain;
  }

  .mobile-drawer-header div {
    min-width: 0;
    display: grid;
    gap: 1px;
  }

  .mobile-drawer-header strong,
  .mobile-drawer-header span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-drawer-header strong {
    color: var(--mobile-ink);
    font-size: 14px;
  }

  .mobile-drawer-header span {
    color: var(--mobile-muted);
    font-size: 10px;
    text-transform: capitalize;
  }

  .mobile-nav-panel .mobile-drawer-close {
    width: 36px;
    min-height: 36px;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50% !important;
    background: var(--mobile-soft);
    font-size: 21px !important;
  }

  .mobile-bottom-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 7px calc(8px + var(--safe-right)) calc(7px + var(--safe-bottom)) calc(8px + var(--safe-left));
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid var(--mobile-line);
    box-shadow: 0 -12px 30px rgba(16, 24, 40, 0.14);
    backdrop-filter: blur(10px);
  }

  .mobile-context-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(64px + var(--safe-bottom));
    z-index: 1080;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px calc(10px + var(--safe-right)) 8px calc(10px + var(--safe-left));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--mobile-line);
    box-shadow: 0 -8px 22px rgba(16, 24, 40, 0.1);
  }

  .mobile-context-actions button {
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--mobile-line);
    background: var(--mobile-surface);
    color: var(--mobile-ink);
    font-weight: 900;
  }

  .mobile-context-actions button.mobile-primary {
    border-color: var(--mobile-brand);
    background: var(--mobile-brand);
    color: #ffffff;
  }

  .mobile-bottom-tabs a,
  .mobile-bottom-tabs button {
    display: grid;
    grid-template-rows: 12px auto;
    gap: 3px;
    place-items: center;
    min-height: 48px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--mobile-muted);
    font-size: 11px !important;
    font-weight: 800;
    text-decoration: none;
  }

  .mobile-bottom-tabs a[aria-current="page"] {
    color: var(--mobile-brand);
    background: rgba(185, 75, 36, 0.1);
  }

  .mobile-tab-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: transparent;
  }

  .mobile-bottom-tabs a[aria-current="page"] .mobile-tab-dot {
    background: currentColor;
  }

  .mobile-fab {
    position: fixed;
    right: calc(16px + var(--safe-right));
    bottom: calc(136px + var(--safe-bottom));
    z-index: 1090;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 54px;
    min-width: 54px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: var(--mobile-brand);
    color: #ffffff;
    box-shadow: 0 14px 30px rgba(185, 75, 36, 0.34);
    font-weight: 900;
  }

  .mobile-install-prompt {
    display: grid;
    gap: 8px;
    margin: 8px 0 12px;
    padding: 10px;
    border: 1px solid rgba(185, 75, 36, 0.25);
    border-radius: 8px;
    background: #fff7ed;
    color: #7c2d12;
    font-size: 13px;
  }

  .mobile-install-prompt button {
    width: 100%;
    border-color: rgba(185, 75, 36, 0.25);
    color: #7c2d12;
    background: #ffffff;
  }

  .mobile-stepper {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow-x: visible;
    padding: 2px 0 10px;
    margin-bottom: 8px;
  }

  .mobile-stepper button {
    flex: 0 0 auto;
    min-height: 38px !important;
    border-radius: 999px !important;
    border: 1px solid var(--mobile-line);
    background: var(--mobile-surface);
    color: var(--mobile-ink);
    font-size: 12px !important;
    font-weight: 800;
    white-space: nowrap;
  }

  body.mobile-quotation-preview-hidden .preview-wrap {
    display: none !important;
  }

  body.mobile-quotation-preview-visible .editor {
    display: none !important;
  }

  .mobile-nav-panel a,
  .mobile-nav-panel button,
  .mobile-nav-panel summary,
  .mobile-more-panel a,
  .mobile-more-panel button {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--mobile-line);
    border-radius: 8px !important;
    background: var(--mobile-surface);
    color: var(--mobile-ink);
    justify-content: flex-start;
    padding: 8px 10px;
    font-weight: 800;
    font-size: 13px !important;
    text-align: left;
    text-decoration: none;
  }

  .mobile-more-panel button {
    cursor: pointer;
  }

  .mobile-nav-panel .auth-user-menu {
    width: 100%;
  }

  .mobile-nav-panel .auth-user-menu-list {
    position: static;
    box-shadow: none;
    margin-top: 6px;
  }

  .mobile-panel-title {
    padding: 4px 5px 1px;
    color: var(--mobile-muted);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
  }

  .mobile-panel-user {
    display: grid;
    gap: 2px;
    padding: 8px 10px;
    border: 1px solid rgba(185, 75, 36, 0.2);
    border-radius: 8px;
    background: rgba(185, 75, 36, 0.08);
  }

  .mobile-panel-user strong {
    color: var(--mobile-ink);
    font-size: 12px;
  }

  .mobile-panel-user span {
    color: var(--mobile-muted);
    font-size: 10px;
    font-weight: 800;
  }

  .topbar,
  header,
  .brand {
    display: grid !important;
    grid-template-columns: 1fr !important;
    align-items: start !important;
  }

  h1 {
    font-size: clamp(22px, 7vw, 30px) !important;
    line-height: 1.12 !important;
  }

  h2 {
    font-size: 18px !important;
  }

  h3 {
    font-size: 16px !important;
  }

  button,
  .btn,
  .button,
  .module,
  .card,
  .module-card {
    font-size: 15px !important;
  }

  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  button,
  .btn,
  input,
  select {
    min-height: 44px !important;
  }

  textarea {
    min-height: 96px;
  }

  input,
  select,
  textarea {
    width: 100% !important;
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 20px !important;
    min-width: 20px !important;
    height: 20px !important;
    min-height: 20px !important;
    flex: 0 0 20px;
    margin: 0;
    accent-color: var(--mobile-brand);
  }

  .tick-row input[type="checkbox"],
  .tick-row input[type="radio"],
  label input[type="checkbox"],
  label input[type="radio"] {
    align-self: center;
  }

  .two,
  .three,
  .fields,
  .search-box,
  .form-grid,
  .section-body,
  .item-panel,
  .editor-actions,
  .history-actions,
  .toolbar {
    grid-template-columns: 1fr !important;
    flex-wrap: wrap;
  }

  .card > .actions,
  .job-card > .actions,
  .opp-card .actions,
  .photo-card .actions,
  .result-card .actions,
  .simple-sr-card .advanced-card-actions .actions {
    display: flex !important;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px !important;
  }

  .toolbar {
    position: sticky;
    bottom: calc(68px + var(--safe-bottom));
    z-index: 900;
    margin: 0 -12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--mobile-line);
    box-shadow: 0 -12px 28px rgba(16, 24, 40, 0.12);
    display: none !important;
  }

  .toolbar .btn {
    width: 100%;
  }

  .card > .actions button,
  .card > .actions .button-link,
  .job-card > .actions button,
  .job-card > .actions .button-link,
  .opp-card .actions button,
  .opp-card .actions .button-link,
  .photo-card .actions button,
  .photo-card .actions .button-link,
  .result-card .actions button,
  .result-card .actions .button-link,
  .simple-sr-card .advanced-card-actions .actions button,
  .simple-sr-card .advanced-card-actions .actions .button-link {
    width: auto !important;
    flex: 0 0 auto;
    min-height: 34px !important;
    border-radius: 999px !important;
    padding: 7px 11px !important;
    font-size: 12px !important;
    line-height: 1 !important;
    white-space: nowrap;
  }

  .card > .actions .primary,
  .card > .actions button.primary,
  .card > .actions .button-link.primary,
  .job-card > .actions .primary,
  .job-card > .actions button.primary,
  .job-card > .actions .button-link.primary,
  .opp-card .actions .primary,
  .opp-card .actions button.primary,
  .opp-card .actions .button-link.primary,
  .photo-card .actions .primary,
  .photo-card .actions button.primary,
  .photo-card .actions .button-link.primary,
  .result-card .actions .primary,
  .result-card .actions button.primary,
  .result-card .actions .button-link.primary,
  .simple-sr-card .advanced-card-actions .actions .primary,
  .simple-sr-card .advanced-card-actions .actions button.primary,
  .simple-sr-card .advanced-card-actions .actions .button-link.primary {
    flex: 1 1 auto;
    min-width: 112px;
  }

  .toolbar .btn:not(#saveData):not(#printPdf):not([data-mos-print]):not([data-mos-save]) {
    position: static;
  }

  details > summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    cursor: pointer;
  }

  table {
    width: 100% !important;
    max-width: 100% !important;
  }

  .table-wrap,
  .machine-table-wrap,
  .history-results,
  .cards {
    overflow-x: visible !important;
  }

  .machine-table thead,
  .data-table thead,
  .items-table thead,
  .mobile-card-table thead {
    display: none;
  }

  .machine-table,
  .machine-table tbody,
  .machine-table tr,
  .machine-table td,
  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td,
  .mobile-card-table,
  .mobile-card-table tbody,
  .mobile-card-table tr,
  .mobile-card-table td {
    display: block;
    width: 100% !important;
  }

  .machine-table tr,
  .data-table tr,
  .mobile-card-table tr,
  .item-panel,
  .card,
  .module-card,
  .result-card {
    margin-bottom: 10px;
    border: 1px solid var(--mobile-line) !important;
    border-radius: 8px !important;
    background: var(--mobile-surface) !important;
    padding: 10px !important;
  }

  .machine-table td,
  .data-table td,
  .mobile-card-table td {
    border: 0 !important;
    padding: 5px 0 !important;
  }

  .mobile-card-table {
    min-width: 0 !important;
    table-layout: auto !important;
  }

  .mobile-card-table td {
    display: grid;
    grid-template-columns: minmax(96px, .34fr) minmax(0, 1fr);
    align-items: start;
    gap: 8px;
    overflow-wrap: anywhere;
  }

  .mobile-card-table td::before {
    content: attr(data-label);
    color: var(--mobile-muted);
    font-size: 11px;
    font-weight: 800;
  }

  .mobile-card-table td[colspan] {
    display: block;
  }

  .mobile-card-table td[colspan]::before {
    content: none;
  }

  .cards,
  .modules,
  .module-grid,
  .results {
    grid-template-columns: 1fr !important;
  }

  .badge,
  .count {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    margin: 2px;
  }

  .mobile-dashboard:not([hidden]) {
    display: grid !important;
    gap: 12px;
    margin: 12px 0;
  }

  .mobile-dashboard[hidden] {
    display: none !important;
  }

  .mobile-dashboard-card {
    border: 1px solid var(--mobile-line);
    border-radius: 8px;
    background: var(--mobile-surface);
    padding: 14px;
    box-shadow: 0 8px 22px rgba(24, 32, 44, 0.06);
  }

  .mobile-dashboard-card h2 {
    margin: 0 0 8px;
  }

  .mobile-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow-x: visible;
    padding-bottom: 4px;
  }

  .mobile-chip-row a,
  .mobile-chip-row button,
  .mobile-chip-row select {
    flex: 0 0 auto;
    min-height: 44px;
    border-radius: 999px !important;
    white-space: nowrap;
  }

  .mobile-dashboard .module {
    min-height: 54px !important;
    padding: 12px 14px !important;
    border-radius: 8px !important;
    box-shadow: none !important;
  }

  body.minimal-app-ui .home-hero,
  body.minimal-app-ui .business-note,
  body.minimal-app-ui [data-owner-workflow-dashboard],
  body.minimal-app-ui .admin-tools {
    display: none !important;
  }

  [data-site-lifting-filter] {
    border-radius: 999px !important;
  }

  .preview-wrap,
  .paper-wrap {
    margin-top: 12px !important;
  }

  .intro {
    margin-bottom: 12px;
  }
}

@media (min-width: 768px) {
  .mobile-nav-shell,
  .mobile-dashboard,
  .mobile-only,
  .mobile-app-topbar,
  .mobile-bottom-tabs,
  .mobile-fab,
  .mobile-context-actions,
  .mobile-install-prompt,
  .mobile-stepper {
    display: none !important;
  }
}

@media print {
  .mobile-nav-shell,
  .mobile-dashboard,
  .mobile-app-topbar,
  .mobile-bottom-tabs,
  .mobile-fab,
  .mobile-context-actions,
  .mobile-install-prompt,
  .mobile-stepper {
    display: none !important;
  }
}
