/* Phone-first layout for the shared Urban Frill CRM. */
@media (max-width: 760px) {
  html,
  body,
  #app {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
  }

  #app:has(> .nav) {
    padding-top: var(--app-header-height, 68px) !important;
    padding-bottom: calc(var(--app-nav-height, 120px) + 8px) !important;
  }

  html {
    scroll-padding-top: var(--app-header-height, 68px);
    scroll-padding-bottom: var(--app-nav-height, 120px);
  }

  #app > .top,
  #app > .top:not(:has(.top-actions)) {
    position: fixed !important;
    display: flex !important;
    inset: 0 0 auto !important;
    width: 100% !important;
    min-height: 62px !important;
    padding: 8px 12px !important;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: #fffdfb;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 2px 10px #342b2710;
    z-index: 30 !important;
  }

  #app > .top .brand {
    flex: 1 1 auto;
    min-width: 0;
    gap: 8px;
  }

  #app > .top .logo {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 12px;
    font-size: 18px;
  }

  #app > .top h1 {
    overflow: hidden;
    font-size: 15px;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #app > .top .subnav {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
  }

  .backup-copy {
    display: none !important;
  }

  #app > .top .top-actions {
    flex: 0 1 auto;
    min-width: 0;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  #app > .top .top-actions button {
    min-height: 38px;
    padding: 7px 8px;
    font-size: 11px;
    line-height: 1.15;
  }

  #app > .nav {
    position: fixed !important;
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 5px 5px calc(5px + env(safe-area-inset-bottom)) !important;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    grid-auto-rows: minmax(48px, auto);
    align-content: end;
    gap: 3px;
    overflow: hidden !important;
    background: #fffdfb;
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -5px 18px #342b2710;
    z-index: 40 !important;
  }

  #app > .nav > button {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 48px;
    max-width: 100%;
    padding: 4px 2px !important;
    display: flex !important;
    flex: initial !important;
    flex-direction: column !important;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 9px;
    background: transparent;
    color: #59483f;
    font-size: 10px;
    line-height: 1.1;
    text-align: center;
    white-space: normal;
  }

  #app > .nav > button.active {
    background: var(--lime);
    color: #8f4b38;
  }

  #app > .nav .nav-icon,
  #app > .nav .nav-icon svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
  }

  #app > .nav .nav-label {
    display: block;
    max-width: 100%;
    font-size: 10px;
    line-height: 1.1;
    text-align: center;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  #app > .shell {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 12px 12px 16px !important;
  }

  #content,
  #content > *,
  .panel,
  .panel-head,
  .measurement-project,
  .measurement-project-content,
  .measurement-project .scroll,
  .fields,
  .fields > * {
    min-width: 0;
    max-width: 100%;
  }

  .hero {
    padding: 17px;
    border-radius: 14px;
  }

  .hero h2 {
    font-size: 21px;
    line-height: 1.2;
  }

  .hero p,
  .hint {
    overflow-wrap: anywhere;
  }

  .stats,
  .sales-stats,
  .labour-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
    margin: 10px 0 14px;
  }

  .stat,
  .sales-stats .stat {
    min-width: 0;
    min-height: 0;
    padding: 12px;
    overflow-wrap: anywhere;
  }

  .stat b {
    font-size: 19px;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .stat span,
  .stat small {
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  .dashboard-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 11px;
    margin-top: 11px;
  }

  .dashboard-split > .panel {
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    display: block;
  }

  .dashboard-split .scroll {
    max-height: none;
    overflow: visible !important;
  }

  .panel {
    width: 100%;
    border-radius: 13px;
  }

  .panel-head {
    padding: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .panel-head h3 {
    flex: 1 1 100%;
    font-size: 16px;
    line-height: 1.25;
  }

  .tab-search {
    order: 3;
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    gap: 7px;
  }

  .tab-search input,
  .tab-search select {
    width: 100%;
    min-width: 0;
    font-size: 16px;
  }

  .panel > .scroll,
  .measurement-project .scroll {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: visible !important;
  }

  .panel .scroll > table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    max-width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
  }

  .panel .scroll > table > thead {
    display: none !important;
  }

  .panel .scroll > table > tbody {
    display: block;
    width: 100%;
  }

  .panel .scroll > table > tbody > tr {
    display: block;
    width: auto;
    min-width: 0;
    margin: 8px;
    padding: 7px 10px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 11px;
    box-shadow: 0 2px 8px #342b2708;
  }

  .panel .scroll > table > tbody > tr > td {
    display: grid;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    align-items: start;
    gap: 7px;
    width: 100%;
    min-width: 0;
    padding: 7px 0;
    border: 0;
    font-size: 14px;
    line-height: 1.35;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .panel .scroll > table > tbody > tr > td::before {
    content: attr(data-mobile-label) !important;
    display: block;
    min-width: 0;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .035em;
    line-height: 1.35;
    text-transform: uppercase;
    overflow-wrap: anywhere;
  }

  .panel .scroll > table > tbody > tr > td[colspan] {
    display: block;
    padding: 18px 8px;
  }

  .panel .scroll > table > tbody > tr > td[colspan]::before {
    display: none;
  }

  .panel .scroll > table > tbody > tr > td:last-child {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding-top: 9px;
    border-top: 1px solid #f0e8e1;
  }

  .panel .scroll > table > tbody > tr > td:last-child::before {
    flex: 0 0 100%;
  }

  .panel .scroll > table > tbody > tr > td button {
    min-height: 40px;
    max-width: 100%;
    white-space: normal;
  }

  .panel .scroll > table > tbody > tr > td.empty {
    display: block;
    text-align: center;
  }

  .panel .scroll > table > tbody > tr > td.empty::before {
    display: none;
  }

  .sales-register {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed;
  }

  .panel .scroll:has(> .sales-register) {
    overflow-x: hidden !important;
  }

  .panel .scroll > .sales-register > tbody > tr > td:last-child {
    display: block !important;
  }

  .panel .scroll > .sales-register > tbody > tr > td:last-child::before {
    display: block;
    margin-bottom: 6px;
  }

  .sale-actions,
  .quote-actions {
    max-width: 100%;
    flex-wrap: wrap;
    white-space: normal;
  }

  .sale-actions button,
  .quote-actions button {
    min-height: 40px;
    white-space: normal;
  }

  .measurement-project > summary {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 7px;
    padding: 13px;
  }

  .measurement-project > summary > span:first-of-type {
    flex: 1 1 calc(100% - 22px);
    min-width: 0;
  }

  .measurement-project > summary > .badge {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .measurement-project-content {
    padding: 8px 9px 12px;
  }

  .measurement-project-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
    padding: 8px 2px;
  }

  .measurement-project-actions > div:first-child {
    width: 100%;
    min-width: 0;
  }

  .measurement-project-actions > div:last-child {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
  }

  .measurement-project-actions > div:last-child button {
    flex: 1 1 130px;
    min-height: 42px;
    white-space: normal;
  }

  .fabric-grid {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100%;
    table-layout: fixed !important;
  }

  .fabric-grid > thead {
    display: none !important;
  }

  .fabric-grid > tbody {
    display: block;
    width: 100%;
  }

  .fabric-grid > tbody > tr {
    display: block;
    width: auto;
    margin: 8px 2px !important;
    padding: 8px 10px !important;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
  }

  .fabric-grid > tbody > tr > td {
    display: grid !important;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr) !important;
    gap: 7px !important;
    align-items: center;
    width: 100%;
    min-width: 0;
    padding: 6px 0 !important;
    border: 0;
    font-size: 13px;
  }

  .fabric-grid > tbody > tr > td::before {
    content: attr(data-mobile-label) !important;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.3;
    text-transform: uppercase;
  }

  .fabric-grid input,
  .fabric-grid select,
  .fabric-grid td:first-child input,
  .fabric-grid [data-field="fabric_code"] {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 42px;
    padding: 8px !important;
    font-size: 16px !important;
  }

  .fabric-grid [data-field="fabric_code"] {
    display: none;
  }

  .fabric-grid > tbody > tr > td:last-child {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
  }

  .fabric-grid > tbody > tr > td:last-child::before {
    flex: 0 0 100%;
  }

  .fabric-grid td:last-child button {
    min-height: 40px;
    margin: 0 !important;
  }

  .ordered-check {
    flex-wrap: wrap;
    white-space: normal;
  }

  .ordered-check input,
  input[type="checkbox"] {
    width: auto !important;
    min-width: 20px !important;
    min-height: 20px !important;
    flex: 0 0 auto;
  }

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

  .fields .wide {
    grid-column: auto;
  }

  input,
  select,
  textarea {
    min-width: 0;
    min-height: 44px;
    font-size: 16px;
  }

  textarea {
    min-height: 90px;
  }

  button,
  .icon-action {
    min-height: 42px;
    touch-action: manipulation;
  }

  .icon-action {
    width: 40px;
    height: 40px;
  }

  .modal,
  .deal-confirm {
    padding: 0;
    align-items: end;
  }

  .dialog,
  .deal-confirm-card {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    padding: 16px;
    border-radius: 16px 16px 0 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .quote-dialog {
    width: 100%;
    max-width: 100%;
    padding: 0;
  }

  .quote-toolbar {
    position: sticky;
    top: 0;
    padding: 11px 12px;
    flex-wrap: wrap;
    gap: 8px;
    z-index: 4;
  }

  .quote-toolbar > div,
  .quote-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .quote-toolbar button {
    min-height: 40px;
    padding: 7px 9px;
    font-size: 12px;
  }

  .quote-body {
    padding: 12px;
  }

  .quote-section-head {
    align-items: stretch;
    flex-wrap: wrap;
    gap: 8px;
  }

  .quote-section-head .title {
    flex: 1 1 100%;
    min-width: 0;
  }

  .quote-section-head > div:not(.title) {
    flex: 1 1 100px;
    width: auto !important;
    min-width: 0;
  }

  .quote-section-head button {
    flex: 1 1 100%;
  }

  .quote-lines {
    width: 100%;
    min-width: 0;
    overflow: visible !important;
  }

  .quote-lines table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    max-width: 100%;
  }

  .quote-lines thead {
    display: none !important;
  }

  .quote-lines tbody {
    display: block;
    width: 100%;
  }

  .quote-lines tr {
    display: block;
    width: auto;
    min-width: 0;
    margin: 8px 0;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
  }

  .quote-lines td {
    display: grid;
    grid-template-columns: minmax(74px, 30%) minmax(0, 1fr);
    align-items: center;
    gap: 7px;
    padding: 6px 0;
    border: 0;
    overflow-wrap: anywhere;
  }

  .quote-lines td::before {
    content: attr(data-mobile-label) !important;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.3;
    text-transform: uppercase;
  }

  .quote-lines td:last-child {
    display: flex;
    justify-content: flex-start;
  }

  .quote-lines input,
  .quote-lines .desc {
    width: 100%;
    min-width: 0 !important;
  }

  .quote-lines input[type="checkbox"] {
    justify-self: start;
  }

  .quote-summary {
    width: 100%;
    max-width: 100%;
  }

  .quote-summary > div {
    gap: 10px;
    overflow-wrap: anywhere;
  }

  .quote-summary > div > b {
    text-align: right;
  }

  .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 7px;
    padding: 10px;
  }

  .toast {
    right: 12px;
    bottom: calc(var(--app-nav-height, 120px) + 10px);
    left: 12px;
    width: auto;
    text-align: center;
    z-index: 50;
  }

  .quote-preview {
    width: 100%;
    min-width: 0 !important;
    table-layout: fixed;
  }
}

@media (max-width: 359px) {
  #app > .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  #app > .nav .nav-label {
    font-size: 9px;
  }

  .stats,
  .sales-stats,
  .labour-stats {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
