/* 4Sofit — Unified responsive card system (v1)
 * Load after reports-premium.css — overrides legacy card rules consistently.
 */

/* ── Card stacks (mobile / tablet lists) ── */
.cards-stack {
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 2.2vw, 14px);
    width: 100%;
    min-width: 0;
}

.responsive-data-list__mobile.cards-stack,
.responsive-data-list__mobile {
    min-width: 0;
}

/* Tablet: بطاقات عمودين عند عرض القائمة فقط (بدون جدول) */
@media (min-width: 600px) and (max-width: 992px) {
    .responsive-data-list__mobile.cards-stack {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
        gap: 12px;
        align-items: stretch;
    }

    .responsive-data-list__mobile.cards-stack > .list-card {
        height: 100%;
    }
}

/* ── List cards ── */
.list-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
    padding: clamp(12px, 2.5vw, 16px) clamp(14px, 3vw, 18px);
    border-radius: var(--radius-md, 14px);
    border: 1px solid var(--border, #e2e8f0);
    background: linear-gradient(165deg, var(--surface, #fff) 0%, #f8fafc 100%);
    box-shadow: var(--shadow, 0 1px 3px rgba(12, 18, 34, 0.06));
    transition:
        transform 0.18s var(--ease-out, ease),
        box-shadow 0.18s ease,
        border-color 0.18s ease;
    container-type: inline-size;
}

.list-card--clickable {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.list-card--clickable:focus-visible {
    outline: 2px solid var(--brand, #0a7b6e);
    outline-offset: 2px;
}

.list-card--clickable:active {
    transform: scale(0.985);
}

@media (hover: hover) and (pointer: fine) {
    .list-card--clickable:hover {
        border-color: rgba(10, 123, 110, 0.35);
        box-shadow: 0 4px 16px rgba(12, 18, 34, 0.08);
    }

    .stat-card-link:hover .stat-card {
        transform: translateY(-2px);
    }
}

.list-card.is-selected,
.list-card.list-card--selected {
    border-color: rgba(10, 123, 110, 0.45);
    background: linear-gradient(165deg, #f0fdfa 0%, #ecfeff 100%);
    box-shadow: 0 0 0 2px rgba(10, 123, 110, 0.14), var(--shadow);
}

.list-card--danger { border-right: 4px solid var(--danger, #dc2626); }
.list-card--warning { border-right: 4px solid var(--warning, #d97706); }
.list-card--success { border-right: 4px solid var(--success, #059669); }
.list-card--brand { border-right: 4px solid var(--brand, #0a7b6e); }

.list-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.list-card__titles {
    min-width: 0;
    flex: 1 1 auto;
}

.list-card__title {
    margin: 0;
    font-size: var(--text-base, 1rem);
    font-weight: 700;
    color: var(--text, #0c1222);
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.list-card__subtitle {
    margin: 4px 0 0;
    font-size: var(--text-xs, 0.8125rem);
    color: var(--text-muted, #5c6b7a);
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.list-card__badge {
    flex-shrink: 0;
    max-width: 48%;
}

.list-card__badge-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.list-card__select {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-min, 44px);
    min-height: var(--touch-min, 44px);
    margin: -8px;
    padding: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.list-card__select input {
    width: 20px;
    height: 20px;
    accent-color: var(--brand, #0a7b6e);
    cursor: pointer;
}

.list-card__meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 14px;
    margin: 0 0 12px;
    padding: 0;
}

.list-card-meta-item dd,
.list-card-meta-value {
    margin: 0;
    font-size: var(--text-sm, 0.875rem);
    font-weight: 600;
    color: #334155;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

/* display:contents legacy override — flex column layout */
.list-card__meta .list-card-meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.list-card__meta .list-card-meta-item dt,
.list-card-meta-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-subtle, #94a3b8);
    line-height: 1.3;
}

.list-card__highlight {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
    border-radius: var(--radius-sm, 10px);
    background: linear-gradient(135deg, #fef2f2 0%, #fff7ed 100%);
    border: 1px solid #fecaca;
    flex-wrap: wrap;
}

.list-card__highlight-label {
    font-size: var(--text-xs, 0.8125rem);
    font-weight: 600;
    color: var(--text-muted, #5c6b7a);
}

.list-card__highlight-value {
    font-size: clamp(1.05rem, 1rem + 0.4vw, 1.25rem) !important;
    font-weight: 800 !important;
    line-height: 1.2;
}

.list-card__footer {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 4px;
}

.list-card__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
}

.list-card__btn-primary,
.list-card__actions .btn {
    min-height: var(--touch-min, 44px);
    touch-action: manipulation;
}

.list-card__btn-primary {
    flex: 1 1 120px;
    justify-content: center;
}

/* Container: عمود واحد للميتا في البطاقات الضيقة */
@container (max-width: 280px) {
    .list-card__meta {
        grid-template-columns: 1fr;
    }

    .list-card__badge {
        max-width: 100%;
    }
}

/* ── Stat cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: clamp(10px, 2vw, 16px);
    margin-bottom: clamp(16px, 3vw, 24px);
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    min-height: 88px;
    padding: clamp(14px, 2.5vw, 18px) clamp(16px, 3vw, 20px);
    border-radius: var(--radius-md, 14px);
    border: 1px solid var(--border, #e2e8f0);
    background: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: var(--shadow);
    border-right: 4px solid var(--brand, #0a7b6e);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.stat-card-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--brand-light, #d1fae8);
    color: var(--brand-dark, #064e45);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-title {
    font-size: var(--text-xs, 0.8125rem);
    font-weight: 600;
    color: var(--text-muted, #5c6b7a);
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.stat-value {
    font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.625rem);
    font-weight: 800;
    line-height: 1.15;
    color: var(--text, #0c1222);
    overflow-wrap: anywhere;
}

.stat-sub {
    font-size: var(--text-xs, 0.8125rem);
    color: var(--text-subtle, #94a3b8);
    line-height: 1.35;
}

.stat-primary { border-right-color: var(--brand, #0a7b6e); }
.stat-success { border-right-color: var(--success, #059669); }
.stat-warning { border-right-color: var(--warning, #d97706); }
.stat-danger { border-right-color: var(--danger, #dc2626); }
.stat-info { border-right-color: var(--info, #0284c7); }
.stat-cyan { border-right-color: #06b6d4; }

.stat-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-md, 14px);
}

.stat-card-link:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ── Dashboard alert cards ── */
.dash-alert-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: clamp(10px, 2vw, 14px);
    margin-bottom: clamp(14px, 2.5vw, 20px);
}

.dash-alert-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: clamp(12px, 2.5vw, 16px);
    border-radius: var(--radius-md, 14px);
    border: 1px solid var(--border, #e2e8f0);
    border-right: 4px solid var(--border-strong, #cbd5e1);
    background: var(--surface, #fff);
    text-decoration: none;
    color: inherit;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
    min-height: 72px;
    touch-action: manipulation;
}

.dash-alert-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated, 0 8px 24px rgba(12, 18, 34, 0.08));
}

.dash-alert-label {
    font-size: var(--text-xs, 0.8125rem);
    font-weight: 600;
    color: var(--text-muted);
}

.dash-alert-value {
    font-size: clamp(1rem, 0.95rem + 0.35vw, 1.125rem);
    font-weight: 700;
    line-height: 1.25;
}

.dash-alert-meta {
    font-size: 11px;
    color: var(--text-subtle);
}

.dash-alert-card.has-alert {
    border-right-color: var(--warning, #d97706);
    background: linear-gradient(165deg, #fffbeb 0%, #fff 100%);
}

.dash-alert-card.has-alert.danger {
    border-right-color: var(--danger, #dc2626);
    background: linear-gradient(165deg, #fef2f2 0%, #fff 100%);
}

.dash-alert-card.is-ok {
    border-right-color: var(--success, #059669);
}

.dash-alert-card.has-alert .dash-alert-value { color: var(--num-caution, #d97706); }
.dash-alert-card.has-alert.danger .dash-alert-value { color: var(--num-negative, #dc2626); }
.dash-alert-card.is-ok .dash-alert-value { color: var(--num-positive, #059669); }

.dash-alert-card:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ── Report hub cards ── */
.reports-hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    gap: clamp(12px, 2.2vw, 16px);
}

.report-hub-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: clamp(132px, 28vw, 156px);
    border-radius: var(--radius-md, 14px);
    overflow: hidden;
    border: 1px solid var(--border, #e2e8f0);
    background: linear-gradient(155deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: var(--shadow);
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.report-hub-card--teal { border-right: 4px solid #14b8a6; }
.report-hub-card--amber { border-right: 4px solid #f59e0b; }
.report-hub-card--cyan { border-right: 4px solid #06b6d4; }
.report-hub-card--green { border-right: 4px solid #22c55e; }

.report-hub-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated, 0 10px 24px rgba(15, 23, 42, 0.08));
    border-color: #cbd5e1;
}

.report-hub-card__link {
    flex: 1 1 auto;
    min-height: var(--touch-min, 44px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: clamp(14px, 2.5vw, 16px) clamp(14px, 2.5vw, 16px) 10px;
    text-decoration: none;
    color: inherit;
}

.report-hub-card__link:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: -2px;
}

.report-hub-card__head {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    min-width: 0;
}

.report-hub-card__titles {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1 1 auto;
}

.report-hub-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.report-hub-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: #ecfeff;
    color: #0891b2;
    flex-shrink: 0;
}

.report-hub-title {
    font-size: var(--text-base, 1rem);
    font-weight: 700;
    line-height: 1.35;
    color: var(--text, #0c1222);
    overflow-wrap: anywhere;
}

.report-hub-desc {
    font-size: var(--text-xs, 0.8125rem);
    color: var(--text-muted, #5c6b7a);
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.report-hub-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    background: #f1f5f9;
    color: #64748b;
}

.report-hub-tag--pdf {
    background: #ecfeff;
    color: #0f766e;
}

.report-hub-open {
    margin-top: auto;
    font-size: 12px;
    font-weight: 700;
    color: var(--brand-dark, #064e45);
}

.report-hub-card__actions {
    display: flex;
    padding: 0 12px 12px;
    gap: 8px;
}

.report-hub-card .report-hub-pdf {
    min-height: var(--touch-min, 44px);
    flex: 1 1 auto;
    justify-content: center;
    touch-action: manipulation;
}

.reports-par-card {
    border-radius: var(--radius-md, 14px);
    padding: clamp(12px, 2vw, 16px);
    min-width: 0;
}

.stat-card-link:hover .stat-card {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated, 0 8px 24px rgba(12, 18, 34, 0.08));
}

.stat-card-link .stat-card {
    height: 100%;
}

.stats-grid.cash-sales-stats-strip {
    margin-bottom: clamp(12px, 2.5vw, 16px);
}

/* ── Form cards (responsive polish) ── */
.form-card {
    min-width: 0;
    border-radius: var(--radius-md, 14px);
}

.form-card-header {
    flex-wrap: wrap;
    gap: 12px;
}

.form-card-header-main {
    min-width: 0;
    flex: 1 1 200px;
}

.form-card-title {
    overflow-wrap: anywhere;
}

.form-card-footer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.form-card-footer-actions .btn {
    min-height: var(--touch-min, 44px);
    touch-action: manipulation;
}

.add-card-panel.page-float-card {
    min-width: 0;
    max-width: 100%;
}

/* ── Loading skeletons (card system) ── */
.loading-state-skeleton--stats .loading-skeleton-stat {
    pointer-events: none;
    border-right-width: 4px;
    border-right-style: solid;
    border-right-color: var(--border-strong, #cbd5e1);
    background: linear-gradient(145deg, #fff 0%, #f8fafc 100%);
}

.loading-state-skeleton--stats .loading-skeleton-stat .skeleton {
    border-radius: 6px;
}

.loading-state-skeleton--reports .loading-skeleton-report {
    padding: 16px;
    border: 1px solid var(--border, #e2e8f0);
    background: linear-gradient(155deg, #fff 0%, #f8fafc 100%);
    min-height: clamp(132px, 28vw, 156px);
}

.loading-state-skeleton--reports .loading-skeleton-report .skeleton {
    border-radius: 8px;
}

.page-scroll-area > .stats-grid:first-child,
.page-scroll-area > .dash-alert-grid:first-child {
    margin-top: 0;
}

.panel .stats-grid {
    margin-bottom: clamp(12px, 2vw, 16px);
}

.panel-title + .stats-grid,
.panel-title + .responsive-data-list {
    margin-top: 8px;
}

.dash-par-grid,
.reports-exec-par {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: clamp(10px, 2vw, 14px);
}

/* ── Breakpoints ── */
@media (max-width: 479px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .stat-card {
        min-height: 76px;
        padding: 12px 14px;
    }

    .stat-icon {
        width: 28px;
        height: 28px;
    }

    .list-card__footer {
        flex-direction: column;
        align-items: stretch;
    }

    .list-card__actions {
        flex-direction: column;
    }

    .list-card__btn-primary,
    .list-card__actions .btn {
        width: 100%;
        flex: 1 1 auto;
    }

    .list-card__meta {
        grid-template-columns: 1fr;
    }

    .reports-hub-grid {
        grid-template-columns: 1fr;
    }

    .dash-alert-grid {
        grid-template-columns: 1fr;
    }

    .report-hub-card__head {
        gap: 10px;
    }

    .report-hub-icon {
        width: 40px;
        height: 40px;
    }

    .form-card-footer-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .form-card-footer-actions .btn {
        width: 100%;
    }
}

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

@media (min-width: 768px) and (max-width: 1023px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .reports-hub-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

@media (min-width: 1024px) {
    .stats-grid.reports-exec-stats {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }
}

@media (min-width: 1440px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    .reports-hub-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .list-card,
    .stat-card,
    .dash-alert-card,
    .report-hub-card {
        transition: none;
    }

    .list-card--clickable:active {
        transform: none;
    }

    .dash-alert-card:hover,
    .report-hub-card:hover {
        transform: none;
    }
}
