/* ═══════════════════════════════════════════════════════════════════════════
   Responsive layer — tablets and phones.
   Loaded after AdminLTE and the shell's own styles, so it only adjusts what
   breaks on small screens. Breakpoints follow Bootstrap 4:
     < 992px  tablet / phone: sidebar is an off-canvas drawer
     < 768px  phone + small tablet portrait: lists become stacked cards
     < 576px  phone
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Shell layout ─────────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  /* The content area is position:fixed — give it both edges so it always
     spans the screen instead of shrinking to its content. */
  .content-wrapper { left: 0 !important; right: 0 !important; margin-left: 0 !important; }
  .main-header { margin-left: 0 !important; }
  .content-wrapper::before { display: none; }
}

.main-footer { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 575.98px) {
  .main-footer { font-size: 11px; padding: 6px 10px; }
}

/* Page header: actions wrap instead of overflowing */
.content-header .row > [class*="col-"]:last-child:not(:first-child) {
  display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .35rem;
}
.content-header .row > [class*="col-"]:last-child:not(:first-child) > * { margin-left: 0 !important; }
@media (max-width: 575.98px) {
  .content-header .breadcrumb { display: none; }
  .content-header h1 { font-size: 1.1rem; }
  .content-header .row > [class*="col-"]:last-child:not(:first-child) { justify-content: flex-start; margin-top: .4rem; }
  .content { padding-left: 0; padding-right: 0; }
  .content > .container-fluid, .content-header > .container-fluid { padding-left: 10px; padding-right: 10px; }
}

/* Page toolbars (button + search + filters) wrap on narrow screens */
.content .d-flex.align-items-center.mb-2,
.content .d-flex.align-items-center.mb-3 { flex-wrap: wrap; row-gap: .4rem; }
@media (max-width: 575.98px) {
  .content .d-flex.align-items-center.mb-2 > .input-group[style*="max-width"],
  .content .d-flex.align-items-center.mb-3 > .input-group[style*="max-width"] { max-width: none !important; flex: 1 1 100%; }
  .content .d-flex.align-items-center.mb-2 > select[style*="max-width"] { max-width: none !important; flex: 1 1 45%; }
}

/* ── Toasts ───────────────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  #toast-container { left: .5rem !important; right: .5rem !important; top: .5rem !important; min-width: 0 !important; }
  .app-toast { min-width: 0 !important; max-width: none !important; }
}

/* ── Dialogs ──────────────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .modal-dialog { margin: .35rem; max-width: none; }
  .modal-dialog-centered { min-height: calc(100% - .7rem); }
  .modal-dialog-scrollable { max-height: calc(100% - .7rem); }
  .modal-header { padding: .6rem .8rem; }
  .modal-body { padding: .75rem; overflow-x: auto; }
  .modal-footer { flex-wrap: wrap; justify-content: flex-end; padding: .5rem; }
  .modal-footer > * { margin: .2rem !important; }
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
/* Wide tables scroll inside their own box (raw tables are wrapped in
   .table-responsive automatically, see public/utils/responsive.js). */
.table-responsive { -webkit-overflow-scrolling: touch; }
/* Bootstrap drops the outer border of bordered tables inside .table-responsive;
   keep auto-wrapped tables looking exactly as they were designed. */
.vsm-autowrap > .table-bordered { border: 1px solid #dee2e6; }
body.dark-mode .vsm-autowrap > .table-bordered { border-color: #6c757d; }

/* Shared Table component: every row becomes a card of "Label: value" lines. */
@media (max-width: 767.98px) {
  .table-stack { border: 0 !important; }
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr {
    width: auto; margin: .5rem; padding: .4rem .7rem;
    background: #fff; border: 1px solid #dee2e6 !important; border-radius: .4rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
  }
  .table-stack td {
    display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
    padding: .3rem 0 !important; border: 0 !important; text-align: right !important;
  }
  .table-stack td + td { border-top: 1px solid #f1f3f5 !important; }
  .table-stack td::before {
    content: attr(data-label); flex: 0 0 38%; text-align: left;
    font-size: .78rem; font-weight: 600; color: #6c757d; padding-top: .1rem;
  }
  .table-stack td > .td-val { min-width: 0; overflow-wrap: anywhere; }
  .table-stack td[data-label=""]::before, .table-stack td[colspan]::before { display: none; }
  .table-stack td[colspan] { justify-content: center; text-align: center !important; }
  .table-stack td.td-actions { justify-content: flex-end; padding-top: .5rem !important; }
  .table-stack td.td-actions > .td-val { width: 100%; text-align: right; }
  .table-stack.table-hover tbody tr:hover { background: #fff; }

  body.dark-mode .table-stack tr { background: #343a40; border-color: #4b545c !important; }
  body.dark-mode .table-stack td + td { border-top-color: #4b545c !important; }
  body.dark-mode .table-stack td::before { color: #adb5bd; }

  /* Tables built by hand in pages, converted to the same cards by utils/responsive.js.
     Their markup can carry fixed column widths / min-widths meant for desktop. */
  .vsm-stack { min-width: 0 !important; }
  .vsm-stack td { width: 100% !important; max-width: none !important; white-space: normal !important; }
  .vsm-stack td > .td-val { flex: 1 1 0; text-align: right; }
  /* Footer total rows stay compact "Label  value" lines under the cards */
  .vsm-stack tfoot { display: block; }
  .vsm-stack tfoot tr {
    display: flex; justify-content: flex-end; align-items: baseline; gap: .75rem;
    margin: .2rem .5rem; padding: .2rem .7rem; border: 0 !important; box-shadow: none; background: transparent;
  }
  .vsm-stack tfoot td, .vsm-stack tfoot th { display: block; width: auto !important; padding: 0 !important; border: 0 !important; }
  .vsm-stack tfoot td::before { display: none; }
  .vsm-stack tfoot td:empty { display: none; }
  body.dark-mode .vsm-stack tfoot tr { background: transparent; }
}

/* Bigger touch targets for row actions on touch-sized screens */
@media (max-width: 767.98px) {
  .table .btn-xs, .table .btn-group-xs > .btn { padding: .3rem .55rem; font-size: .8rem; }
  .table .btn-group-sm > .btn, .table .btn-sm { padding: .35rem .6rem; }
  .table .btn-group { flex-wrap: wrap; }
  .pagination .page-link { padding: .4rem .65rem; }
  .pagination { flex-wrap: wrap; }
}

/* ── Job cards workspace ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* "Collapsed" is a desktop side-panel state — on phones the list is on top */
  #jc-panel-toggle { display: none !important; }
  #jc-list-panel.jc-panel--collapsed { width: 100% !important; }
  #jc-list-panel.jc-panel--collapsed .jc-panel-body { opacity: 1 !important; pointer-events: auto !important; }
}
@media (max-width: 575.98px) {
  .ws-header { flex-direction: column; }
  .ws-header__right { flex-wrap: wrap; width: 100%; }
  .ws-header__num { font-size: 17px; }
  .ws-status__btns { display: flex; flex-wrap: wrap; gap: .3rem; }
  .ws-item { grid-template-columns: 1fr 1fr 72px 28px !important; row-gap: 4px; }
  .ws-item > :first-child { grid-column: 1 / -1; }
  .ws-item__note-input { display: block; width: 100% !important; margin: 4px 0 0 !important; }
  .ws-notes__grid { grid-template-columns: 1fr !important; }
}

/* ── Counter sale (POS) cart on phones: one card per line ──────────────────── */
@media (max-width: 575.98px) {
  .pos-cart thead { display: none; }
  .pos-cart tbody tr { display: flex; flex-wrap: wrap; align-items: center; border-bottom: 1px solid #dee2e6; padding: .35rem .25rem; }
  .pos-cart tbody td { border: 0 !important; padding: .2rem .35rem !important; }
  .pos-cart tbody td:nth-child(1) { order: 1; flex: 1 1 calc(100% - 44px); }
  .pos-cart tbody td:nth-child(5) { order: 2; flex: 0 0 44px; }
  .pos-cart tbody td:nth-child(2) { order: 3; flex: 0 0 40%; }
  .pos-cart tbody td:nth-child(3) { order: 4; flex: 1 1 0; }
  .pos-cart tbody td:nth-child(4) { order: 5; flex: 0 0 100%; text-align: right; }
  .pos-cart tbody td[colspan] { flex: 1 1 100%; }
  .pos-total { font-size: 2rem; }
  .pos-methods .btn { font-size: .72rem; }
}

/* ── Forms: avoid iOS zoom-on-focus (inputs under 16px) on phones ─────────── */
@media (max-width: 575.98px) {
  input.form-control, select.form-control, textarea.form-control { font-size: 16px; }
  .form-control-sm { height: calc(1.8125rem + 6px); }
}
