/* نظام إدارة الأقساط اليومية - ملف التنسيقات الرئيسي */
/* Mobile First Design with X-Menu Sidebar */

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-light: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --sidebar-width: 280px;
    --header-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f1f5f9;
    color: var(--text-color);
    line-height: 1.6;
    direction: rtl;
}

/* Header */
.header {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    height: var(--header-height);
    background: #1e293b;
    color: white;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.menu-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: white;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo {
    font-size: 1.25rem;
    font-weight: bold;
    color: white;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Sidebar - X-Menu Style */
.sidebar {
    position: fixed;
    top: var(--header-height);
    right: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: #1e293b;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 999;
    overflow-y: auto;
}

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

.sidebar-menu {
    list-style: none;
    padding: 1rem 0;
}

.sidebar-menu li {
    margin: 0.25rem 0;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    transition: all 0.2s;
    border-right: 3px solid transparent;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: rgba(255, 255, 255, 0.1);
    border-right-color: #3b82f6;
    color: white;
}

.sidebar-menu a i {
    margin-left: 0.75rem;
    width: 20px;
    text-align: center;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 998;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Main Content */
.main-content {
    margin-top: var(--header-height);
    padding: 1rem;
    min-height: calc(100vh - var(--header-height));
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

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

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--text-color);
}

/* Zebra striping - تنسيق السطور بالتناوب */
.table tbody tr:nth-child(odd) {
    background-color: #f8f9fa;
}

.table tbody tr:nth-child(even) {
    background-color: #ffffff;
}

.table tbody tr:hover {
    background-color: #e9ecef !important;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid var(--success-color);
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid var(--danger-color);
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid var(--info-color);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary-color);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-card:nth-child(1) {
    border-left-color: #2563eb;
}

.stat-card:nth-child(2) {
    border-left-color: #10b981;
}

.stat-card:nth-child(3) {
    border-left-color: #f59e0b;
}

.stat-card:nth-child(4) {
    border-left-color: #ef4444;
}

.stat-card:nth-child(5) {
    border-left-color: #8b5cf6;
}

.stat-card:nth-child(6) {
    border-left-color: #06b6d4;
}

.stat-card-title {
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--text-color);
}

.stat-card-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

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

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

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-box {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.login-form {
    margin-top: 1.5rem;
}

/* Daily Payment Grid */
.payment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

.payment-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.payment-day.paid {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

.payment-day.unpaid {
    background: var(--card-bg);
    color: var(--text-light);
}

.payment-day.unpaid:not(.empty):hover {
    background: var(--warning-color);
    color: white;
    border-color: var(--warning-color);
}

.payment-day.empty {
    background: transparent;
    border-color: transparent;
    cursor: default;
}

/* Print Styles */
@media print {
    .no-print {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }
    
    .card-header {
        page-break-after: avoid;
    }
    
    table {
        page-break-inside: auto;
    }
    
    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
}

/* Mobile Optimizations */
@media (max-width: 767px) {
    :root {
        --header-height: 56px;
        --sidebar-width: 85vw;
    }
    
    body {
        font-size: 14px;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .header {
        padding: 0 0.75rem;
        height: var(--header-height);
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .user-info {
        font-size: 0.75rem;
        gap: 0.25rem;
    }
    
    .user-info span {
        display: none;
    }
    
    .main-content {
        padding: 0.75rem;
        margin-top: var(--header-height);
    }
    
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
        border-radius: 12px;
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
    }
    
    .card-title {
        font-size: 1.1rem;
        width: 100%;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-card-value {
        font-size: 1.5rem;
    }
    
    .stat-card-icon {
        font-size: 1.5rem;
    }
    
    .table {
        font-size: 0.875rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.375rem;
        white-space: nowrap;
    }
    
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        min-height: 44px; /* Touch target size */
    }
    
    .btn-sm {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        min-height: 36px;
    }
    
    .form-control {
        padding: 0.875rem;
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
    }
    
    .payment-grid {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
        gap: 0.375rem;
    }
    
    .payment-day {
        font-size: 0.75rem;
        min-height: 50px;
    }
    
    .sidebar-menu a {
        padding: 1rem 1.25rem;
        font-size: 0.9375rem;
        min-height: 48px;
    }
    
    .d-flex {
        flex-wrap: wrap;
    }
    
    .gap-2 {
        gap: 0.5rem !important;
    }
    
    /* تحسين الجداول للجوال */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }
    
    /* تحسين النماذج */
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    /* تحسين الأزرار */
    .btn-block {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* تحسين البطاقات */
    .badge {
        font-size: 0.6875rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* إخفاء بعض العناصر على الجوال */
    .header-right .user-info .badge {
        display: none;
    }
}

/* Tablet Optimizations */
@media (min-width: 768px) and (max-width: 1023px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .payment-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    }
}

/* Desktop */
@media (min-width: 768px) {
    .sidebar {
        transform: translateX(0);
    }
    
    .main-content {
        margin-right: var(--sidebar-width);
    }
    
    .menu-toggle {
        display: none;
    }
    
    .overlay {
        display: none;
    }
}

/* PWA Install Button */
.install-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    z-index: 10000;
    display: none;
    align-items: center;
    gap: 1rem;
    max-width: 90%;
    animation: slideUp 0.3s ease;
}

.install-prompt.show {
    display: flex;
}

.install-prompt-content {
    flex: 1;
}

.install-prompt-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
}

.install-prompt-text {
    font-size: 0.8125rem;
    color: var(--text-light);
}

.install-prompt-actions {
    display: flex;
    gap: 0.5rem;
}

.install-prompt-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.install-prompt-btn.primary {
    background: var(--primary-color);
    color: white;
}

.install-prompt-btn.secondary {
    background: var(--bg-color);
    color: var(--text-color);
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* Safe Area for iOS */
@supports (padding: max(0px)) {
    .main-content {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* Loading Spinner */
.spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utilities */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-left {
    text-align: left;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.d-flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 1rem;
}

/* Touch optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        opacity: 1;
    }
    
    .btn:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
    
    .payment-day:active {
        transform: scale(0.95);
    }
    
    .sidebar-menu a:active {
        background: var(--primary-color);
        color: white;
    }
}

/* Prevent text selection on buttons */
.btn, .payment-day {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

body {
    -webkit-tap-highlight-color: transparent;
}

/* Better focus indicators for accessibility */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Improve form inputs on mobile */
@media (max-width: 767px) {
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    /* Larger touch targets */
    a, button, .btn {
        min-height: 44px;
        min-width: 44px;
    }
}

