/* ShopEase shared responsive layer. Page CSS may keep page-specific exceptions. */

/* 1. Global responsive rules */
html { -webkit-text-size-adjust: 100%; }
body {
    min-width: 320px;
    overflow-x: hidden;
    min-height: 100vh;
}

img, svg, canvas, video { max-width: 100%; height: auto; }
button, input, select, textarea { max-width: 100%; font: inherit; }

/* 2. Responsive typography */
@media (max-width: 767px) {
    h1 { font-size: clamp(1.45rem, 6vw, 2rem); }
    h2 { font-size: clamp(1.2rem, 5vw, 1.6rem); }
    p, label, input, select, textarea, button { font-size: max(0.875rem, 16px); }
}

/* 3. Responsive containers and layouts */
.page-container, .sales-container, .history-container, .udhar-container,
.reports-container, .expense-container, .invoice-page, .invoice-container {
    max-width: 100%;
    min-width: 0;
}
@media (max-width: 767px) {
    .page-container, .sales-container, .history-container, .udhar-container,
    .reports-container, .expense-container, .invoice-page { padding-inline: 14px; }
    .page-header, .expense-header, .table-header, .table-heading,
    .header-actions, .invoice-actions { flex-wrap: wrap; gap: 12px; }
}

/* 4. Responsive header */
@media (max-width: 480px) {
    .page-header > *, .expense-header > *, .topbar > * { min-width: 0; }
    .page-header p, .expense-header p, .topbar p { overflow-wrap: anywhere; }
}

/* 5. Responsive sidebar and navigation (dashboard adds the off-canvas behavior). */
@media (max-width: 767px) {
    .sidebar nav a, .logout-btn { min-height: 44px; }
}

/* 6. Responsive dashboard */
@media (max-width: 767px) {
    .stats-grid, .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-details-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 380px) {
    .stats-grid, .quick-grid { grid-template-columns: minmax(0, 1fr); }
}

/* 7. Responsive cards and statistics */
.table-card, .stat-card, .quick-card, .dashboard-list-card { min-width: 0; }
@media (max-width: 480px) {
    .table-card, .stat-card, .quick-card, .dashboard-list-card { border-radius: 12px; }
}

/* 8. Responsive tables */
.table-wrapper, .table-responsive, .dashboard-table-wrapper, .invoice-table-wrapper,
.expense-table-wrapper { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrapper > table, .table-responsive > table, .dashboard-table-wrapper > table,
.invoice-table-wrapper > table, .expense-table-wrapper > table { min-width: max-content; }
@media (max-width: 767px) {
    .table-responsive > table, .dashboard-table-wrapper > table,
    .invoice-table-wrapper > table { min-width: 620px; }
}

/* 9. Responsive forms and inputs */
@media (max-width: 767px) {
    .form-grid, .filter-grid, .filters-grid, .form-row { grid-template-columns: minmax(0, 1fr); }
    input:not([type="checkbox"]):not([type="radio"]), select, textarea { width: 100%; }
}

/* 10. Responsive buttons and action groups */
.modal-actions, .header-actions, .table-header, .page-header, .expense-header,
.invoice-actions { flex-wrap: wrap; }
@media (max-width: 480px) {
    .modal-actions > button, .modal-actions > a, .form-actions > button,
    .header-actions > a, .invoice-actions > a, .invoice-actions > button { flex: 1 1 auto; }
}

/* 11. Responsive modals and dialogs */
@media (max-width: 767px) {
    .modal-overlay { padding: 14px; align-items: flex-start; overflow-y: auto; }
    .modal-card { width: min(100%, 34rem); max-height: calc(100dvh - 28px); overflow-y: auto; }
}

/* 12. Responsive pagination */
.pagination, .pagination-controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* 13. Responsive images */
.logo img, .brand-logo img { object-fit: contain; }

/* 14. Responsive utility classes */
.responsive-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.responsive-stack { display: flex; flex-wrap: wrap; gap: 12px; }
@media (max-width: 480px) { .responsive-stack { flex-direction: column; } }

/* ===============================
   GLOBAL BUTTON LOADING ANIMATION
================================ */

.btn-loading {
    opacity: 0.7;
    cursor: not-allowed !important;
    pointer-events: none;
    user-select: none;
}

/* Loading spinner */
.btn-spinner {
    display: inline-block;
    width: 15px;
    height: 15px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btnSpin 0.6s linear infinite;
    vertical-align: middle;
    flex-shrink: 0;
}

/* Spinner animation */
@keyframes btnSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Loading button content alignment */
.btn-loading-content {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
