/* Phase Z13.1 — real iPhone Safari polish */

:root {
  --mobile-nav-bar: 58px;
  --mobile-nav-safe: env(safe-area-inset-bottom, 0px);
  --mobile-nav-total: calc(var(--mobile-nav-bar) + var(--mobile-nav-safe));
  --mobile-content-pad: calc(var(--mobile-nav-total) + 10px);
}

@media (max-width: 768px) {
  main {
    padding: 0 10px var(--mobile-content-pad) !important;
  }

  /* Compact header */
  .topbar {
    padding: 6px 10px 4px !important;
    gap: 6px !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
  }

  .menu-toggle {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    padding: 8px !important;
    border-radius: 10px !important;
    flex-shrink: 0;
  }

  .page-title {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  .page-title h2 {
    font-size: 17px !important;
    line-height: 1.25 !important;
    margin: 0 !important;
  }

  .page-title p {
    display: none !important;
  }

  #data-freshness {
    display: block !important;
    font-size: 11px !important;
    color: var(--muted) !important;
    margin-top: 2px !important;
    line-height: 1.3 !important;
  }

  .topbar-meta {
    display: none !important;
  }

  /* Bottom navigation — equal 5-column geometry */
  .mobile-nav {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    align-items: end !important;
    gap: 0 !important;
    padding: 6px 4px var(--mobile-nav-safe) !important;
    min-height: var(--mobile-nav-total) !important;
    height: auto !important;
    box-sizing: border-box !important;
    background: #1e1433 !important;
  }

  .mobile-nav button {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 3px !important;
    min-height: 44px !important;
    height: auto !important;
    padding: 0 2px 4px !important;
    margin: 0 !important;
    font-size: 10px !important;
    font-weight: 600 !important;
    line-height: 1.1 !important;
    color: rgba(245, 243, 255, 0.68) !important;
    position: relative !important;
    top: 0 !important;
    white-space: nowrap !important;
  }

  .mobile-nav button svg {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0;
  }

  .mobile-nav button.active {
    color: #fff !important;
  }

  .mobile-nav button.active svg {
    color: #c4b5fd;
  }

  .mobile-nav .nav-add {
    justify-content: flex-end !important;
    padding-bottom: 2px !important;
  }

  .mobile-nav .nav-add .nav-add-fab {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(160deg, #7c3aed, #5b21b6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(91, 33, 182, 0.38);
    border: 2px solid #1e1433;
    margin-bottom: 10px;
    transform: translateY(-10px);
    flex-shrink: 0;
  }

  .mobile-nav .nav-add .nav-add-fab svg {
    width: 22px !important;
    height: 22px !important;
  }

  .mobile-nav .nav-add > span:not(.nav-add-fab) {
    font-size: 10px !important;
    margin-top: 0 !important;
    transform: translateY(-8px);
  }

  .mobile-nav .nav-badge {
    top: 0 !important;
    right: calc(50% - 20px) !important;
  }

  /* Search — single field + filter */
  .filter-panel {
    padding: 8px 10px !important;
    margin-bottom: 6px !important;
    border-radius: 12px !important;
  }

  .filter-hint-bar {
    display: none !important;
  }

  .sheet-search-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
  }

  .sheet-search-fields {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    display: block !important;
  }

  .search-field-label {
    display: none !important;
  }

  .search-loc-wrap {
    display: none !important;
  }

  .sheet-search-row .smart-search {
    width: 100% !important;
    padding: 10px 12px !important;
    font-size: 16px !important;
    border-radius: 10px !important;
    min-height: 44px !important;
  }

  .sheet-search-actions {
    flex: 0 0 auto !important;
    width: auto !important;
    display: flex !important;
    gap: 6px !important;
  }

  .sheet-search-actions #apply-filter-btn,
  .sheet-search-actions #reset-filter {
    display: none !important;
  }

  .sheet-search-actions #toggle-filters {
    min-height: 44px !important;
    min-width: 72px !important;
    padding: 8px 12px !important;
    flex: 0 0 auto !important;
    white-space: nowrap;
  }

  /* Sort + pagination compact */
  .status-bar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
    padding: 4px 2px 8px !important;
    flex-wrap: nowrap !important;
  }

  .status-bar .result-count {
    font-size: 13px !important;
    font-weight: 600 !important;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .status-bar .sort-wrap {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    margin-left: 0 !important;
    justify-content: flex-end !important;
    gap: 6px !important;
  }

  .sort-label-desktop {
    display: none !important;
  }

  .status-bar .sort-wrap select {
    min-width: 0 !important;
    max-width: 140px !important;
    flex: 1 1 auto !important;
    min-height: 36px !important;
    padding: 6px 8px !important;
    font-size: 12px !important;
  }

  .prop-page-compact-wrap {
    display: flex !important;
    align-items: center !important;
    gap: 2px !important;
    flex: 0 0 auto;
  }

  .prop-page-btn {
    appearance: none;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
  }

  .prop-page-btn:disabled {
    opacity: 0.35;
    cursor: default;
  }

  .prop-page-compact {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    min-width: 42px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  /* Hide desktop table header */
  .prop-list-head,
  .prop-list-head-desktop {
    display: none !important;
  }

  .scroll {
    max-height: none !important;
  }

  .props-table-scroll {
    overflow: visible !important;
  }

  /* Property cards — mobile-native */
  .prop-sheet-row {
    display: grid !important;
    grid-template-columns: 92px minmax(0, 1fr) !important;
    grid-template-rows: auto !important;
    gap: 10px !important;
    padding: 10px 10px 10px !important;
    margin-bottom: 8px !important;
    border-radius: 12px !important;
    border: 1px solid var(--line) !important;
    background: var(--surface) !important;
    box-shadow: 0 1px 4px rgba(46, 16, 101, 0.05) !important;
    cursor: pointer;
  }

  .prop-sheet-thumb {
    grid-row: 1 / span 4;
    width: 92px !important;
    height: 92px !important;
    border-radius: 10px;
    overflow: hidden;
  }

  .prop-thumb,
  .prop-thumb-ph {
    width: 100% !important;
    height: 100% !important;
    border-radius: 10px;
  }

  .prop-thumb-ph {
    font-size: 9px !important;
    color: #a1a1aa !important;
    background: #f4f4f5 !important;
    border: 1px dashed #e4e4e7 !important;
  }

  .prop-sheet-side-desktop {
    display: none !important;
  }

  .prop-sheet-meta-desktop {
    display: none !important;
  }

  .prop-sheet-top {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 4px 6px !important;
    margin-bottom: 2px !important;
  }

  .prop-sheet-top .date {
    display: none !important;
  }

  .prop-sheet-top .code {
    font-size: 13px !important;
    font-weight: 700 !important;
    color: var(--accent) !important;
  }

  .prop-origin-sub {
    font-size: 10px !important;
    opacity: 0.7;
  }

  .prop-date-sub {
    font-size: 10px !important;
    color: var(--muted) !important;
    margin-left: auto;
  }

  .offer-badge {
    font-size: 10px !important;
    font-weight: 700 !important;
    padding: 2px 7px !important;
    border-radius: 999px !important;
    line-height: 1.3;
  }

  .offer-rent { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
  .offer-sale { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
  .offer-both { background: var(--accent-soft); color: #5b21b6; border: 1px solid var(--accent-border); }

  .prop-sheet-project {
    font-size: 15px !important;
    font-weight: 700 !important;
    line-height: 1.3 !important;
    margin: 0 0 4px !important;
    color: var(--ink) !important;
  }

  .prop-sheet-price-inline {
    display: block !important;
    margin: 2px 0 4px !important;
  }

  .prop-sheet-price-inline .price-stack {
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
    align-items: flex-start !important;
  }

  .prop-sheet-price-inline .price-rent,
  .prop-sheet-price-inline .price-sale {
    font-size: 16px !important;
    font-weight: 700 !important;
    line-height: 1.2;
  }

  .prop-sheet-price-inline .price-rent {
    color: var(--accent) !important;
  }

  .prop-sheet-price-inline .price-sale {
    color: #1e293b !important;
  }

  .prop-sheet-price-inline .price-lbl {
    font-size: 11px;
    font-weight: 600;
    margin-right: 2px;
    opacity: 0.85;
  }

  .prop-sheet-price-inline .price-unit {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.75;
  }

  .prop-sheet-facts,
  .prop-sheet-loc {
    font-size: 12px !important;
    line-height: 1.35 !important;
    color: #52525b !important;
    margin-bottom: 2px !important;
  }

  .prop-sheet-loc {
    color: var(--accent) !important;
    font-weight: 500;
  }

  .prop-sheet-notes {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    max-height: 4.5em !important;
    overflow: hidden !important;
    font-size: 12px !important;
    margin-top: 6px !important;
    margin-bottom: 4px !important;
    padding: 6px 8px !important;
    border-radius: 8px !important;
    background: #f4f0fa !important;
    border: 1px solid #e8e2f1 !important;
    color: #3c3548 !important;
    line-height: 1.4 !important;
    -webkit-line-clamp: unset !important;
  }

  .prop-sheet-notes strong {
    font-weight: 700 !important;
    color: #5b21b6 !important;
    font-size: 11px !important;
  }

  .prop-sheet-actions-mobile {
    display: block !important;
    margin-top: 8px !important;
  }

  .prop-quick-actions {
    display: flex !important;
    gap: 6px !important;
    align-items: center !important;
  }

  .prop-qa-btn {
    min-height: 36px !important;
    padding: 6px 12px !important;
    font-size: 12px !important;
    border-radius: 8px !important;
  }

  .prop-qa-btn.edit {
    flex: 0 0 auto !important;
  }

  .prop-qa-btn.edit.primary {
    /* Z14: Edit is compact secondary — never full-width. */
    flex: 0 0 auto !important;
  }

  .prop-qa-btn.more {
    flex: 0 0 44px !important;
    width: 44px !important;
    padding: 0 !important;
    font-size: 14px !important;
    letter-spacing: 1px;
  }

  .prop-more-menu {
    position: absolute;
    right: 8px;
    bottom: calc(100% + 4px);
    z-index: 20;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    min-width: 150px;
    overflow: hidden;
  }

  .prop-more-menu .prop-more-item {
    display: block;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid #f3f0f8;
  }

  .prop-more-menu .prop-more-item:last-child {
    border-bottom: none;
  }

  .prop-sheet-actions-mobile,
  .prop-quick-actions {
    position: relative;
  }

  /* Sticky save above nav */
  .mobile-sticky-save {
    bottom: var(--mobile-nav-total) !important;
    padding: 6px 12px !important;
    z-index: 44;
  }

  body:has(#add-panel:not(.hidden)) .mobile-sticky-save {
    display: flex !important;
    align-items: center;
    gap: 8px;
  }

  body:has(#add-panel:not(.hidden)) main {
    padding-bottom: calc(var(--mobile-nav-total) + 58px) !important;
  }

  /* Filter bottom sheet */
  .filters-drawer:not(.hidden) {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    max-height: 82vh;
    overflow: auto;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
    padding: 0 12px calc(12px + var(--mobile-nav-safe));
    margin: 0;
  }

  .filters-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 59;
    background: rgba(15, 10, 30, 0.45);
  }

  .mobile-filter-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0 8px;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 2;
    border-bottom: 1px solid var(--line);
    margin-bottom: 8px;
  }

  .mobile-filter-sheet-head strong {
    font-size: 15px;
  }

  .mobile-filter-sheet-actions {
    display: flex;
    gap: 8px;
    padding: 10px 0 calc(4px + var(--mobile-nav-safe));
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0), #fff 24%);
  }

  .mobile-filter-sheet-actions .btn-sm {
    flex: 1;
    min-height: 44px;
  }

  /* Add form — sticky step nav so Step 1 stays tappable after scroll (Z13.6) */
  .add-step-nav {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 6px 0 8px;
    margin-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--surface, #fff);
    pointer-events: auto;
  }

  .add-step-btn {
    flex: 0 0 auto;
    min-height: 40px;
    min-width: 72px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--line, #e4e4e7);
    background: #fafafa;
    font-size: 13px;
    pointer-events: auto;
    touch-action: manipulation;
  }

  .add-step-btn.active {
    background: #18181b;
    color: #fff;
    border-color: #18181b;
  }

  .add-zone.collapsed-mobile .add-grid,
  .add-zone.collapsed-mobile .toolbar-row,
  .add-zone.collapsed-mobile label.add-wide,
  .add-zone.collapsed-mobile .warn-list,
  .add-zone.collapsed-mobile #post-footer-box,
  .add-zone.collapsed-mobile #group-recommend-box {
    display: none !important;
  }

  .owner-contact-block {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #fffbeb;
    border: 1px solid #fde68a;
  }

  /* Recheck mobile */
  .recheck-summary-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .recheck-summary-card {
    min-height: 52px;
    padding: 8px 10px;
  }

  .recheck-summary-card strong {
    font-size: 18px !important;
  }

  .recheck-desktop-tables {
    display: none !important;
  }

  .recheck-mobile-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  /* More menu sheet */
  .mobile-more-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 10, 30, 0.45);
    z-index: 55;
  }

  .mobile-more-backdrop.open {
    display: block;
  }

  .mobile-more-sheet {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-total);
    z-index: 56;
    background: var(--surface, #fff);
    border-radius: 16px 16px 0 0;
    padding: 12px 12px calc(12px + var(--mobile-nav-safe));
    box-shadow: 0 -10px 30px rgba(30, 20, 51, 0.18);
    max-height: min(70dvh, 520px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-more-sheet.open {
    display: block;
  }

  .mobile-more-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-more-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 68px;
    padding: 10px 6px;
    border: 1px solid var(--line, #e8e2f1);
    border-radius: 12px;
    background: #faf8fc;
    color: var(--ink, #1e1433);
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    box-sizing: border-box;
    overflow: hidden;
  }

  .mobile-more-item svg {
    width: 22px !important;
    height: 22px !important;
    flex-shrink: 0;
    display: block;
  }

  /* Sidebar legacy links must not leak into mobile viewport */
  .sidebar-subnav .tab-sub[href] {
    display: none !important;
  }

  .submenu-bar {
    padding: 4px 0 !important;
  }
}

@media (max-width: 700px) {
  .prop-list-head,
  .prop-list-head-desktop {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
  }
}

/* Tablet — preserve Z13 adaptive + Accordion/step nav for Add/Edit (Z13.6) */
@media (min-width: 769px) and (max-width: 1024px) {
  .mobile-nav {
    display: none !important;
  }

  .add-step-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 0 10px;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--surface, #fff);
    pointer-events: auto;
  }

  .add-step-btn {
    flex: 0 0 auto;
    min-height: 40px;
    min-width: 80px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--line, #e4e4e7);
    background: #fafafa;
    font-size: 13px;
    pointer-events: auto;
    touch-action: manipulation;
  }

  .add-step-btn.active {
    background: #18181b;
    color: #fff;
    border-color: #18181b;
  }

  .add-zone.collapsed-mobile .add-grid,
  .add-zone.collapsed-mobile .toolbar-row,
  .add-zone.collapsed-mobile label.add-wide,
  .add-zone.collapsed-mobile .warn-list,
  .add-zone.collapsed-mobile #post-footer-box,
  .add-zone.collapsed-mobile #group-recommend-box {
    display: none !important;
  }

  main {
    padding: 0 16px 24px !important;
  }

  .prop-sheet-side-desktop {
    display: flex !important;
  }

  .prop-sheet-meta-desktop {
    display: flex !important;
  }

  .prop-sheet-actions-mobile {
    display: none !important;
  }

  .prop-sheet-price-inline {
    display: none !important;
  }

  #property-rows {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .prop-sheet-row {
    margin-bottom: 0 !important;
  }

  .prop-list-head-desktop {
    display: grid !important;
    visibility: visible !important;
    height: auto !important;
  }
}

@media (min-width: 1025px) {
  .prop-sheet-side-desktop {
    display: flex !important;
  }

  .prop-sheet-meta-desktop {
    display: flex !important;
  }

  .prop-sheet-actions-mobile,
  .prop-sheet-price-inline {
    display: none !important;
  }

  .prop-page-compact-wrap {
    display: none !important;
  }

  .sort-label-desktop {
    display: inline !important;
  }

  .recheck-mobile-cards,
  .recheck-summary-grid {
    display: none;
  }

  .recheck-desktop-tables {
    display: block !important;
  }

  .add-step-nav {
    display: none;
  }
}

@media (min-width: 769px) {
  .mobile-sticky-save,
  .mobile-more-sheet,
  .mobile-more-backdrop,
  .mobile-filter-sheet-head,
  .mobile-filter-sheet-actions {
    display: none !important;
  }
}
/* Editable internal contact fields, shared by mobile and desktop. */
.owner-contact-block > label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  min-width: 0;
}
.owner-contact-block input {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  font-size: 16px;
}
.owner-contact-block input:focus-visible {
  outline: 2px solid #6d28d9;
  outline-offset: 2px;
}
#owner-contact-help {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.5;
}
