/* ===== متغيرات CSS ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --info: #0891b2;

    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-input: #f8fafc;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-sidebar: #cbd5e1;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 12px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0f172a;
    --bg-input: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

/* ===== إعادة تعيين ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    line-height: 1.6;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* ===== شاشة تسجيل الدخول ===== */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #2563eb 100%);
    padding: 20px;
}

.login-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-logo {
    margin-bottom: 36px;
}

.login-logo i {
    font-size: 56px;
    color: var(--primary);
    margin-bottom: 16px;
    display: block;
}

.login-logo h1 {
    font-size: 22px;
    color: var(--text);
    margin-bottom: 8px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-container .input-group {
    position: relative;
    margin-bottom: 20px;
}

.login-container .input-group i {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 16px;
}

.login-container .input-group input {
    width: 100%;
    padding: 14px 44px 14px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    background: var(--bg-input);
    color: var(--text);
    transition: var(--transition);
    direction: rtl;
}

.login-container .input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* ===== الأزرار ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-dark {
    background: #1e293b;
    color: #fff;
}

.btn-dark:hover {
    background: #0f172a;
}

.btn-block {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 16px;
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 8px;
}

.btn-icon:hover {
    background: var(--border);
    color: var(--text);
}

.btn-logout {
    width: 100%;
    justify-content: center;
    background: rgba(220,38,38,0.1);
    color: var(--danger);
    padding: 10px;
    border-radius: 10px;
    font-weight: 600;
}

.btn-logout:hover {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* ===== التطبيق الرئيسي ===== */
.main-app {
    display: flex;
    min-height: 100vh;
}

/* ===== الشريط الجانبي ===== */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: var(--transition);
}

.sidebar-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header i {
    font-size: 28px;
    color: var(--primary);
}

.sidebar-header span {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 10px;
    color: var(--text-sidebar);
    text-decoration: none;
    margin-bottom: 4px;
    transition: var(--transition);
    font-size: 14px;
    font-weight: 500;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.nav-item:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.nav-item.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* ===== المحتوى الرئيسي ===== */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    min-height: 100vh;
    transition: var(--transition);
}

/* ===== شريط الأدوات ===== */
.top-bar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 100;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text);
    cursor: pointer;
}

.top-bar-title {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.user-info i {
    font-size: 24px;
    color: var(--primary);
}

/* ===== الصفحات ===== */
.page {
    display: none;
    padding: 24px;
    animation: fadeIn 0.3s ease;
}

.page.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

.page-header .page-title { margin-bottom: 0; }

/* ===== بطاقات الإحصائيات ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 14px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    border: 1px solid var(--border);
    text-align: center;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card.stat-card-header {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, #1e293b, #2563eb);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    text-align: right;
}

.stat-header-title {
    font-size: 18px;
    font-weight: 800;
}

.stat-header-date {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 2px;
}

.stat-header-time {
    font-size: 24px;
    font-weight: 800;
    direction: ltr;
}

.stat-header-sub {
    font-size: 12px;
    opacity: 0.75;
}

.stat-card .stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin: 0 auto 8px;
}

.stat-card .stat-value {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 2px;
    direction: ltr;
}

.stat-card .stat-label {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
}

.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: #dcfce7; color: var(--success); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }
.stat-icon.yellow { background: #fef3c7; color: var(--warning); }
.stat-icon.teal { background: #ccfbf1; color: var(--info); }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }
.stat-icon.indigo { background: #e0e7ff; color: #4f46e5; }
.stat-icon.total { background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; }

/* ===== ملخص الحسابات ===== */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    text-align: center;
}

.summary-card .value {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 4px;
}

.summary-card .label {
    color: var(--text-secondary);
    font-size: 13px;
}

/* ===== ملخص التسويات ===== */
.settlement-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.settlement-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    text-align: center;
}

.settlement-card .value {
    font-size: 26px;
    font-weight: 800;
    margin-top: 8px;
}

.settlement-card .label {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
}

/* ===== شريط الفلترة ===== */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
    align-items: center;
}

.search-input, .date-input {
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text);
    transition: var(--transition);
    font-family: inherit;
    direction: rtl;
}

.search-input { min-width: 260px; }
.date-input { min-width: 170px; }

.search-input:focus, .date-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ===== الجداول ===== */
.table-container {
    overflow-x: auto;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-sidebar);
    color: #fff;
}

th {
    padding: 14px 16px;
    text-align: right;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

tbody tr:hover {
    background: var(--bg);
}

tbody tr:last-child td { border-bottom: none; }

/* ===== التبويبات ===== */
.cashflow-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 10px 24px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.tab-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ===== الإعدادات ===== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.settings-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.settings-card h3 {
    font-size: 17px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.settings-card h3 i {
    color: var(--primary);
}

.settings-card .input-group {
    margin-bottom: 16px;
}

.settings-card label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.settings-card input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text);
    transition: var(--transition);
    font-family: inherit;
    direction: rtl;
}

.settings-card input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.import-area {
    display: inline-flex;
}

/* ===== النوافذ المنبثقة ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

.modal-large { max-width: 700px; }
.modal-small { max-width: 380px; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 17px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover { color: var(--danger); }

.modal-content form, .modal-content > div:not(.modal-header):not(.modal-footer) {
    padding: 24px;
}

.modal-content .input-group {
    margin-bottom: 16px;
}

.modal-content label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.modal-content input, .modal-content select, .modal-content textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text);
    transition: var(--transition);
    font-family: inherit;
    direction: rtl;
}

.modal-content input:focus, .modal-content select:focus, .modal-content textarea:focus {
    outline: none;
    border-color: var(--primary);
}

#debtAmount, #editDebtAmount, #cashflowAmount, #settlementAmount, #payDebtAmount {
    direction: ltr;
    text-align: left;
    font-size: 16px;
    letter-spacing: 0.5px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

#confirmModal .modal-content {
    text-align: center;
}

#confirmMessage {
    padding: 20px 24px;
    font-size: 15px;
}

#confirmModal .modal-footer {
    justify-content: center;
}

/* ===== الإشعارات ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: var(--success);
    color: #fff;
    padding: 14px 24px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    z-index: 3000;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
}

.toast.error { background: var(--danger); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== أزرار الإجراءات في الجدول ===== */
.action-btns {
    display: flex;
    gap: 6px;
}

.action-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: var(--transition);
}

.action-btn.edit {
    background: var(--primary-light);
    color: var(--primary);
}

.action-btn.edit:hover {
    background: var(--primary);
    color: #fff;
}

.action-btn.delete {
    background: #fee2e2;
    color: var(--danger);
}

.action-btn.delete:hover {
    background: var(--danger);
    color: #fff;
}

.action-btn.view {
    background: #dcfce7;
    color: var(--success);
}

.action-btn.view:hover {
    background: var(--success);
    color: #fff;
}

.action-btn.pay {
    background: #fef3c7;
    color: #92400e;
}

.action-btn.pay:hover {
    background: #f59e0b;
    color: #fff;
}

/* ===== تفاصيل الحساب ===== */
.account-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.account-info-item {
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
}

.account-info-item .label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.account-info-item .value {
    font-size: 16px;
    font-weight: 700;
}

/* ===== بطاقات العملاء ===== */
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.client-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}

.client-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.client-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.client-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
}

.client-info h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 2px;
}

.client-info span {
    font-size: 12px;
    color: var(--text-secondary);
}

.client-card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 14px;
}

.client-stat {
    text-align: center;
    padding: 10px;
    background: var(--bg);
    border-radius: 8px;
}

.client-stat-value {
    display: block;
    font-size: 18px;
    font-weight: 800;
}

.client-stat-label {
    font-size: 11px;
    color: var(--text-secondary);
}

.client-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
}

.client-card-footer i.fa-chevron-left {
    color: var(--primary);
}

/* ===== بطاقات الديون ===== */
.section-subtitle {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}

.debts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.debt-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.debt-card:hover {
    box-shadow: var(--shadow-lg);
}

.debt-card.archived {
    opacity: 0.7;
}

.debt-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.debt-id {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    font-family: monospace;
}

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

.badge-archived {
    background: #e2e8f0;
    color: #475569;
}

.debt-card-body {
    padding: 18px;
}

.debt-amount {
    font-size: 28px;
    font-weight: 800;
    color: var(--danger);
    margin-bottom: 12px;
    direction: ltr;
    text-align: right;
}

.debt-progress {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-bottom: 14px;
    overflow: hidden;
}

.debt-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #22c55e);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.debt-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.debt-detail {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.debt-detail span {
    color: var(--text-secondary);
}

.debt-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.debt-meta i {
    margin-left: 4px;
}

.debt-notes {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 8px 10px;
    background: var(--bg);
    border-radius: 6px;
    margin-top: 8px;
}

.debt-notes i {
    margin-left: 4px;
}

.debt-card-footer {
    display: flex;
    gap: 8px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
}

/* ===== تبويبات نوع العميل ===== */
.client-type-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.client-type-tabs .tab-btn {
    flex: 1;
    text-align: center;
}

/* ===== جدول قائمة العملاء ===== */
.client-table {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.client-table-header {
    display: flex;
    background: var(--bg-sidebar);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.client-table-row {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
}

.client-table-row:last-child {
    border-bottom: none;
}

.client-table-row:hover {
    background: var(--bg);
}

.ct-col {
    padding: 0 12px;
}

.client-table-header .ct-col {
    padding: 14px 12px;
}

.ct-num {
    width: 50px;
    text-align: center;
    flex-shrink: 0;
}

.ct-name {
    flex: 1;
    font-weight: 600;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ct-count {
    width: 70px;
    text-align: center;
    flex-shrink: 0;
}

.ct-remaining {
    width: 130px;
    text-align: center;
    flex-shrink: 0;
    direction: ltr;
}

.ct-paid {
    width: 110px;
    text-align: center;
    flex-shrink: 0;
    direction: ltr;
}

.ct-date {
    width: 100px;
    text-align: center;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.ct-action {
    width: 50px;
    text-align: center;
    flex-shrink: 0;
}

/* ===== جدول الديون العمودي المضغوط ===== */
.debts-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.debt-row {
    display: flex;
    align-items: stretch;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: var(--transition);
}

.debt-row:hover {
    box-shadow: var(--shadow);
}

.debt-row.archived {
    opacity: 0.6;
}

.debt-row-num {
    width: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-sidebar);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}

.debt-row-body {
    flex: 1;
    padding: 10px 14px;
    min-width: 0;
}

.debt-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.debt-row-amount {
    font-size: 18px;
    font-weight: 800;
    color: var(--danger);
    direction: ltr;
}

.debt-row-badge {
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.debt-row-info {
    display: flex;
    gap: 20px;
    font-size: 12px;
    margin-bottom: 4px;
}

.debt-row-info span {
    color: var(--text-secondary);
}

.debt-row-meta {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--text-secondary);
}

.debt-row-notes {
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 4px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.debt-row-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 8px;
    border-right: 1px solid var(--border);
}

.btn-icon-sm {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: var(--transition);
}

.btn-green {
    background: #dcfce7;
    color: #166534;
}
.btn-green:hover {
    background: #16a34a;
    color: #fff;
}

.btn-blue {
    background: var(--primary-light);
    color: var(--primary);
}
.btn-blue:hover {
    background: var(--primary);
    color: #fff;
}

.btn-red {
    background: #fee2e2;
    color: #991b1b;
}
.btn-red:hover {
    background: #dc2626;
    color: #fff;
}

/* ===== الطباعة ===== */
@media print {
    .sidebar, .top-bar, .filters-bar, .page-header, .action-btns,
    .btn, .modal, .toast { display: none !important; }

    .main-content { margin: 0 !important; }

    .page { display: block !important; padding: 10px !important; }

    .table-container { box-shadow: none !important; border: 1px solid #000 !important; }

    body { background: #fff !important; color: #000 !important; }
}

/* ===== التجاوب ===== */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
    }

    .menu-toggle { display: block; }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .stat-card { padding: 12px; }
    .stat-card .stat-value { font-size: 16px; }
    .stat-card .stat-icon { width: 32px; height: 32px; font-size: 14px; }
    .stat-card .stat-label { font-size: 10px; }

    .stat-card.stat-card-header {
        padding: 14px 16px;
    }

    .stat-header-title { font-size: 15px; }
    .stat-header-time { font-size: 20px; }

    .settlement-summary {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .page { padding: 16px; }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .filters-bar {
        flex-direction: column;
    }

    .search-input, .date-input { min-width: 100%; }

    .modal-content { margin: 10px; }

    .account-info { grid-template-columns: 1fr; }

    .top-bar { padding: 0 12px; }

    .cashflow-tabs { flex-direction: column; }
    .tab-btn { text-align: center; }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .clients-grid {
        grid-template-columns: 1fr;
    }

    .debts-grid {
        grid-template-columns: 1fr;
    }

    .client-card-stats {
        grid-template-columns: 1fr 1fr;
    }

    .client-type-tabs {
        flex-direction: column;
    }

    .client-table-header {
        display: none;
    }

    .client-table-row {
        flex-wrap: wrap;
        gap: 8px;
        padding: 14px;
    }

    .ct-num { display: none; }
    .ct-count { display: none; }

    .ct-action {
        position: absolute;
        top: 14px;
        left: 14px;
    }

    .client-table-row {
        position: relative;
    }

    .ct-name {
        width: 100%;
        font-size: 15px;
    }

    .ct-remaining, .ct-paid {
        width: auto;
        flex: 1;
        text-align: center;
        background: var(--bg);
        padding: 6px 10px;
        border-radius: 6px;
    }

    .ct-date {
        width: 100%;
        text-align: left;
    }

    .debt-row {
        flex-direction: column;
    }

    .debt-row-num {
        width: 100%;
        min-width: 100%;
        padding: 4px;
        font-size: 11px;
    }

    .debt-row-actions {
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        justify-content: center;
        padding: 8px;
    }

    .debt-row-info {
        flex-direction: column;
        gap: 4px;
    }

    table { font-size: 13px; }
    th, td { padding: 8px 10px; }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-card .stat-value {
        font-size: 14px;
    }

    .stat-card .stat-label {
        font-size: 9px;
    }

    .stat-card .stat-icon {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .stat-card.stat-card-header {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .stat-header-time {
        font-size: 18px;
    }

    .summary-cards {
        grid-template-columns: 1fr;
    }

    .user-info span { display: none; }

    .login-container {
        padding: 32px 24px;
    }
}

/* ===== شريط التمرير ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ===== وسم الحساب ===== */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-debtor { background: #dcfce7; color: #166534; }
.badge-creditor { background: #fee2e2; color: #991b1b; }
.badge-add { background: #dcfce7; color: #166534; }
.badge-withdraw { background: #fee2e2; color: #991b1b; }
.badge-rafidain { background: var(--primary-light); color: var(--primary); }
.badge-rashid { background: #fef3c7; color: #92400e; }
