/* نظام ديون السوبرماركت — أنماط مخصصة */

:root {
    --fab-size: 60px;
    --fab-offset: 24px;
}

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: #f4f6f8;
    font-size: 1rem;
    -webkit-tap-highlight-color: transparent;
}

body.has-fab main.container-fluid {
    padding-bottom: calc(var(--fab-size) + var(--fab-offset) + 1rem);
}

.login-page {
    background: linear-gradient(135deg, #198754 0%, #146c43 100%);
    min-height: 100vh;
}

/* زر عائم تسجيل دين */
.fab-debt {
    position: fixed;
    bottom: calc(var(--fab-offset) + env(safe-area-inset-bottom, 0px));
    right: calc(var(--fab-offset) + env(safe-area-inset-right, 0px));
    left: auto;
    width: var(--fab-size);
    height: var(--fab-size);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    font-size: 1.5rem;
    box-shadow: 0 4px 16px rgba(25, 135, 84, 0.45) !important;
    transition: transform 0.15s ease;
}

.fab-debt:active {
    transform: scale(0.94);
}

.fab-debt .fab-label {
    position: absolute;
    right: calc(100% + 10px);
    white-space: nowrap;
    background: #212529;
    color: #fff;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.fab-debt:hover .fab-label,
.fab-debt:focus .fab-label {
    opacity: 1;
}

/* بطاقات الإحصائيات */
.stat-card {
    border-radius: 12px;
}

@media (hover: hover) {
    .stat-card {
        transition: transform 0.15s;
    }

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

.stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

/* الإكمال التلقائي */
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1100;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0 0 8px 8px;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #f0f0f0;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #e8f5e9;
}

.autocomplete-item:active {
    background: #c8e6c9;
}

/* الزبون المختار في نافذة الدين */
.selected-customer-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 8px;
    margin-top: 8px;
}

.selected-customer-chip .btn-clear-customer {
    padding: 0 6px;
    line-height: 1;
}

/* أزرار كبيرة للهاتف */
@media (max-width: 576px) {
    :root {
        --fab-size: 64px;
    }

    .btn-lg, .form-control-lg {
        min-height: 48px;
        font-size: 1.1rem;
    }

    .btn, .form-select {
        min-height: 44px;
    }

    #customerActions .btn {
        flex: 1 1 calc(50% - 4px);
        min-height: 48px;
        font-size: 1rem;
    }

    .stat-value {
        font-size: 1rem;
    }

    .table {
        font-size: 0.85rem;
    }

    body {
        font-size: 1.05rem;
    }

    .fab-debt .fab-label {
        display: none;
    }

    #reportTabs .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    [data-range] {
        min-height: 44px;
    }
}

/* كشف الحساب — مشطوب */
.text-decoration-line-through td {
    opacity: 0.6;
}

/* طباعة كشف الحساب */
.print-only-statement {
    display: none;
}

@media print {
    .print-only-statement {
        display: block !important;
        margin-bottom: 1rem;
    }

    .navbar, .fab-debt, #customerActions, .btn, nav, footer {
        display: none !important;
    }

    main {
        padding: 0 !important;
    }

    #statementTable thead {
        display: table-header-group !important;
    }

    #statementTable tbody tr {
        display: table-row !important;
        padding: 0 !important;
    }

    #statementTable tbody td {
        display: table-cell !important;
        padding: 0.5rem !important;
    }

    #statementTable tbody td::before {
        display: none !important;
    }
}

/* تكبير الخط */
body.font-large {
    font-size: 1.2rem;
}

body.font-large .stat-value {
    font-size: 1.45rem;
}

#btnFontSize[aria-pressed="true"] {
    background: rgba(255, 255, 255, 0.25);
}

/* قائمة الزبائن */
.list-group-item-action {
    padding: 14px 16px;
}

.list-group-item-action:active {
    background: #e8f5e9;
}

/* تبويبات التقارير */
#reportTabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    white-space: nowrap;
}

#reportTabs .nav-link {
    font-size: 0.9rem;
}

/* صلاحيات */
#permissionsGrid .form-check {
    padding: 4px 8px;
    background: #f8f9fa;
    border-radius: 6px;
}

.amount-input {
    direction: ltr;
    text-align: right;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

/* لوحة فئات الدينار — مودال الدين */
.amount-pad-section + .amount-pad-section {
    margin-top: 0.5rem;
}

.amount-pad-label {
    font-weight: 600;
}

.amount-pad-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
}

.amount-pad-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 6px 2px;
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    white-space: nowrap;
}

.amount-pad-btn.amount-pad-btn-pressed {
    transform: scale(0.94);
}

@media (max-width: 576px) {
    .amount-pad-row {
        gap: 3px;
    }

    .amount-pad-btn {
        min-height: 48px;
        font-size: 0.72rem;
        padding: 8px 1px;
    }
}

@media (min-width: 400px) {
    .amount-pad-btn {
        font-size: 0.85rem;
    }
}

/* حالة التحميل */
.loading-skeleton {
    background: linear-gradient(90deg, #e9ecef 25%, #f8f9fa 50%, #e9ecef 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.2s ease-in-out infinite;
    border-radius: 6px;
    color: transparent !important;
    user-select: none;
    pointer-events: none;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .loading-skeleton {
        animation: none;
        background: #e9ecef;
    }
}

/* Toast فوق الزر العائم */
body.has-fab #toastContainer {
    bottom: calc(var(--fab-size) + var(--fab-offset) + 8px) !important;
    z-index: 1060;
}

/* كشف الحساب — بطاقات على الهاتف */
@media (max-width: 767px) {
    #statementTable thead {
        display: none;
    }

    #statementTable tbody tr {
        display: block;
        border-bottom: 1px solid #dee2e6;
        padding: 12px 16px;
    }

    #statementTable tbody tr.text-decoration-line-through {
        opacity: 0.55;
    }

    #statementTable tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        border: none;
        padding: 4px 0;
    }

    #statementTable tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6c757d;
        flex-shrink: 0;
    }

    #statementTable tbody td:last-child {
        justify-content: flex-end;
        padding-top: 8px;
    }

    #statementTable tbody td:last-child::before {
        display: none;
    }
}

/* صفحة الدخول */
.login-page .card {
    border-radius: 16px;
}

.login-page .btn-login-loading .spinner-border {
    width: 1.1rem;
    height: 1.1rem;
}

/* ترحيب الموظف */
.welcome-actions .btn {
    min-width: 180px;
}

.stat-card .stat-icon {
    font-size: 1.25rem;
    opacity: 0.7;
    margin-bottom: 4px;
}

.net-positive { color: #dc3545 !important; }
.net-negative { color: #198754 !important; }
.net-zero { color: #6c757d !important; }
