/* Responsive ownership layer.
   All phone/tablet layout rules live here so components have one authoritative
   breakpoint implementation. Desktop component styling remains in app.css. */

:root {
  --tap-target: 44px;
  --mobile-gap: 10px;
}

html {
  min-width: 0;
  overflow-x: clip;
}

body,
.app-shell,
.app-main,
.dashboard-card {
  min-width: 0;
}

.inventory-row-disclosure {
  display: none;
}

.row-disclosure-button {
  display: none;
}

.invoice-share-button {
  min-height: 32px;
  white-space: nowrap;
}

.secondary-nav-link {
  opacity: 0.82;
}

#inventory-table input:disabled,
#inventory-table select:disabled,
#inventory-table button:disabled,
#inventory-table .stock-input {
  color: #4b5565 !important;
  -webkit-text-fill-color: #4b5565 !important;
  opacity: 1 !important;
}

body[data-review-mode="true"] #inventory-table .stock-controls,
body[data-review-mode="true"] #inventory-table .inventory-inline-select,
body[data-review-mode="true"] #inventory-table .inventory-inline-input,
body[data-review-mode="true"] #inventory-table .inventory-delete {
  opacity: 1 !important;
  filter: none !important;
}

body[data-review-mode="true"] #inventory-table .inventory-delete {
  color: #963a35 !important;
  -webkit-text-fill-color: #963a35 !important;
}

@media (max-width: 980px) {
  body .app-sidebar {
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand sync"
      "nav nav";
    gap: 5px 10px;
    padding: 7px 12px 5px;
  }

  body .sidebar-brand,
  body .sidebar-logo-frame {
    width: 118px;
    min-width: 118px;
  }

  body .sidebar-logo-frame {
    height: 34px;
  }

  body .sidebar-logo {
    width: 126px;
  }

  body .sidebar-sync-summary {
    min-height: 34px;
    padding: 5px 9px;
  }

  body .sidebar-nav {
    width: calc(100% + 8px);
    margin: 0 -4px;
    padding: 1px 4px 3px;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x proximity;
  }

  body .sidebar-nav a {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 12px;
    scroll-snap-align: start;
  }

  body .app-main {
    width: 100%;
    padding: 14px 12px calc(28px + env(safe-area-inset-bottom));
  }

  body .review-mode-banner,
  body .staging-mode-banner,
  body .inventory-sticky-controls,
  body[data-review-mode="true"] .inventory-sticky-controls,
  #inventory-table thead th,
  .invoice-items-sticky-heading,
  .invoice-totals,
  .shop-editor-preview {
    position: static;
    top: auto;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,
  textarea {
    max-width: 100%;
    font-size: 16px !important;
    pointer-events: auto;
    touch-action: manipulation;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  textarea {
    -webkit-user-select: text;
    user-select: text;
  }

  details.dashboard-card {
    scroll-margin-top: 88px;
  }

  #inventory-section .table-wrap,
  .invoice-recent-section .table-wrap,
  #recent-changes .table-wrap {
    width: 100%;
    max-height: none;
    overflow: visible;
  }

  #inventory-table,
  #inventory-table tbody,
  #invoice-list-table,
  #invoice-list-table tbody,
  #recent-table,
  #recent-table tbody {
    display: block;
    width: 100%;
    min-width: 0;
  }

  #inventory-table thead,
  #invoice-list-table thead,
  #recent-table thead {
    display: none;
  }

  #inventory-table tbody {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
  }

  #inventory-table tbody tr.inventory-row {
    display: grid;
    height: auto !important;
    min-height: 0;
    grid-template-columns: 30px minmax(0, 1fr) minmax(136px, 0.8fr);
    grid-template-areas:
      "select article stock"
      "description description description"
      "location location bin"
      "actions actions actions";
    align-items: start;
    gap: 10px;
    margin: 0;
    border: 1px solid #dfe4ea;
    border-radius: 14px;
    background: #fff;
    padding: 12px;
    box-shadow: 0 3px 12px rgba(15, 23, 42, 0.045);
  }

  #inventory-table tbody tr.inventory-row-inactive {
    border-color: #cfd5de;
    background: #f3f4f6;
  }

  #inventory-table tbody tr.inventory-row > td {
    position: static;
    z-index: auto;
    width: auto;
    min-width: 0;
    max-width: none;
    border: 0;
    background: transparent;
    padding: 0;
    box-shadow: none;
  }

  #inventory-table tbody tr.inventory-row:hover > td,
  #inventory-table tbody tr.inventory-row:nth-child(even) > td,
  #inventory-table tbody tr.inventory-row-inactive > td {
    background: transparent;
  }

  #inventory-table .inventory-select-cell { grid-area: select; padding-top: 4px; }
  #inventory-table .inventory-article-cell { grid-area: article; font-size: 14px; font-weight: 800; }
  #inventory-table .inventory-description-cell { grid-area: description; }
  #inventory-table .inventory-location-cell { grid-area: location; }
  #inventory-table .inventory-bin-cell { grid-area: bin; }
  #inventory-table .inventory-stock-cell { grid-area: stock; }
  #inventory-table .inventory-actions-cell { grid-area: actions; }
  #inventory-table .inventory-centered-cell { display: none; }

  #inventory-table .inventory-select-cell::before,
  #inventory-table .inventory-article-cell::before,
  #inventory-table .inventory-description-cell::before,
  #inventory-table .inventory-actions-cell::before {
    display: none;
  }

  #inventory-table .inventory-description-text {
    display: -webkit-box;
    overflow: hidden;
    line-height: 1.35;
    overflow-wrap: anywhere;
    white-space: pre-line;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
  }

  #inventory-table .inventory-location-cell,
  #inventory-table .inventory-bin-cell,
  #inventory-table .inventory-stock-cell {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
  }

  #inventory-table .inventory-stock-cell {
    align-items: flex-end;
  }

  #inventory-table .inventory-location-cell::before,
  #inventory-table .inventory-bin-cell::before,
  #inventory-table .inventory-stock-cell::before {
    color: #667085;
    content: attr(data-label);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  #inventory-table .inventory-inline-select,
  #inventory-table .inventory-inline-input {
    width: 100%;
    min-width: 0;
    max-width: none;
    min-height: var(--tap-target);
  }

  #inventory-table .inventory-actions {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  #inventory-table .inventory-actions .inventory-copy,
  #inventory-table .inventory-actions .inventory-edit,
  #inventory-table .inventory-actions .inventory-delete,
  #inventory-table .stock-step-button {
    min-height: var(--tap-target) !important;
  }

  #invoice-list-table tbody,
  #recent-table tbody {
    box-sizing: border-box;
    display: grid;
    gap: 8px;
    padding: 8px;
  }

  #invoice-list-table .invoice-list-row,
  #recent-table .recent-row {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    margin: 0;
    border: 1px solid #dfe4ea;
    border-radius: 12px;
    background: #fff;
    padding: 12px 38px 12px 12px;
    cursor: pointer;
  }

  #invoice-list-table .invoice-list-row::after,
  #recent-table .recent-row::after {
    position: absolute;
    top: 14px;
    right: 14px;
    color: #667085;
    content: "⌄";
    font-weight: 800;
  }

  #invoice-list-table .invoice-list-row.is-expanded::after,
  #recent-table .recent-row.is-expanded::after {
    content: "⌃";
  }

  #invoice-list-table .invoice-list-row td,
  #recent-table .recent-row td {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
    border: 0;
    background: transparent;
    padding: 0;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  #invoice-list-table .invoice-list-row td::before,
  #recent-table .recent-row td::before {
    color: #667085;
    content: attr(data-label);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.055em;
    text-transform: uppercase;
  }

  #invoice-list-table .invoice-list-customer,
  #recent-table td[data-label="Wine"],
  #recent-table td[data-label="Change"] {
    grid-column: 1 / -1;
  }

  #invoice-list-table .invoice-document-actions-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .row-disclosure-button {
    display: none;
  }

  .invoice-finalize-dialog[open] {
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }

  .shop-product-form {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 760px) {
  body .app-sidebar {
    padding-inline: 10px;
  }

  body .app-main {
    padding-inline: 8px;
  }

  .dashboard-card > .card-header {
    min-height: 58px;
    padding: 12px 14px;
  }

  .card-title {
    font-size: 17px;
  }

  .card-subtitle {
    font-size: 12px;
  }

  .inventory-toolbar,
  .inventory-bulk-section {
    padding: 12px;
  }

  .inventory-filter-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .inventory-filter-form .toolbar-field:first-child,
  .inventory-filter-form .toolbar-reset-button {
    grid-column: 1 / -1;
  }

  .inventory-filter-form .toolbar-field,
  .inventory-filter-form .inventory-filter-input,
  .inventory-filter-form .toolbar-reset-button {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .inventory-bulk-section .bulk-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  #inventory-table tbody {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  #inventory-table tbody tr.inventory-row {
    grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas:
      "select article stock"
      "description description description"
      "location location location"
      "bin bin bin"
      "actions actions actions";
    gap: 7px 9px;
    padding: 10px;
  }

  #inventory-table .inventory-description-text {
    -webkit-line-clamp: 3;
  }

  #inventory-table .inventory-row:not(.is-expanded) .inventory-location-cell,
  #inventory-table .inventory-row:not(.is-expanded) .inventory-bin-cell,
  #inventory-table .inventory-row:not(.is-expanded) .inventory-actions-cell {
    display: none;
  }

  .inventory-row-disclosure {
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    margin: 5px 0 0;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    background: #fff;
    padding: 4px 9px;
    color: #245293;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
  }

  .row-disclosure-button {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    margin-top: 5px;
    border: 0;
    background: transparent;
    padding: 0;
    color: #245293;
    font: inherit;
    font-size: 11px;
    font-weight: 800;
  }

  #invoice-list-table .invoice-list-row:not(.is-expanded) td:nth-child(n+5),
  #recent-table .recent-row:not(.is-expanded) td:not([data-label="Article"]):not([data-label="Wine"]):not([data-label="Change"]):not([data-label="Detected"]) {
    display: none;
  }

  #recent-table .recent-row:not(.is-expanded) td[data-label="Detected"] {
    grid-column: 1 / -1;
  }

  .invoice-recent-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
  }

  .invoice-recent-toolbar #invoice-list-search {
    grid-column: 1 / -1;
    width: 100%;
  }

  .invoice-recent-toolbar .invoice-status-filter,
  .invoice-recent-toolbar select {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 430px) {
  body .sidebar-nav a {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 11px;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
