/* ============================================================
   MOBILE.CSS — Responsive Overrides
============================================================ */

@media (max-width: 1024px) {
  .form-row { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

@media (max-width: 768px) {
  #sidebar                { display: none; }
  #sidebar.mobile-open    { display: flex; position: fixed; height: 100%; z-index: 200; }
  #page-content           { padding: 12px; }
  .page-header            { flex-direction: column; align-items: flex-start; }
  .modal                  { max-width: 100%; margin: 0; border-radius: var(--radius) var(--radius) 0 0; }
  #modal-overlay          { align-items: flex-end; padding: 0; }
  .form-row               { grid-template-columns: 1fr; }
  .table-toolbar          { flex-direction: column; align-items: flex-start; }
  #toast-container        { bottom: 10px; right: 10px; left: 10px; }
  .toast                  { min-width: unset; max-width: 100%; }
}

@media (max-width: 480px) {
  .btn-group              { flex-direction: column; }
  .search-bar             { flex-direction: column; }
  .search-input           { width: 100%; }
  .pagination             { flex-wrap: wrap; }
}

/* ============================================================
   M-PAGE STYLES — for #m/* mobile-specific pages (Phase 3A+)
============================================================ */

/* ============================================================
   MOBILE.CSS — styles for #m/* pages
   Loaded site-wide but scoped to body.m or .m-page so it never
   accidentally affects the desktop layout.
============================================================ */

/* When body has class 'm', hide the desktop sidebar and topbar entirely */
body.m #sidebar,
body.m #topbar {
  display: none !important;
}
body.m #main {
  margin-left: 0 !important;
  padding: 0 !important;
}
body.m #page-content {
  padding: 0 !important;
}

/* Mobile page wrapper — owns the whole viewport */
.m-page {
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  padding: 0;
}

/* Sticky header bar (shows quote number + close button) */
.m-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 17px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.m-topbar .m-back {
  background: transparent;
  color: #fff;
  border: none;
  font-size: 22px;
  padding: 4px 8px;
  cursor: pointer;
  line-height: 1;
}
.m-topbar .m-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
}

/* Status pill */
.m-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* Summary card on mobile pages */
.m-summary {
  background: var(--card-bg, var(--bg-elev));
  margin: 12px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.m-summary .m-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 15px;
}
.m-summary .m-row:last-child { border-bottom: none; }
.m-summary .m-row .m-label {
  color: var(--text-muted);
  font-size: 14px;
}
.m-summary .m-row .m-value {
  font-weight: 600;
  text-align: right;
}
.m-summary .m-amount {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  padding: 16px 0 8px 0;
}
.m-summary .m-client {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 4px;
}
.m-summary .m-quote-num {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* PDF view button */
.m-pdf-btn {
  display: block;
  width: calc(100% - 24px);
  margin: 12px 12px;
  padding: 16px;
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--accent);
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
}
.m-pdf-btn:active {
  background: var(--bg-hover);
}

/* Inline PDF embed area (optional — shown on big enough phones) */
.m-pdf-embed {
  margin: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
.m-pdf-embed iframe {
  width: 100%;
  height: 60vh;
  border: 0;
  display: block;
}

/* Action buttons — full-width, stacked, big tap target */
.m-actions {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.m-btn {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  border: none;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  min-height: 52px;
}
.m-btn-approve {
  background: #10b981;
  color: #fff;
}
.m-btn-approve:active { background: #059669; }
.m-btn-reject {
  background: #ef4444;
  color: #fff;
}
.m-btn-reject:active { background: #dc2626; }
.m-btn-secondary {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
}
.m-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Spinner area when loading */
.m-loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

/* Error / empty state */
.m-error {
  margin: 24px 12px;
  padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--text-muted);
}

/* ============================================================
   M-INBOX — listing cards (Phase 3C-1)
============================================================ */

.m-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 12px 16px 8px 16px;
  margin: 0;
}
.m-section-count {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
  letter-spacing: 0;
}
.m-section-empty {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 24px 16px;
  margin: 0 16px;
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.m-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 8px 12px;
  padding: 14px;
  background: var(--card-bg, var(--bg-elev));
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none !important;
  color: inherit;
  cursor: pointer;
}
.m-card:active { background: var(--bg-hover); }

.m-card-pending { border-left: 4px solid var(--accent); }

.m-card-icon {
  flex: 0 0 auto;
  font-size: 22px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev);
  border-radius: 10px;
}

.m-card-body { flex: 1; min-width: 0; }

.m-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.m-card-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-card-amount {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  white-space: nowrap;
}

.m-card-sub {
  font-size: 14px;
  color: var(--text);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-card-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.m-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-elev);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.m-pill-good { background: rgba(16,185,129,0.15); color: #10b981; border-color: rgba(16,185,129,0.3); }
.m-pill-bad  { background: rgba(239,68,68,0.15);  color: #ef4444; border-color: rgba(239,68,68,0.3); }
.m-pill-warn { background: rgba(245,158,11,0.15); color: #f59e0b; border-color: rgba(245,158,11,0.3); }

.m-card-when {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================
   PHONE-WIDTH HAMBURGER (Phase 3C-2 fix)
   The button #mobile-menu-btn has inline `display:none`. Override it
   on phone width so the sidebar can be reached when on the desktop
   dashboard view.
============================================================ */
@media (max-width: 768px) {
  #mobile-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    padding: 6px 10px;
    border-radius: 8px;
  }
  #mobile-menu-btn:active { background: var(--bg-hover); }

  /* Make the topbar wrap reasonably on small screens */
  #topbar { flex-wrap: wrap; gap: 4px; padding-left: 8px; padding-right: 8px; }

  /* The original mobile.css set `position:fixed` but didn't anchor
     the sidebar to top-left — so it appeared off-screen. Pin it
     properly when open. */
  #sidebar.mobile-open {
    top: 0;
    left: 0;
    width: 260px;
    max-width: 80vw;
    box-shadow: 2px 0 12px rgba(0,0,0,0.3);
  }
}

/* Mobile mode (body.m) hides the hamburger entirely — the m-page
   has its own navigation. */
body.m #mobile-menu-btn { display: none !important; }
