/* ==================== DESKTOP LAYOUT (wide screens only) ====================
   Everything here is inside min-width media queries so phones (<1024px) are
   untouched. Loaded last so it wins the cascade on desktop. */

.desktop-shortcuts-link {
  display: none;
}

@media (min-width: 1024px) {
  :root {
    --desktop-nav-width: 232px;
    --desktop-content-max: 1360px;
  }

  /* ---------- App shell: permanent sidebar, no hamburger/overlay ---------- */
  .hamburger,
  .side-nav .close-btn,
  .overlay {
    display: none !important;
  }

  .side-nav {
    left: 0;
    width: var(--desktop-nav-width);
    max-width: none;
    box-shadow: none;
    border-right: 1px solid var(--border-color);
    transition: none;
    z-index: 900;
  }

  .nav-header {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 20px 18px;
  }

  .nav-header h2 {
    font-size: 20px;
  }

  /* Notifications bell sits in the sidebar header; inbox opens beside it */
  .notif-bell {
    top: 22px;
    left: calc(var(--desktop-nav-width) - 54px);
    right: auto;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.18);
    box-shadow: none;
  }

  .notif-backdrop {
    background: transparent;
  }

  .notif-panel {
    left: calc(var(--desktop-nav-width) + 12px);
    right: auto;
    top: 12px;
    bottom: auto;
    width: 420px;
    max-height: calc(100vh - 24px);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  }

  .nav-menu {
    padding: 8px 0;
  }

  .nav-menu a {
    padding: 10px 14px;
    font-size: 14px;
    margin: 1px 8px;
  }

  .nav-icon {
    font-size: 18px;
    margin-right: 10px;
  }

  .desktop-shortcuts-link {
    display: block;
    margin: 8px 16px 20px;
    padding: 8px 10px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    text-align: left;
    cursor: pointer;
    width: calc(100% - 32px);
  }

  .desktop-shortcuts-link:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
  }

  .tab {
    margin-left: var(--desktop-nav-width);
    max-width: none;
    padding: 24px max(32px, calc((100vw - var(--desktop-nav-width) - var(--desktop-content-max)) / 2)) 48px;
    /* Dynamic viewport height where supported (tabs.css keeps 100vh for phones). */
    min-height: 100dvh;
    height: 100dvh;
  }

  /* Top-of-page segmented toggles (Purchase | Sale etc.) span the content
     width (no max-width) and match Today's .sub-tabs bar height. */
  .tab > .filter-buttons:first-child > .filter-btn {
    padding: 14px 20px;
  }

  /* ---------- Billing: entry left, sticky bill summary right ---------- */
  #purchaseSection:not([style*="none"]),
  #saleSection:not([style*="none"]),
  #salesEntrySection:not([style*="none"]) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
    column-gap: 28px;
    align-items: start;
  }

  /* Live bill-check banner (#188) spans both columns */
  .bill-check-banner {
    grid-column: 1 / -1;
  }

  #salesEntrySection > :not(.bill-col-entry):not(.bill-col-summary) {
    grid-column: 1 / -1;
  }

  .bill-col-entry,
  .bill-col-summary {
    min-width: 0;
  }

  .bill-col-summary {
    position: sticky;
    top: 0;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    padding: 4px 4px 8px;
  }

  .bill-col-summary > .bill-totals:first-child {
    margin-top: 0;
  }

  .bill-col-entry > .form-row:first-child {
    margin-top: 0;
  }

  #billing .bill-col-entry > .bill-totals,
  #wholesale-sales .bill-col-entry > .bill-totals {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
  }

  #billing .bill-col-entry > .bill-totals > *,
  #wholesale-sales .bill-col-entry > .bill-totals > * {
    grid-column: 1 / -1;
  }

  #billing .bill-col-entry > .bill-totals > .form-row:nth-child(1),
  #billing .bill-col-entry > .bill-totals > .form-row:nth-child(2) {
    grid-column: auto;
  }

  #billTable,
  #saleTable,
  #salesTable {
    table-layout: auto;
  }

  #billTable td, #saleTable td {
    max-width: none;
  }

  /* ---------- Outstanding: aging panel (#46) ---------- */
  .aging-bucket {
    padding: 10px 14px;
  }

  .aging-bucket-amount {
    font-size: 18px;
  }

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

  .aging-party {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .aging-party-actions {
    grid-column: auto;
    flex-wrap: nowrap;
  }

  /* ---------- History / lists: dense rows ---------- */
  #historyList .history-item,
  #salesHistoryList .history-item {
    display: grid;
    grid-template-columns: minmax(260px, 1.3fr) minmax(250px, 1fr) minmax(0, 1.2fr) minmax(180px, auto);
    align-items: center;
    column-gap: 20px;
    padding: 10px 16px;
    margin-bottom: 6px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
  }

  #historyList .history-item:hover,
  #salesHistoryList .history-item:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
  }

  #historyList .history-item > *,
  #salesHistoryList .history-item > * {
    margin: 0;
    min-width: 0;
  }

  #historyList .history-summary,
  #salesHistoryList .history-summary {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #historyList .history-payment,
  #salesHistoryList .history-payment {
    justify-content: flex-end;
  }

  #historyList .payment-badge,
  #salesHistoryList .payment-badge {
    padding: 3px 8px;
    font-size: 12px;
  }

  /* ---------- Today: dashboard grid ---------- */
  #dayTodayContent:not([style*="none"]) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
  }

  #dayTodayContent > * {
    margin: 0 !important;
    min-width: 0;
  }

  #dayTodayContent > :nth-child(1),
  #dayTodayContent > :nth-child(2) {
    grid-column: 1 / -1;
  }

  /* ---------- Generic: wider grids and tables ---------- */
  .stats-grid-2:has(> :nth-child(3)) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tab table {
    width: 100%;
  }

  /* ---------- Modals: centered dialogs with comfortable width ---------- */
  .modal-box {
    max-width: 520px;
  }

  .bill-details-container {
    max-width: 680px;
  }

  .bill-details-footer {
    justify-content: flex-end;
  }

  .bill-details-footer .bill-action-btn {
    flex: 0 0 auto;
    min-width: 120px;
  }

  /* ---------- Android update banner: keep clear of the permanent sidebar ---------- */
  .app-update-banner {
    left: calc(var(--desktop-nav-width) + 16px);
    right: 16px;
  }

  /* ---------- Keyboard shortcuts help ---------- */
  .kbd-help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 21000;
  }

  .kbd-help {
    background: var(--card-bg);
    color: var(--text-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: min(560px, 92vw);
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px 24px;
  }

  .kbd-help h3 {
    margin: 0 0 12px;
    font-size: 18px;
  }

  .kbd-help table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
  }

  .kbd-help td {
    padding: 5px 4px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
  }

  .kbd-help td:first-child {
    white-space: nowrap;
    width: 1%;
    padding-right: 16px;
  }

  .kbd-help kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border-color);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--light-bg);
    font-family: inherit;
    font-size: 12px;
  }

  .kbd-help .kbd-hi {
    color: var(--text-secondary);
    margin-left: 6px;
  }

  .kbd-help-close {
    margin-top: 14px;
    float: right;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    background: var(--primary-gradient);
    color: white;
    font-weight: 600;
    cursor: pointer;
  }

  /* Anomalies page (#187): filters in one row, patterns in two columns, row actions inline */
  .anomaly-filters {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

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

  .anomaly-pattern-wide {
    grid-column: 1 / -1;
  }

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

  .anomaly-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .anomaly-row-main {
    flex: 1 1 auto;
  }

  .anomaly-row-actions {
    flex: 0 0 auto;
    justify-content: flex-end;
  }

  /* Rate trends page (#65): pickers in one row, outlooks side by side */
  .rt-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  #rtOutlook .rt-empty {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1024px) and (max-height: 900px) {
  /* Laptop heights (768/720): compact the bill summary column so the total and
     Save/Print stay visible without scrolling the page. */
  .bill-col-summary .bill-totals {
    padding: 8px 16px;
  }

  .bill-col-summary .total-row,
  .bill-col-summary .labor-input-row,
  .bill-col-summary .payment-row {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .bill-col-summary .grand-total,
  .bill-col-summary .payment-row.payment-total {
    padding: 9px 14px !important;
    margin-top: 4px;
    margin-bottom: 4px;
  }

  .bill-col-summary input[type="number"] {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .bill-col-summary > .form-row,
  .bill-col-summary > div[style*="display: flex"] {
    margin-top: 10px !important;
  }

  /* Hidden receipt-preview holder still reserves its inline 20px margin. */
  .bill-col-summary > div:has(> img[id$="DebugPreview"][style*="none"]) {
    margin-top: 0 !important;
  }
}

@media (min-width: 1440px) {
  :root {
    --desktop-nav-width: 256px;
  }
}

/* Finance card breakdown (#215): side panel instead of a bottom sheet */
@media (min-width: 1024px) {
  .fin-sheet-overlay {
    align-items: stretch;
    justify-content: flex-end;
  }

  .fin-sheet {
    width: 520px;
    max-width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.25);
  }

  .fin-sheet-tools input {
    flex: 2 1 200px;
  }

  .fin-sheet-tools select {
    flex: 1 1 120px;
  }
}