/* =========================================================
   MOBILE LAYOUT (phones, max-width 768px)
   Desktop is not affected: the elements below are hidden on
   desktop, and every other rule is inside the media query.
   ========================================================= */

/* Mobile-only elements; desktop never shows them */
.m-topbar,
.m-overlay,
.m-close,
.m-stats,
.m-only {
  display: none;
}

@media (max-width: 768px) {

  /* ---------- BASICS ---------- */
  html {
    -webkit-text-size-adjust: 100%;
  }

  /* 16px inputs stop iPhones zooming in when a field is tapped */
  input,
  select,
  textarea {
    font-size: 16px;
    max-width: 100%;
  }

  img {
    max-width: 100%;
  }

  /* ---------- TOP BAR + HAMBURGER ---------- */
  .m-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 900;
    height: 56px;
    padding: 0 12px;
    box-sizing: border-box;
    border-bottom: 1px solid #1e293b;
  }

  .m-burger,
  .m-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-size: 0;
  }

  .m-burger:active,
  .m-close:active {
    background: rgba(255, 255, 255, 0.08);
  }

  .m-burger svg,
  .m-close svg {
    width: 26px;
    height: 26px;
  }

  .m-brand {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 0.5px;
  }

  /* ---------- SLIDE-OUT DRAWER ---------- */
  body.has-drawer {
    display: block;
  }

  body.has-drawer .app {
    display: block;
  }

  body.has-drawer .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    height: auto;
    box-sizing: border-box;
    overflow-y: auto;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  body.has-drawer .m-close {
    position: absolute;
    top: 10px;
    right: 10px;
  }

  body.has-drawer .sidebar > h2:first-of-type,
  body.has-drawer .sidebar > .logo {
    margin-top: 6px;
    padding-right: 48px;
  }

  .m-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 950;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  body.nav-open .m-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  body.nav-open {
    overflow: hidden;
  }

  /* ---------- SUMMARY CARDS (moved out of the sidebar) ---------- */
  .m-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0 0 16px;
  }

  .m-stats .card {
    margin: 0;
    padding: 12px 14px;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    min-height: 72px;
    box-sizing: border-box;
  }

  .m-stats .card span {
    opacity: 0.8;
  }

  .m-stats .card strong {
    font-size: 24px;
    line-height: 1;
  }

  .m-stats .card.clickable {
    border-color: #22c55e55;
  }

  /* ---------- SHARED TABLE → CARD PATTERN ---------- */
  .m-cards thead {
    display: none;
  }

  .m-cards,
  .m-cards tbody {
    display: block;
    width: 100%;
    background: transparent;
  }

  .m-cards tr {
    display: grid;
    gap: 10px 12px;
    background: #111827;
    border: 1px solid #1e293b;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    box-sizing: border-box;
  }

  .m-cards tr:hover {
    background: #111827;
  }

  .m-cards td {
    display: block;
    width: auto !important;
    min-width: 0;
    padding: 0 !important;
    border: none !important;
    text-align: left !important;
    white-space: normal !important;
    overflow: visible !important;
    overflow-wrap: anywhere;
    font-size: 15px;
    line-height: 1.35;
  }

  .m-cards td::before {
    display: block;
    font-size: 11px;
    font-weight: normal;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 2px;
  }

  /* "No data" style rows */
  .m-cards td[colspan] {
    grid-column: 1 / -1;
    text-align: center !important;
  }

  .m-cards td[colspan]::before {
    content: none !important;
  }

  /* =========================================================
     DASHBOARD (index.html)
     ========================================================= */
  .page-dashboard main {
    padding: 16px;
    overflow-x: visible;
  }

  .page-dashboard main h1 {
    font-size: 22px;
    margin: 4px 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .page-dashboard .live {
    font-size: 12px;
    padding: 3px 8px;
    border: 1px solid #22c55e;
    border-radius: 999px;
  }

  .page-dashboard .search {
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    margin-bottom: 12px;
  }

  /* FILTER CAROUSEL
     mobile.js wraps .top-actions as: [◀] [ filters viewport ] [▶]
     Only the filter viewport scrolls, never the page. */
  .page-dashboard .m-filter-carousel {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-bottom: 16px;
  }

  .page-dashboard .m-filter-arrow {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 40px;
    padding: 0;
    margin: 0;
    background: #111827;
    color: #fff;
    border: 1px solid #1e293b;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s ease;
  }

  .page-dashboard .m-filter-arrow svg {
    width: 18px;
    height: 18px;
  }

  .page-dashboard .m-filter-arrow:active:not(:disabled) {
    background: #1e293b;
  }

  .page-dashboard .m-filter-arrow:disabled {
    opacity: 0.3;
    cursor: default;
  }

  .page-dashboard .m-filter-carousel .top-actions {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .page-dashboard .m-filter-carousel .top-actions::-webkit-scrollbar {
    display: none;
  }

  .page-dashboard .m-filter-carousel .top-actions > * {
    scroll-snap-align: start;
  }

  .page-dashboard .top-actions input,
  .page-dashboard .top-actions select,
  .page-dashboard .top-actions button {
    flex: 0 0 auto;
    box-sizing: border-box;
    height: 40px;
    margin: 0;
  }

  /* 16px text stops iPhones zooming in when a filter is tapped */
  .page-dashboard .top-actions input,
  .page-dashboard .top-actions select {
    width: auto;
    padding: 0 10px;
    font-size: 16px;
  }

  .page-dashboard #filterDate {
    width: 150px;
  }

  .page-dashboard #filterProduct {
    width: 120px;
  }

  /* Drawer menu items all look the same */
  .page-dashboard .sidebar .m-only {
    display: flex;
  }

  .page-dashboard .sidebar .card h3 {
    margin: 0;
    font-size: inherit;
    font-weight: normal;
  }

  .page-dashboard #downloadExcelBtn {
    padding: 0 14px;
    font-size: 14px;
    white-space: nowrap;
  }

  /* Call cards: columns are
     1 Date, 2 Time, 3 Name, 4 Number, 5 Type, 6 Status,
     7 Product, 8 Details, 9 WA, 10 Mail, 11 Actions */
  .page-dashboard #callTable tr {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas:
      "name name name name"
      "number number number number"
      "date date time time"
      "type type status status"
      "product product details details"
      "wa mail actions actions";
  }

  .page-dashboard #callTable td:nth-child(1)  { grid-area: date; }
  .page-dashboard #callTable td:nth-child(2)  { grid-area: time; }
  .page-dashboard #callTable td:nth-child(3)  { grid-area: name; font-size: 17px; font-weight: bold; }
  .page-dashboard #callTable td:nth-child(4)  { grid-area: number; }
  .page-dashboard #callTable td:nth-child(5)  { grid-area: type; }
  .page-dashboard #callTable td:nth-child(6)  { grid-area: status; }
  .page-dashboard #callTable td:nth-child(7)  { grid-area: product; }
  .page-dashboard #callTable td:nth-child(8)  { grid-area: details; }
  .page-dashboard #callTable td:nth-child(9)  { grid-area: wa; align-self: center; }
  .page-dashboard #callTable td:nth-child(10) { grid-area: mail; align-self: center; }
  .page-dashboard #callTable td:nth-child(11) {
    grid-area: actions;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
  }

  .page-dashboard #callTable td:nth-child(1)::before { content: "Date"; }
  .page-dashboard #callTable td:nth-child(2)::before { content: "Time"; }
  .page-dashboard #callTable td:nth-child(4)::before { content: "Number"; }
  .page-dashboard #callTable td:nth-child(5)::before { content: "Type"; }
  .page-dashboard #callTable td:nth-child(6)::before { content: "Status"; }
  .page-dashboard #callTable td:nth-child(7)::before { content: "Product"; }
  .page-dashboard #callTable td:nth-child(8)::before { content: "Details"; }

  .page-dashboard #callTable .wa-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    font-size: 24px;
  }

  .page-dashboard #callTable td:nth-child(11) button {
    margin: 0;
    min-height: 40px;
    padding: 8px 16px;
    font-size: 14px;
  }

  /* Edit / product modals */
  .page-dashboard .modal-box {
    width: calc(100vw - 32px);
    max-width: 420px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
  }

  .page-dashboard .modal-box input,
  .page-dashboard .modal-box select {
    box-sizing: border-box;
    min-height: 44px;
  }

  .page-dashboard .modal-box .btns button {
    flex: 1;
    min-height: 44px;
    margin-top: 12px;
  }

  /* =========================================================
     LOGIN (login.html)
     ========================================================= */
  .page-login {
    height: auto;
    min-height: 100vh;
    padding: 16px;
    box-sizing: border-box;
  }

  .page-login .login-container {
    width: 100%;
    max-width: 380px;
    padding: 32px 20px;
    box-sizing: border-box;
  }

  .page-login input {
    box-sizing: border-box;
    min-height: 46px;
  }

  .page-login button[type="submit"] {
    min-height: 46px;
    font-size: 16px;
  }

  /* Eye icon: inputs use border-box here, so it sits inside the right edge */
  .page-login .pw-wrap input {
    width: 100%;
    padding-right: 44px;
  }

  .page-login .pw-toggle {
    right: 4px;
    width: 40px;
  }

  .page-login .link {
    padding: 8px;
  }

  /* =========================================================
     ADMIN (admin.html)
     ========================================================= */
  .page-admin main {
    padding: 16px;
    overflow-x: visible;
  }

  .page-admin main h1 {
    font-size: 22px;
    margin: 4px 0 14px;
  }

  .page-admin .box {
    padding: 16px;
  }

  .page-admin .box h2 {
    font-size: 18px;
    margin-top: 0;
  }

  .page-admin .input {
    width: 100%;
    box-sizing: border-box;
    min-height: 46px;
  }

  .page-admin .btn {
    width: 100%;
    min-height: 46px;
    font-size: 15px;
  }

  .page-admin .customer-card {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    overflow-wrap: anywhere;
  }

  .page-admin .customer-card input[type="date"] {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    box-sizing: border-box;
  }

  .page-admin .customer-card button {
    min-height: 40px;
  }

  .page-admin .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-admin .actions button {
    flex: 1 1 0;
    margin: 0;
    min-height: 42px;
    font-size: 14px;
  }

  /* =========================================================
     CUSTOMER DASHBOARD (customer-dashboard.html)
     ========================================================= */
  .page-customer-dashboard .main {
    padding: 16px;
  }

  .page-customer-dashboard .title {
    font-size: 22px;
    margin-bottom: 14px;
  }

  .page-customer-dashboard .menu button {
    min-height: 46px;
    font-size: 16px;
  }

  .page-customer-dashboard .action-btn {
    min-height: 50px;
  }

  /* =========================================================
     CUSTOMERS (customers.html)
     ========================================================= */
  body.page-customers {
    padding: 16px;
  }

  .page-customers h2 {
    font-size: 22px;
    margin: 4px 0 14px;
  }

  /* 1 Date, 2 Name, 3 Number, 4 Product, 5 View */
  .page-customers #customerTable tr {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "name name"
      "number date"
      "product product"
      "view view";
  }

  .page-customers #customerTable td:nth-child(1) { grid-area: date; }
  .page-customers #customerTable td:nth-child(2) { grid-area: name; font-size: 17px; font-weight: bold; }
  .page-customers #customerTable td:nth-child(3) { grid-area: number; }
  .page-customers #customerTable td:nth-child(4) { grid-area: product; }
  .page-customers #customerTable td:nth-child(5) { grid-area: view; }

  .page-customers #customerTable td:nth-child(1)::before { content: "Date"; }
  .page-customers #customerTable td:nth-child(3)::before { content: "Number"; }
  .page-customers #customerTable td:nth-child(4)::before { content: "Product"; }

  .page-customers #customerTable .view-btn {
    width: 100%;
    min-height: 44px;
    font-size: 15px;
  }

  /* =========================================================
     CUSTOMER DETAILS (customer-details.html)
     ========================================================= */
  .page-customer-details .header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 16px;
  }

  .page-customer-details .header h1 {
    font-size: 22px;
  }

  .page-customer-details .header-buttons {
    display: flex;
    gap: 8px;
    width: 100%;
  }

  .page-customer-details .header-buttons button {
    flex: 1;
    margin: 0;
    min-height: 42px;
    font-size: 14px;
  }

  .page-customer-details .container {
    flex-direction: column;
    padding: 16px;
    gap: 24px;
    margin-top: 0;
  }

  .page-customer-details .left-panel {
    width: 100%;
  }

  .page-customer-details .left-card {
    min-height: 0;
    padding: 20px 16px;
  }

  .page-customer-details .save-btn {
    min-height: 42px;
    padding: 8px 24px;
  }

  .page-customer-details .info-row {
    align-items: center;
    gap: 12px;
  }

  .page-customer-details .info-label {
    flex-shrink: 0;
  }

  .page-customer-details .info-value {
    min-width: 0;
  }

  .page-customer-details .warranty-btn {
    min-height: 40px;
    padding: 8px 14px;
  }

  .page-customer-details .footer button {
    min-height: 42px;
    padding: 8px 32px;
  }

  /* =========================================================
     FULL CALL HISTORY (full-calls.html)
     ========================================================= */
  .page-full-calls .main {
    margin-left: 0;
    padding: 16px;
  }

  .page-full-calls .sidebar h2 {
    margin-bottom: 28px;
  }

  .page-full-calls .header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 16px;
  }

  .page-full-calls .header h1 {
    font-size: 22px;
  }

  .page-full-calls .search-filter {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .page-full-calls .search-filter input {
    grid-column: 1 / -1;
  }

  .page-full-calls .search-filter input,
  .page-full-calls .search-filter select,
  .page-full-calls .search-filter button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }

  .page-full-calls .m-stats .total-box {
    grid-column: 1 / -1;
    text-align: center;
  }

  /* 1 Date & Time, 2 Name, 3 Number, 4 Type, 5 Status */
  .page-full-calls #callTable tr {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "name name"
      "number number"
      "datetime datetime"
      "type status";
  }

  .page-full-calls #callTable td:nth-child(1) { grid-area: datetime; }
  .page-full-calls #callTable td:nth-child(2) { grid-area: name; font-size: 17px; font-weight: bold; }
  .page-full-calls #callTable td:nth-child(3) { grid-area: number; }
  .page-full-calls #callTable td:nth-child(4) { grid-area: type; }
  .page-full-calls #callTable td:nth-child(5) { grid-area: status; }

  .page-full-calls #callTable td:nth-child(1)::before { content: "Date & Time"; }
  .page-full-calls #callTable td:nth-child(3)::before { content: "Number"; }
  .page-full-calls #callTable td:nth-child(4)::before { content: "Type"; }
  .page-full-calls #callTable td:nth-child(5)::before { content: "Status"; }

  .page-full-calls .load-more {
    width: 100%;
    min-height: 46px;
  }

  /* =========================================================
     STAFF REPORT (staff-report.html)
     ========================================================= */
  body.page-staff-report {
    padding: 16px;
  }

  .page-staff-report h1 {
    font-size: 22px;
    margin: 4px 0 12px;
  }

  .page-staff-report #summary {
    font-size: 15px;
    line-height: 1.5;
    background: transparent;
    border: 1px solid #1c2a44;
    border-radius: 10px;
    padding: 12px;
  }

  /* 1 Staff, 2 Total, 3 Answered, 4 Missed, 5 Success */
  .page-staff-report #staffTable tr {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas:
      "staff staff staff staff"
      "total answered missed success";
    background: transparent;
    border-color: #1c2a44;
  }

  .page-staff-report #staffTable td:nth-child(1) { grid-area: staff; font-size: 17px; font-weight: bold; }
  .page-staff-report #staffTable td:nth-child(2) { grid-area: total; }
  .page-staff-report #staffTable td:nth-child(3) { grid-area: answered; }
  .page-staff-report #staffTable td:nth-child(4) { grid-area: missed; }
  .page-staff-report #staffTable td:nth-child(5) { grid-area: success; }

  .page-staff-report #staffTable td:nth-child(2)::before { content: "Total"; }
  .page-staff-report #staffTable td:nth-child(3)::before { content: "Answered"; }
  .page-staff-report #staffTable td:nth-child(4)::before { content: "Missed"; }
  .page-staff-report #staffTable td:nth-child(5)::before { content: "Success"; }

  .page-staff-report #staffTable td:nth-child(n+2)::before {
    font-size: 10px;
    letter-spacing: 0;
  }

  /* =========================================================
     PRODUCTS (products.html)
     ========================================================= */
  .page-products .layout {
    display: block;
    min-height: 0;
  }

  .page-products .main {
    padding: 16px;
  }

  .page-products h1 {
    font-size: 22px;
    margin: 4px 0 14px;
  }

  .page-products .sidebar a {
    padding: 6px 0;
  }

  .page-products .form-card {
    flex-direction: column;
    margin-bottom: 20px;
  }

  .page-products .form-card input {
    width: 100%;
    box-sizing: border-box;
    min-height: 46px;
  }

  .page-products .form-card button {
    min-height: 46px;
    font-size: 15px;
  }

  .page-products .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .page-products .card {
    height: auto;
    min-height: 240px;
    gap: 8px;
  }

  /* Show long product names in full instead of cutting them off */
  .page-products .card h3 {
    height: auto;
    min-height: 40px;
    overflow: visible;
    overflow-wrap: anywhere;
  }

  .page-products .card img {
    width: 100%;
    max-width: 120px;
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .page-products .card button {
    min-height: 40px;
    width: 100%;
  }
}
