/* ═══════════════════════════════════════════════
   BREWER QUOTE BUILDER — MOBILE RESPONSIVE
   All desktop (1024px+) layouts are unchanged.
   All overrides are inside media queries.
   ═══════════════════════════════════════════════ */

/* ── DESKTOP: hide all mobile-only elements ─── */
@media (min-width: 1024px) {
  .mobile-top-bar    { display: none !important; }
  .drawer-overlay    { display: none !important; }
  .drawer-user-header { display: none !important; }
  .mobile-action-bar { display: none !important; }
  .quote-metrics-grid { display: none !important; }
  .quotes-cards-list  { display: none !important; }
  .users-cards        { display: none !important; }
  .price-lists-cards  { display: none !important; }
  .add-rep-fixed-btn  { display: none !important; }
  .admin-notice-banner { display: none !important; }
  .btn-export-csv-mobile { display: none !important; }
}

/* ══════════════════════════════════════════════
   MOBILE + TABLET NAV (max-width: 1023px)
   ══════════════════════════════════════════════ */
@media (max-width: 1023px) {
  /* No horizontal scrolling */
  body { overflow-x: hidden; }

  /* Zero-out sidebar width so main content fills viewport */
  :root { --sidebar-w: 0px; }

  /* ── Mobile top bar ── */
  .mobile-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 56px;
    background: var(--navy);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 998;
    flex-shrink: 0;
  }

  .mobile-logo {
    max-height: 32px;
    max-width: 120px;
    object-fit: contain;
    filter: brightness(0) invert(1);
  }

  .hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
  }

  .hamburger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
  }

  /* ── Drawer overlay ── */
  .drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
  .drawer-overlay.open { display: block; }

  /* ── Sidebar becomes off-canvas drawer ── */
  #sidebar {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1000;
  }
  #sidebar.open { transform: translateX(0); }

  /* Hide desktop sidebar logo — top bar has logo */
  .sidebar-logo { display: none; }

  /* ── Drawer user header (mobile only) ── */
  .drawer-user-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
  }

  .drawer-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: var(--red);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
  }

  .drawer-user-info-text {
    flex: 1;
    min-width: 0;
  }

  .drawer-user-display-name {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ── Nav links: 48px touch targets ── */
  .nav-link {
    height: 48px;
    padding: 0 16px;
    font-size: 0.95rem;
    min-height: 48px;
  }

  /* ── Sidebar user (sign-out area) ── */
  #sidebar-user-name { display: none; }
  .sidebar-user {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
  .sidebar-user .btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
  }

  /* ── Admin-only nav items: show but dim for sales_rep ── */
  body.is-sales-rep #nav-admin-section.hidden,
  body.is-sales-rep #nav-users.hidden,
  body.is-sales-rep #nav-pricelists.hidden,
  body.is-sales-rep #nav-settings.hidden,
  body.is-sales-rep .nav-admin-only.hidden {
    display: block !important;
  }
  body.is-sales-rep #nav-users .nav-link,
  body.is-sales-rep #nav-pricelists .nav-link,
  body.is-sales-rep #nav-settings .nav-link,
  body.is-sales-rep .nav-admin-only .nav-link {
    opacity: 0.4;
    pointer-events: none;
    cursor: default;
  }
  body.is-sales-rep #nav-admin-section .nav-section-label {
    opacity: 0.4;
  }

  /* ── Push main content below fixed top bar ── */
  #main-content {
    padding-top: calc(56px + 1rem);
    width: 100%;
  }

  /* Screen-app: flex still works (sidebar is out of flow) */
  #screen-app.active {
    display: flex;
    overflow: hidden;
  }
}

/* ── Tablet: restore normal content padding ── */
@media (min-width: 768px) and (max-width: 1023px) {
  #main-content {
    padding-top: calc(56px + 1.75rem);
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* ══════════════════════════════════════════════
   MOBILE ONLY (max-width: 767px)
   ══════════════════════════════════════════════ */
@media (max-width: 767px) {

  /* ── Global ── */
  body { font-size: max(12px, 0.9rem); }
  .btn { min-height: 44px; }

  #main-content {
    padding-left: 14px;
    padding-right: 14px;
  }

  /* ── Input sizing ── */
  .input-sm { max-width: 100%; }

  /* ══════════════════════════════════════════════
     QUOTES VIEW
     ══════════════════════════════════════════════ */

  /* Metric cards grid */
  .quote-metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .metric-card {
    background: #fff;
    border: 1px solid #e0e2e6;
    border-radius: 8px;
    padding: 12px 14px;
  }

  .metric-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
  }

  .metric-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--navy);
    line-height: 1.2;
  }

  /* Admin notice banner */
  .admin-notice-banner {
    border-left: 4px solid #e8a900;
    background: #fffbea;
    padding: 12px 16px;
    font-size: 13px;
    color: #7a5c00;
    border-radius: 0 4px 4px 0;
  }

  /* Filters: stack vertically */
  #view-quotes .filters-row {
    flex-direction: column;
    gap: 8px;
  }
  #view-quotes .filters-row .input-sm {
    max-width: 100%;
    width: 100%;
  }

  /* Export CSV button: full width */
  .btn-export-csv-mobile {
    display: flex;
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  /* Hide table, show cards */
  #view-quotes .table-wrap { display: none; }
  .quotes-cards-list { display: block; }

  /* Quote cards */
  .quote-card {
    background: #fff;
    border: 1px solid #e0e2e6;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
  }

  .quote-card-row1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
  }

  .quote-card-num {
    color: var(--red);
    font-weight: 600;
    font-size: 0.9rem;
  }

  .quote-card-row2 {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .quote-card-row3 {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 8px;
  }

  .quote-card-row4 {
    font-size: 18px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 10px;
  }

  .quote-card-divider {
    border: none;
    border-top: 1px solid #e0e2e6;
    margin-bottom: 10px;
  }

  .quote-card-actions {
    display: flex;
    gap: 6px;
  }

  .quote-card-actions .btn {
    flex: 1;
    justify-content: center;
    min-height: 44px;
    font-size: 0.78rem;
    padding: 0 6px;
    white-space: nowrap;
    overflow: hidden;
  }

  /* Admin card rows */
  .quote-card-admin-row1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
  }

  .quote-card-admin-row2 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    margin-bottom: 6px;
  }

  .quote-card-admin-row3 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
  }

  .rep-initials-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    margin-right: 4px;
    vertical-align: middle;
  }

  /* ══════════════════════════════════════════════
     QUOTE EDITOR
     ══════════════════════════════════════════════ */

  /* Stack editor grid */
  .editor-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Editor meta fields: keep 2-col for date pairs */
  .editor-meta .field-grid-2 {
    grid-template-columns: 1fr 1fr;
  }

  /* Hide desktop header action buttons */
  #view-quote-editor .view-header-actions { display: none; }

  /* Search input: full width stacked */
  .search-controls {
    flex-direction: column;
  }
  .search-controls input,
  .search-controls select {
    width: 100%;
    min-width: unset;
    flex: none;
  }

  /* Product results: mobile card layout */
  .product-results {
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .product-result-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid #E2E2E8;
  }

  .product-result-item .product-info {
    width: 100%;
  }

  .product-result-item .item-num {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
  }

  .product-result-item .item-num span:first-child {
    font-weight: 700;
    color: #C8102E;
    font-size: 13px;
  }

  .product-result-item .item-desc {
    font-size: 12px;
    color: #4A4A4A;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    white-space: normal;
  }

  .btn-add-mobile {
    width: 100%;
    background-color: #C8102E !important;
    color: white !important;
    border: none !important;
    padding: 10px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    margin-top: 4px;
  }

  .btn-add-freight {
    background: transparent !important;
    color: #1C1C2E !important;
    border: 1px solid #1C1C2E !important;
    width: auto !important;
  }

  .product-result-item .btn-add-mobile:hover:not(:disabled) {
    background: var(--red-hover);
    border-color: var(--red-hover);
  }

  /* Dist price shown inline on item-num row */
  .product-result-item .mobile-dist-price {
    margin-left: auto;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--navy);
  }

  /* Line items: CSS grid override for table rows */
  #line-items-table thead { display: none; }

  #line-items-table tbody { display: block; }

  #line-items-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-rows: auto auto auto;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    gap: 2px 6px;
    align-items: start;
  }
  #line-items-table tbody tr:last-child { border-bottom: none; }

  /* Col 1: item number */
  #line-items-table td:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
    display: block;
  }
  #line-items-table td:nth-child(1) input { width: 90px; font-size: 0.82rem; }

  /* Col 2: description — spans full width on row 2 */
  #line-items-table td:nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
    display: block;
  }
  #line-items-table td:nth-child(2) input { font-size: 0.85rem; }

  /* Extended price — row 1, col 2 */
  #line-items-table td:nth-child(6) {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: center;
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.9rem;
    text-align: right;
  }

  /* Delete button — row 1, col 3 */
  #line-items-table td:nth-child(7) {
    grid-column: 3;
    grid-row: 1;
    display: flex;
    align-items: center;
  }
  #line-items-table td:nth-child(7) .btn { min-height: 36px; }

  /* Qty, price type, unit price — row 3 inline */
  #line-items-table td:nth-child(3),
  #line-items-table td:nth-child(4),
  #line-items-table td:nth-child(5) {
    grid-row: 3;
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
  }
  #line-items-table td:nth-child(3) { grid-column: 1; }
  #line-items-table td:nth-child(3) input { width: 55px; font-size: 0.82rem; }
  #line-items-table td:nth-child(4) { grid-column: 2; }
  #line-items-table td:nth-child(4) select { font-size: 0.82rem; }
  #line-items-table td:nth-child(5) { grid-column: 3; }
  #line-items-table td:nth-child(5) input { width: 72px; font-size: 0.82rem; }

  /* Subtotal bar: navy full-width strip */
  .subtotal-row {
    background: var(--navy);
    margin: 0 -14px;
    padding: 16px 14px;
    justify-content: space-between;
    color: #fff;
  }
  #quote-subtotal { color: #fff; }

  /* Mobile action bar: pinned to bottom */
  .mobile-action-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e0e2e6;
    z-index: 200;
    padding: 8px 14px;
    gap: 8px;
  }

  .mobile-action-bar .btn {
    flex: 1;
    justify-content: center;
    height: 48px;
    min-height: 48px;
    font-size: 0.82rem;
    padding: 0 6px;
  }

  /* Bottom padding so content isn't hidden behind action bar */
  #view-quote-editor { padding-bottom: 80px; }

  /* ══════════════════════════════════════════════
     PRICE LISTS
     ══════════════════════════════════════════════ */

  #view-price-lists .table-wrap { display: none; }
  .price-lists-cards { display: block; }

  /* Upload button full-width */
  #view-price-lists .view-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  #view-price-lists .view-header label.btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
    text-align: center;
  }

  /* Price list cards */
  .price-list-card {
    background: #fff;
    border: 1px solid #e0e2e6;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
  }

  .price-list-card-row1 {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
  }

  .price-list-filename {
    font-weight: 600;
    color: var(--text);
    word-break: break-all;
    flex: 1;
    margin-right: 8px;
    font-size: 0.9rem;
  }

  .price-list-card-row2 {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 12px;
  }

  .price-list-card-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .price-list-card-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  /* ══════════════════════════════════════════════
     USERS / MANAGE REPS
     ══════════════════════════════════════════════ */

  #view-users .table-wrap { display: none; }
  .users-cards { display: block; }

  /* Hide desktop "New User" header button */
  #view-users #btn-new-user { display: none; }

  /* Padding for fixed add-rep button */
  #view-users { padding-bottom: 60px; }

  /* User cards */
  .user-card {
    background: #fff;
    border: 1px solid #e0e2e6;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
  }

  .user-card-row1 {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
  }

  .user-initials-circle {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
  }

  .user-card-name-wrap {
    flex: 1;
    min-width: 0;
  }

  .user-card-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .user-card-row2 {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 6px;
    padding-left: 52px;
    word-break: break-all;
  }

  .user-card-row3 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-left: 52px;
  }

  .user-card-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .user-card-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  /* Fixed "Add New Rep" button */
  .add-rep-fixed-btn {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 52px;
    min-height: 52px;
    background: var(--red);
    color: #fff;
    border: none;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 100;
    letter-spacing: 0.01em;
  }
  .add-rep-fixed-btn:hover { background: var(--red-hover); }

  /* ══════════════════════════════════════════════
     TOAST: keep away from bottom action bar
     ══════════════════════════════════════════════ */
  #toast-container {
    bottom: 80px;
    right: 14px;
    left: 14px;
    align-items: flex-end;
  }

  .toast { max-width: 100%; }

} /* end @media (max-width: 767px) */
