/*
 * Design System Utilities
 * ======================
 * Bridge layer: maps design tokens to semantic CSS classes.
 * Use these classes instead of inline styles in Blade templates.
 *
 * Token source: resources/views/layouts/partials/design-tokens.blade.php
 * Dependencies: design-tokens must load before this file.
 *
 * Naming: .ds-{category}-{variant}
 *   .ds-card        — surface card with border, radius, shadow
 *   .ds-badge-*     — status badges (success, danger, warning, info, muted)
 *   .ds-icon-badge  — 48px icon container (setup wizards, dashboards)
 *   .ds-section     — content section with padding + border-bottom
 *   .ds-text-*      — semantic text styles
 *   .ds-bg-*        — semantic background fills
 */

/* ==========================================================================
   CARDS — Replace inline: background:#fff; border-radius:12px; border:1px solid #e5e7eb; box-shadow:...
   143+ occurrences across templates
   ========================================================================== */

.ds-card {
    background: #fff;
    border: 1px solid var(--app-color-border, #e5e7eb);
    border-radius: var(--ds-radius-lg, 0.75rem);
    box-shadow: var(--ds-shadow-sm, 0 1px 2px 0 rgba(0, 0, 0, 0.05));
    overflow: hidden;
}

.ds-card-hover {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.ds-card-hover:hover {
    box-shadow: var(--ds-shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
    transform: translateY(-2px);
}

/* Card padding variants */
.ds-card-body {
    padding: var(--ds-spacing-4, 1rem);
}

.ds-card-body-lg {
    padding: var(--ds-spacing-6, 1.5rem);
}

.ds-card-body-sm {
    padding: var(--ds-spacing-3, 0.75rem);
}

/* Card header — icon + title + optional actions */
.ds-card-header {
    display: flex;
    align-items: center;
    gap: var(--ds-spacing-3, 0.75rem);
    padding: var(--ds-spacing-4, 1rem);
    border-bottom: 1px solid var(--app-color-border, #e5e7eb);
    font-weight: var(--ds-font-weight-semibold, 600);
    font-size: var(--ds-font-size-base, 1rem);
    color: var(--app-color-text-primary, #111827);
}

.ds-card-header .ds-card-actions {
    margin-inline-start: auto;
}

/* Card footer */
.ds-card-footer {
    padding: var(--ds-spacing-3, 0.75rem) var(--ds-spacing-4, 1rem);
    border-top: 1px solid var(--app-color-border, #e5e7eb);
    background: var(--ds-color-gray-50, #f9fafb);
}


/* ==========================================================================
   STATUS BADGES — Replace inline: padding:3px 10px; border-radius:12px; background:#d1fae5; color:#065f46;
   123 occurrences across 39 files
   ========================================================================== */

.ds-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.625rem;
    border-radius: var(--ds-radius-full, 9999px);
    font-size: var(--ds-font-size-xs, 0.75rem);
    font-weight: var(--ds-font-weight-medium, 500);
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
}

.ds-badge-success {
    background: #dcfce7;
    color: #166534;
}

.ds-badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.ds-badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.ds-badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.ds-badge-muted {
    background: var(--ds-color-gray-100, #f3f4f6);
    color: var(--ds-color-gray-600, #4b5563);
}

.ds-badge-primary {
    background: #e0e7ff;
    color: #3730a3;
}

/* Dot indicator variant: small colored dot before text */
.ds-badge-dot::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ds-badge-success.ds-badge-dot::before { background: #16a34a; }
.ds-badge-danger.ds-badge-dot::before  { background: #dc2626; }
.ds-badge-warning.ds-badge-dot::before { background: #d97706; }
.ds-badge-info.ds-badge-dot::before    { background: #2563eb; }
.ds-badge-muted.ds-badge-dot::before   { background: #9ca3af; }
.ds-badge-primary.ds-badge-dot::before { background: #4f46e5; }


/* ==========================================================================
   ICON BADGES — Replace inline: width:48px; height:48px; border-radius:12px; display:flex;
                  align-items:center; justify-content:center; font-size:18px;
   9+ identical patterns in setup wizards, dashboards
   ========================================================================== */

.ds-icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: var(--ds-radius-lg, 0.75rem);
    font-size: 1.125rem;
    font-weight: var(--ds-font-weight-bold, 700);
    flex-shrink: 0;
}

.ds-icon-badge-sm {
    width: 36px;
    min-width: 36px;
    height: 36px;
    font-size: 0.875rem;
    border-radius: var(--ds-radius-md, 0.5rem);
}

.ds-icon-badge-lg {
    width: 56px;
    min-width: 56px;
    height: 56px;
    font-size: 1.375rem;
    border-radius: var(--ds-radius-xl, 1rem);
}

/* Semantic color fills for icon badges */
.ds-icon-badge-success { background: #dcfce7; color: #166534; }
.ds-icon-badge-danger  { background: #fee2e2; color: #991b1b; }
.ds-icon-badge-warning { background: #fef3c7; color: #92400e; }
.ds-icon-badge-info    { background: #dbeafe; color: #1e40af; }
.ds-icon-badge-primary { background: #e0e7ff; color: #3730a3; }
.ds-icon-badge-muted   { background: var(--ds-color-gray-100, #f3f4f6); color: var(--ds-color-gray-600, #4b5563); }
.ds-icon-badge-purple  { background: #f3e8ff; color: #6b21a8; }


/* ==========================================================================
   SECTION CARDS — For grouped content areas (settings, form sections)
   iPhone-Settings-style grouped sections
   ========================================================================== */

.ds-section {
    background: #fff;
    border: 1px solid var(--app-color-border, #e5e7eb);
    border-radius: var(--ds-radius-lg, 0.75rem);
    overflow: hidden;
}

.ds-section-header {
    padding: var(--ds-spacing-3, 0.75rem) var(--ds-spacing-4, 1rem);
    font-size: var(--ds-font-size-sm, 0.875rem);
    font-weight: var(--ds-font-weight-semibold, 600);
    color: var(--app-color-text-secondary, #4b5563);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    background: var(--ds-color-gray-50, #f9fafb);
    border-bottom: 1px solid var(--app-color-border, #e5e7eb);
}

.ds-section-row {
    display: flex;
    align-items: center;
    gap: var(--ds-spacing-3, 0.75rem);
    padding: var(--ds-spacing-3, 0.75rem) var(--ds-spacing-4, 1rem);
    border-bottom: 1px solid var(--ds-color-gray-100, #f3f4f6);
    min-height: 44px; /* WCAG touch target */
}

.ds-section-row:last-child {
    border-bottom: none;
}

.ds-section-row-label {
    flex: 1;
    font-size: var(--ds-font-size-sm, 0.875rem);
    color: var(--app-color-text-primary, #111827);
}

.ds-section-row-value {
    font-size: var(--ds-font-size-sm, 0.875rem);
    color: var(--app-color-text-secondary, #4b5563);
}


/* ==========================================================================
   STAT CARDS — KPI / metric display (dashboards, reports)
   ========================================================================== */

.ds-stat {
    display: flex;
    align-items: center;
    gap: var(--ds-spacing-4, 1rem);
    padding: var(--ds-spacing-4, 1rem) var(--ds-spacing-6, 1.5rem);
}

.ds-stat-value {
    font-size: var(--ds-font-size-2xl, 1.5rem);
    font-weight: var(--ds-font-weight-bold, 700);
    color: var(--app-color-text-primary, #111827);
    line-height: var(--ds-line-height-tight, 1.25);
}

.ds-stat-label {
    font-size: var(--ds-font-size-sm, 0.875rem);
    color: var(--app-color-text-secondary, #4b5563);
    font-weight: var(--ds-font-weight-medium, 500);
}

.ds-stat-change {
    font-size: var(--ds-font-size-xs, 0.75rem);
    font-weight: var(--ds-font-weight-medium, 500);
}

.ds-stat-change-up   { color: #16a34a; }
.ds-stat-change-down { color: #dc2626; }


/* ==========================================================================
   TEXT UTILITIES — Semantic text colors mapped to tokens
   ========================================================================== */

.ds-text-primary   { color: var(--app-color-text-primary, #111827) !important; }
.ds-text-secondary { color: var(--app-color-text-secondary, #4b5563) !important; }
.ds-text-muted     { color: var(--app-color-text-tertiary, #6b7280) !important; }
.ds-text-success   { color: var(--ds-color-success-700, #067647) !important; }
.ds-text-danger    { color: var(--ds-color-danger-700, #b42318) !important; }
.ds-text-warning   { color: var(--ds-color-warning-700, #b54708) !important; }
.ds-text-info      { color: var(--ds-color-info-700, #026aa2) !important; }

/* Font sizes */
.ds-text-xs   { font-size: var(--ds-font-size-xs, 0.75rem) !important; }
.ds-text-sm   { font-size: var(--ds-font-size-sm, 0.875rem) !important; }
.ds-text-base { font-size: var(--ds-font-size-base, 1rem) !important; }
.ds-text-lg   { font-size: var(--ds-font-size-lg, 1.125rem) !important; }
.ds-text-xl   { font-size: var(--ds-font-size-xl, 1.25rem) !important; }
.ds-text-2xl  { font-size: var(--ds-font-size-2xl, 1.5rem) !important; }

/* Font weights */
.ds-font-normal   { font-weight: var(--ds-font-weight-normal, 400) !important; }
.ds-font-medium   { font-weight: var(--ds-font-weight-medium, 500) !important; }
.ds-font-semibold { font-weight: var(--ds-font-weight-semibold, 600) !important; }
.ds-font-bold     { font-weight: var(--ds-font-weight-bold, 700) !important; }


/* ==========================================================================
   BACKGROUND UTILITIES — Semantic surface colors
   ========================================================================== */

.ds-bg-surface  { background-color: var(--ds-color-gray-50, #f9fafb) !important; }
.ds-bg-white    { background-color: #fff !important; }
.ds-bg-success  { background-color: #dcfce7 !important; }
.ds-bg-danger   { background-color: #fee2e2 !important; }
.ds-bg-warning  { background-color: #fef3c7 !important; }
.ds-bg-info     { background-color: #dbeafe !important; }
.ds-bg-muted    { background-color: var(--ds-color-gray-100, #f3f4f6) !important; }
.ds-bg-primary  { background-color: #e0e7ff !important; }


/* ==========================================================================
   BORDER UTILITIES — Common border patterns
   ========================================================================== */

.ds-border       { border: 1px solid var(--app-color-border, #e5e7eb) !important; }
.ds-border-b     { border-bottom: 1px solid var(--app-color-border, #e5e7eb) !important; }
.ds-border-t     { border-top: 1px solid var(--app-color-border, #e5e7eb) !important; }
.ds-border-light { border: 1px solid var(--ds-color-gray-100, #f3f4f6) !important; }

/* Border radius */
.ds-rounded-sm   { border-radius: var(--ds-radius-sm, 0.25rem) !important; }
.ds-rounded      { border-radius: var(--ds-radius-base, 0.375rem) !important; }
.ds-rounded-md   { border-radius: var(--ds-radius-md, 0.5rem) !important; }
.ds-rounded-lg   { border-radius: var(--ds-radius-lg, 0.75rem) !important; }
.ds-rounded-xl   { border-radius: var(--ds-radius-xl, 1rem) !important; }
.ds-rounded-full { border-radius: var(--ds-radius-full, 9999px) !important; }


/* ==========================================================================
   SHADOW UTILITIES
   ========================================================================== */

.ds-shadow-none { box-shadow: none !important; }
.ds-shadow-sm   { box-shadow: var(--ds-shadow-sm, 0 1px 2px 0 rgba(0, 0, 0, 0.05)) !important; }
.ds-shadow      { box-shadow: var(--ds-shadow-base, 0 1px 3px 0 rgba(0, 0, 0, 0.1)) !important; }
.ds-shadow-md   { box-shadow: var(--ds-shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1)) !important; }
.ds-shadow-lg   { box-shadow: var(--ds-shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1)) !important; }


/* ==========================================================================
   SPACING UTILITIES — Gap, padding, margin mapped to token scale
   ========================================================================== */

.ds-gap-1  { gap: var(--ds-spacing-1, 0.25rem) !important; }
.ds-gap-2  { gap: var(--ds-spacing-2, 0.5rem) !important; }
.ds-gap-3  { gap: var(--ds-spacing-3, 0.75rem) !important; }
.ds-gap-4  { gap: var(--ds-spacing-4, 1rem) !important; }
.ds-gap-6  { gap: var(--ds-spacing-6, 1.5rem) !important; }
.ds-gap-8  { gap: var(--ds-spacing-8, 2rem) !important; }

.ds-p-0  { padding: 0 !important; }
.ds-p-2  { padding: var(--ds-spacing-2, 0.5rem) !important; }
.ds-p-3  { padding: var(--ds-spacing-3, 0.75rem) !important; }
.ds-p-4  { padding: var(--ds-spacing-4, 1rem) !important; }
.ds-p-6  { padding: var(--ds-spacing-6, 1.5rem) !important; }
.ds-p-8  { padding: var(--ds-spacing-8, 2rem) !important; }

.ds-px-4 { padding-inline: var(--ds-spacing-4, 1rem) !important; }
.ds-px-6 { padding-inline: var(--ds-spacing-6, 1.5rem) !important; }
.ds-py-2 { padding-block: var(--ds-spacing-2, 0.5rem) !important; }
.ds-py-3 { padding-block: var(--ds-spacing-3, 0.75rem) !important; }
.ds-py-4 { padding-block: var(--ds-spacing-4, 1rem) !important; }

.ds-mb-4 { margin-bottom: var(--ds-spacing-4, 1rem) !important; }
.ds-mb-6 { margin-bottom: var(--ds-spacing-6, 1.5rem) !important; }
.ds-mt-4 { margin-top: var(--ds-spacing-4, 1rem) !important; }


/* ==========================================================================
   LAYOUT HELPERS
   ========================================================================== */

.ds-flex        { display: flex !important; }
.ds-flex-col    { display: flex !important; flex-direction: column !important; }
.ds-items-center { align-items: center !important; }
.ds-justify-between { justify-content: space-between !important; }

.ds-grid        { display: grid !important; }
.ds-grid-cards  { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)) !important; gap: var(--ds-spacing-4, 1rem) !important; }
.ds-grid-stats  { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important; gap: var(--ds-spacing-4, 1rem) !important; }


/* ==========================================================================
   EMPTY STATE — Consistent "no data" pattern
   ========================================================================== */

.ds-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--ds-spacing-12, 3rem) var(--ds-spacing-4, 1rem);
    text-align: center;
    color: var(--app-color-text-tertiary, #6b7280);
}

.ds-empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: var(--ds-spacing-4, 1rem);
    opacity: 0.5;
}

.ds-empty-state-title {
    font-size: var(--ds-font-size-base, 1rem);
    font-weight: var(--ds-font-weight-medium, 500);
    color: var(--app-color-text-secondary, #4b5563);
    margin: 0 0 var(--ds-spacing-2, 0.5rem);
}

.ds-empty-state-text {
    font-size: var(--ds-font-size-sm, 0.875rem);
    margin: 0 0 var(--ds-spacing-6, 1.5rem);
    max-width: 320px;
}


/* ==========================================================================
   WIZARD STEPS — Consistent step indicator pattern
   6+ different implementations across templates
   ========================================================================== */

.ds-wizard-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-spacing-2, 0.5rem);
    padding: var(--ds-spacing-4, 1rem) 0;
    margin-bottom: var(--ds-spacing-6, 1.5rem);
}

.ds-wizard-step {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-spacing-2, 0.5rem);
    padding: var(--ds-spacing-2, 0.5rem) var(--ds-spacing-4, 1rem);
    border-radius: var(--ds-radius-full, 9999px);
    font-size: var(--ds-font-size-sm, 0.875rem);
    font-weight: var(--ds-font-weight-medium, 500);
    background: var(--ds-color-gray-100, #f3f4f6);
    color: var(--ds-color-gray-500, #6b7280);
    cursor: default;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ds-wizard-step.active {
    background: #e0e7ff;
    color: #4338ca;
    font-weight: var(--ds-font-weight-semibold, 600);
}

.ds-wizard-step.done {
    background: #dcfce7;
    color: #166534;
    cursor: pointer;
}

.ds-wizard-step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: var(--ds-font-size-xs, 0.75rem);
    font-weight: var(--ds-font-weight-bold, 700);
    background: rgba(0, 0, 0, 0.1);
}

.ds-wizard-step.active .ds-wizard-step-number {
    background: #4338ca;
    color: #fff;
}

.ds-wizard-step.done .ds-wizard-step-number {
    background: #16a34a;
    color: #fff;
}

.ds-wizard-connector {
    width: 32px;
    height: 2px;
    background: var(--ds-color-gray-200, #e5e7eb);
    flex-shrink: 0;
}

.ds-wizard-connector.done {
    background: #16a34a;
}


/* ==========================================================================
   KEBAB MENU — 3-dot action menu for cards
   ========================================================================== */

.ds-kebab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--ds-radius-md, 0.5rem);
    cursor: pointer;
    color: var(--ds-color-gray-400, #9ca3af);
    transition: all 0.15s ease;
    border: none;
    background: transparent;
    padding: 0;
}

.ds-kebab:hover {
    background: var(--ds-color-gray-100, #f3f4f6);
    color: var(--ds-color-gray-700, #374151);
}


/* ==========================================================================
   DARK MODE OVERRIDES
   ========================================================================== */

html[data-ui-theme="dark"] .ds-card,
html[data-ui-theme="dark"] .ds-section {
    background: #1f2937;
    border-color: rgba(255, 255, 255, 0.1);
}

html[data-ui-theme="dark"] .ds-card-header {
    border-color: rgba(255, 255, 255, 0.1);
    color: #e5e7eb;
}

html[data-ui-theme="dark"] .ds-card-footer {
    background: #111827;
    border-color: rgba(255, 255, 255, 0.1);
}

html[data-ui-theme="dark"] .ds-section-header {
    background: #111827;
    border-color: rgba(255, 255, 255, 0.1);
    color: #9ca3af;
}

html[data-ui-theme="dark"] .ds-section-row {
    border-color: rgba(255, 255, 255, 0.06);
}

html[data-ui-theme="dark"] .ds-section-row-label { color: #e5e7eb; }
html[data-ui-theme="dark"] .ds-section-row-value { color: #9ca3af; }

html[data-ui-theme="dark"] .ds-stat-value { color: #e5e7eb; }
html[data-ui-theme="dark"] .ds-stat-label { color: #9ca3af; }

html[data-ui-theme="dark"] .ds-empty-state { color: #6b7280; }
html[data-ui-theme="dark"] .ds-empty-state-title { color: #9ca3af; }

html[data-ui-theme="dark"] .ds-wizard-step {
    background: #374151;
    color: #9ca3af;
}

html[data-ui-theme="dark"] .ds-wizard-step.active {
    background: #312e81;
    color: #a5b4fc;
}

html[data-ui-theme="dark"] .ds-wizard-step.done {
    background: #14532d;
    color: #86efac;
}

html[data-ui-theme="dark"] .ds-wizard-connector {
    background: #374151;
}

html[data-ui-theme="dark"] .ds-kebab:hover {
    background: #374151;
    color: #e5e7eb;
}

/* Dark mode badge variants */
html[data-ui-theme="dark"] .ds-badge-success { background: #14532d; color: #86efac; }
html[data-ui-theme="dark"] .ds-badge-danger  { background: #7f1d1d; color: #fca5a5; }
html[data-ui-theme="dark"] .ds-badge-warning { background: #78350f; color: #fcd34d; }
html[data-ui-theme="dark"] .ds-badge-info    { background: #1e3a5f; color: #93c5fd; }
html[data-ui-theme="dark"] .ds-badge-muted   { background: #374151; color: #9ca3af; }
html[data-ui-theme="dark"] .ds-badge-primary { background: #312e81; color: #a5b4fc; }

html[data-ui-theme="dark"] .ds-icon-badge-success { background: #14532d; color: #86efac; }
html[data-ui-theme="dark"] .ds-icon-badge-danger  { background: #7f1d1d; color: #fca5a5; }
html[data-ui-theme="dark"] .ds-icon-badge-warning { background: #78350f; color: #fcd34d; }
html[data-ui-theme="dark"] .ds-icon-badge-info    { background: #1e3a5f; color: #93c5fd; }
html[data-ui-theme="dark"] .ds-icon-badge-primary { background: #312e81; color: #a5b4fc; }
html[data-ui-theme="dark"] .ds-icon-badge-muted   { background: #374151; color: #9ca3af; }
html[data-ui-theme="dark"] .ds-icon-badge-purple  { background: #3b0764; color: #d8b4fe; }

/* Dark mode background utilities */
html[data-ui-theme="dark"] .ds-bg-surface  { background-color: #1f2937 !important; }
html[data-ui-theme="dark"] .ds-bg-white    { background-color: #1f2937 !important; }
html[data-ui-theme="dark"] .ds-bg-success  { background-color: #14532d !important; }
html[data-ui-theme="dark"] .ds-bg-danger   { background-color: #7f1d1d !important; }
html[data-ui-theme="dark"] .ds-bg-warning  { background-color: #78350f !important; }
html[data-ui-theme="dark"] .ds-bg-info     { background-color: #1e3a5f !important; }
html[data-ui-theme="dark"] .ds-bg-muted    { background-color: #374151 !important; }
html[data-ui-theme="dark"] .ds-bg-primary  { background-color: #312e81 !important; }

/* Dark mode empty state */
html[data-ui-theme="dark"] .ds-empty-state-icon { opacity: 0.4; }


/* ==========================================================================
   RTL ADJUSTMENTS
   ========================================================================== */

html[dir="rtl"] .ds-card-header .ds-card-actions {
    margin-inline-start: auto;
    margin-inline-end: 0;
}


/* **************************************************************************
 * RESPONSIVE ADAPTATION LAYER
 * Global responsive fixes that affect every page in the system.
 * ************************************************************************** */


/* ==========================================================================
   SIDEBAR — Mobile drawer fix
   The sidebar has inline style="display:flex" which breaks responsive hiding.
   JS already toggles .small-view-side-active + .overlay on hamburger click.
   This CSS makes it a proper off-canvas drawer on < 992px.
   ========================================================================== */

@media (max-width: 991px) {
    /* Hide sidebar by default on mobile/tablet — override inline style */
    .side-bar {
        display: none !important;
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px !important;
        max-width: 85vw;
        z-index: 1050;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        transition: transform 0.25s ease;
    }

    /* When toggled open via JS */
    .side-bar.small-view-side-active {
        display: flex !important;
        flex-direction: column;
    }

    /* Overlay behind sidebar */
    .overlay {
        z-index: 1040 !important;
    }

    /* Give main content full width */
    .thetop > main {
        width: 100% !important;
    }
}

/* RTL sidebar: slide from right */
@media (max-width: 991px) {
    html[dir="rtl"] .side-bar {
        left: auto;
        right: 0;
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    }
}


/* ==========================================================================
   MODALS — Responsive sizing
   modal-lg (900px) and modal-xl (1140px) are unusable on phones.
   Force them to near-full-width on small screens.
   ========================================================================== */

@media (max-width: 767px) {
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        width: calc(100vw - 20px) !important;
        max-width: none !important;
        margin: 10px auto !important;
    }

    /* Limit modal height so content scrolls instead of page */
    .modal-dialog.modal-lg .modal-body,
    .modal-dialog.modal-xl .modal-body {
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Shrink modal header padding on mobile */
    .modal-header {
        padding: 12px 16px;
    }

    .modal-body {
        padding: 12px 16px;
    }

    .modal-footer {
        padding: 8px 16px;
    }

    /* Modal title smaller on mobile */
    .modal-title {
        font-size: 1rem;
    }
}

/* Tablet: modal-xl gets reduced to near-lg width */
@media (min-width: 768px) and (max-width: 991px) {
    .modal-dialog.modal-xl {
        width: calc(100vw - 40px) !important;
        max-width: 900px !important;
    }
}


/* ==========================================================================
   TOUCH TARGETS — 44px minimum for all interactive elements
   WCAG 2.1 AA / Apple HIG touch target requirement
   ========================================================================== */

/* Buttons: ensure minimum touch target */
.btn,
.ds-badge[onclick],
.ds-badge[role="button"],
a.ds-badge {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Exception: buttons inside DataTable rows and dense lists can be smaller */
.modern-dt-card .btn,
.table .btn,
.btn-group .btn {
    min-height: 36px;
    min-width: 36px;
}

/* btn-xs: increase to 36px minimum (was ~22px) */
.btn-xs {
    min-height: 36px !important;
    min-width: 36px !important;
    padding: 4px 10px !important;
    font-size: 12px !important;
}

/* Form controls: minimum height */
.form-control,
.select2-container .select2-selection--single,
.select2-container .select2-selection--multiple {
    min-height: 44px !important;
}

/* === Light mode form input fix (034) === */
html:not([data-ui-theme-mode="dark"]) .form-control,
html:not([data-ui-theme="dark"]) .form-control {
    background-color: #fff;
    color: #333;
    border-color: #d2d6de;
}
html:not([data-ui-theme-mode="dark"]) .select2-container--default .select2-selection--single,
html:not([data-ui-theme-mode="dark"]) .select2-container--default .select2-selection--multiple {
    background-color: #fff;
    color: #333;
    border-color: #d2d6de;
}

/* Dropdown menu items: 44px minimum touch target */
.dropdown-menu > li > a {
    padding: 10px 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* Sidebar links: touch-friendly spacing */
@media (max-width: 991px) {
    .side-bar .treeview-menu > li > a,
    .side-bar .sidebar-menu > li > a {
        padding: 12px 16px !important;
        min-height: 44px;
    }
}

/* Checkbox/radio: increase clickable area */
input[type="checkbox"],
input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
}


/* ==========================================================================
   TABLES — Make tables scrollable on mobile by default
   ========================================================================== */

@media (max-width: 767px) {
    /* Auto-wrap tables that aren't already in a responsive container */
    .box-body > .table,
    .ds-card-body > .table,
    .tab-content > .table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* DataTable wrapper scrolls on mobile */
    .dataTables_wrapper {
        overflow-x: auto;
    }

    /* Reduce DataTable button text on mobile */
    .dt-buttons .btn {
        padding: 6px 8px !important;
        font-size: 11px !important;
    }

    /* Stack DataTable controls */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: center !important;
        margin-bottom: 8px;
    }

    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
        margin-top: 8px;
    }
}


/* ==========================================================================
   FORMS — Column stacking on mobile
   ========================================================================== */

@media (max-width: 575px) {
    /* Force all Bootstrap columns to full-width on phones */
    .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6,
    .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}


/* ==========================================================================
   HEADER — Mobile compact
   ========================================================================== */

@media (max-width: 767px) {
    /* Compact header padding on mobile */
    .app-theme-header .tw-px-5 {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Hide non-essential header items on mobile */
    .app-theme-header .tw-hidden.sm\:tw-flex {
        display: none !important;
    }
}


/* ==========================================================================
   GRID CARDS — Responsive minmax adjustments
   ========================================================================== */

@media (max-width: 480px) {
    .ds-grid-cards {
        grid-template-columns: 1fr !important;
    }

    .ds-grid-stats {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 359px) {
    .ds-grid-stats {
        grid-template-columns: 1fr !important;
    }
}


/* ==========================================================================
   PRINT — Hide non-content elements
   ========================================================================== */

@media print {
    .side-bar,
    .app-theme-header,
    .overlay,
    .ds-kebab,
    .btn,
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dt-buttons,
    .no-print {
        display: none !important;
    }

    .ds-card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        break-inside: avoid;
    }

    #scrollable-container {
        overflow: visible !important;
        height: auto !important;
    }

    body, main {
        background: white !important;
    }
}


/* **************************************************************************
 * HARDENING LAYER
 * Production resilience: text overflow, reduced motion, RTL icons,
 * double-submit prevention, error recovery.
 * ************************************************************************** */


/* ==========================================================================
   TEXT OVERFLOW — Prevent Arabic (30-50% longer) from breaking layouts
   Affects: card titles, sidebar labels, table cells, KPI cards
   ========================================================================== */

/* Card titles: single-line truncate */
.box-title,
.ds-card-header,
.modal-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* Sidebar menu labels: truncate within 256px sidebar */
.side-bar .sidebar-menu > li > a,
.side-bar .treeview-menu > li > a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sidebar business name: truncate in header */
.side-bar .side-bar-heading {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

/* DataTable cells: prevent extremely long text from forcing horizontal scroll */
.table td {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Allow wrapping in specific columns that need it (descriptions, notes) */
.table td.wrap-text,
.table td[data-wrap] {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: none;
}

/* Flex item overflow prevention (critical for flex layouts) */
.ds-card-header,
.ds-section-row,
.ds-stat,
.ds-wizard-step {
    min-width: 0;
}

/* Multi-line text clamp (for card descriptions, product names in cards) */
.ds-line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ds-line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ds-line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Word break for long unbroken strings (SKUs, URLs, emails) */
.ds-break-word {
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Truncate utility */
.ds-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* ==========================================================================
   REDUCED MOTION — WCAG 2.1 AA accessibility requirement
   Zero instances existed before this. Affects all animations/transitions.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Allow essential loading spinners to still indicate "working" */
    .fa-spin,
    .fa-spinner {
        animation-duration: 2s !important;
        animation-iteration-count: infinite !important;
    }
}


/* ==========================================================================
   RTL ICON FLIPPING — Directional icons that must mirror in RTL
   51 fa-arrow-* and 5 fa-chevron-* instances not flipped before this.
   ========================================================================== */

html[dir="rtl"] .fa-arrow-left,
html[dir="rtl"] .fa-arrow-right,
html[dir="rtl"] .fa-chevron-left,
html[dir="rtl"] .fa-chevron-right,
html[dir="rtl"] .fa-arrow-circle-left,
html[dir="rtl"] .fa-arrow-circle-right,
html[dir="rtl"] .fa-long-arrow-left,
html[dir="rtl"] .fa-long-arrow-right,
html[dir="rtl"] .fa-long-arrow-alt-left,
html[dir="rtl"] .fa-long-arrow-alt-right,
html[dir="rtl"] .fa-angle-left,
html[dir="rtl"] .fa-angle-right,
html[dir="rtl"] .fa-angle-double-left,
html[dir="rtl"] .fa-angle-double-right,
html[dir="rtl"] .fa-caret-left,
html[dir="rtl"] .fa-caret-right {
    transform: scaleX(-1);
}

/* Prevent double-flip when icon is inside an already-flipped parent */
html[dir="rtl"] [style*="scaleX(-1)"] .fa-arrow-left,
html[dir="rtl"] [style*="scaleX(-1)"] .fa-arrow-right {
    transform: none;
}


/* ==========================================================================
   DOUBLE-SUBMIT PREVENTION — Visual state for disabled buttons during submit
   app.js disables buttons but never re-enables on error. This provides
   visual feedback and a CSS class for JS to toggle.
   ========================================================================== */

/* Submitting state: show spinner, reduce opacity */
.btn.is-submitting,
.btn[disabled] {
    opacity: 0.65;
    pointer-events: none;
    position: relative;
}

/* Loading spinner overlay on submitting buttons */
.btn.is-submitting::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-inline-start: 8px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ds-spin 0.6s linear infinite;
    vertical-align: middle;
}

@keyframes ds-spin {
    to { transform: rotate(360deg); }
}

/* Reduced motion: static indicator instead of spinner */
@media (prefers-reduced-motion: reduce) {
    .btn.is-submitting::after {
        animation: none;
        border-right-color: currentColor;
        opacity: 0.5;
    }
}


/* ==========================================================================
   ERROR STATES — Visual feedback for failed operations
   ========================================================================== */

/* Form field with error */
.form-control.is-invalid,
.form-control.has-error,
.has-error .form-control {
    border-color: var(--ds-color-danger-700, #b42318) !important;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12) !important;
}

/* Error message below field */
.ds-field-error {
    color: var(--ds-color-danger-700, #b42318);
    font-size: var(--ds-font-size-xs, 0.75rem);
    margin-top: var(--ds-spacing-1, 0.25rem);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Network error banner */
.ds-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--ds-color-danger-700, #b42318);
    color: white;
    text-align: center;
    padding: 8px 16px;
    font-size: var(--ds-font-size-sm, 0.875rem);
    font-weight: var(--ds-font-weight-medium, 500);
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.ds-offline-banner.active {
    transform: translateY(0);
}

/* Dark mode error states */
html[data-ui-theme="dark"] .ds-field-error {
    color: #fca5a5;
}

html[data-ui-theme="dark"] .form-control.is-invalid,
html[data-ui-theme="dark"] .form-control.has-error,
html[data-ui-theme="dark"] .has-error .form-control {
    border-color: #fca5a5 !important;
    box-shadow: 0 0 0 3px rgba(252, 165, 165, 0.12) !important;
}

/* ============================================================
   Tailwind Polyfill — Missing utilities from the compiled
   public/css/tailwind/app.css (positioning, z-index, responsive
   grid variants, a few colors). Loaded after tailwind/app.css so
   these act as a safety net for blade files that use tw-* classes
   the compiler's purge dropped.
   ============================================================ */

/* Position utilities */
.tw-fixed   { position: fixed !important; }
.tw-absolute { position: absolute !important; }
.tw-relative { position: relative !important; }
.tw-sticky  { position: sticky !important; }
.tw-static  { position: static !important; }

/* Inset shorthand (full cover) */
.tw-inset-0 { top: 0 !important; right: 0 !important; bottom: 0 !important; left: 0 !important; }
.tw-top-0    { top: 0 !important; }
.tw-right-0  { right: 0 !important; }
.tw-bottom-0 { bottom: 0 !important; }
.tw-left-0   { left: 0 !important; }

/* Z-index utilities */
.tw-z-0  { z-index: 0 !important; }
.tw-z-10 { z-index: 10 !important; }
.tw-z-20 { z-index: 20 !important; }
.tw-z-30 { z-index: 30 !important; }
.tw-z-40 { z-index: 40 !important; }
.tw-z-50 { z-index: 50 !important; }

/* Semi-transparent black backgrounds (modal overlays) */
.tw-bg-black\/50 { background-color: rgba(0, 0, 0, 0.5) !important; }
.tw-bg-black\/40 { background-color: rgba(0, 0, 0, 0.4) !important; }
.tw-bg-black\/60 { background-color: rgba(0, 0, 0, 0.6) !important; }

/* Responsive grid columns — md: (≥768px) and lg: (≥1024px) */
@media (min-width: 768px) {
    .md\:tw-grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)) !important; }
    .md\:tw-grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .md\:tw-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
    .md\:tw-grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
    .md\:tw-text-base  { font-size: 1rem !important; line-height: 1.5rem !important; }
    .md\:tw-text-lg    { font-size: 1.125rem !important; line-height: 1.75rem !important; }
    .md\:tw-text-xl    { font-size: 1.25rem !important; line-height: 1.75rem !important; }
    .md\:tw-text-2xl   { font-size: 1.5rem !important; line-height: 2rem !important; }
    .md\:tw-text-3xl   { font-size: 1.875rem !important; line-height: 2.25rem !important; }
}

@media (min-width: 1024px) {
    .lg\:tw-grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)) !important; }
    .lg\:tw-grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .lg\:tw-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
    .lg\:tw-grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
}

@media (min-width: 1280px) {
    .xl\:tw-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
    .xl\:tw-grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
}

/* Col-span for empty states */
.tw-col-span-1 { grid-column: span 1 / span 1 !important; }
.tw-col-span-2 { grid-column: span 2 / span 2 !important; }
.tw-col-span-3 { grid-column: span 3 / span 3 !important; }
.tw-col-span-full { grid-column: 1 / -1 !important; }

