/* ==========================================================================
   Smart Invoicing System - Core Stylesheet
   Premium Financial UI | Arabic RTL
   ========================================================================== */

:root {
    /* Color Palette */
    --primary-dark: #1E103C; /* Dark Premium Purple */
    --primary-light: #2D1A54;
    --primary-accent: #6C5DD3;
    
    --bg-workspace: #F4F6F8;
    --bg-card: #FFFFFF;
    
    --text-main: #111827;
    --text-muted: #6B7280;
    --text-sidebar: #E5E7EB;
    
    --border-color: #E5E7EB;
    --border-focus: #6C5DD3;
    
    /* Status Colors */
    --status-active: #10B981; /* Green */
    --status-archived: #6B7280; /* Gray */
    --status-paid: #10B981; /* Green */
    --status-partial: #F59E0B; /* Yellow */
    --status-unpaid: #EF4444; /* Red */

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    
    /* Typography */
    --font-family: 'Cairo', sans-serif;
    
    /* Spacing & Layout */
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ==========================================
   RESET & BASICS
   ========================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-workspace);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    font-family: var(--font-family);
    cursor: pointer;
    border: none;
    background: none;
}

input, select, textarea {
    font-family: var(--font-family);
}

/* ==========================================
   LAYOUT STRUCTURE
   ========================================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ==========================================
   SIDEBAR
   ========================================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-dark);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: all 0.3s ease;
    z-index: 10;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    background-color: rgba(0,0,0,0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.logo h2 {
    font-size: 18px;
    font-weight: 700;
    color: #FFF;
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--primary-light);
    border-radius: 4px;
}


/* Sidebar Sections */
.nav-section {
    margin-bottom: 4px;
}
.nav-section-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: var(--text-sidebar);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.8;
}
.nav-section-header:hover {
    background-color: rgba(255, 255, 255, 0.05);
    opacity: 1;
}
.nav-section-header.active {
    background: linear-gradient(90deg, rgba(108, 93, 211, 0.15) 0%, transparent 100%);
    border-right: 3px solid var(--primary-color);
    opacity: 1;
}
.nav-section-header i {
    font-size: 20px;
}
.nav-section-header span {
    margin-right: 12px;
    flex-grow: 1;
}
.nav-section-header .arrow {
    font-size: 14px;
    transition: transform 0.3s ease;
}
.nav-section.expanded .nav-section-header {
    opacity: 1;
}
.nav-section.expanded .nav-section-header .arrow {
    transform: rotate(180deg);
}
.nav-section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
    margin-top: 4px;
}
.nav-section.expanded .nav-section-content {
    max-height: 500px;
}
.nav-section-content .nav-item {
    padding-right: 48px;
    margin-bottom: 2px;
    font-size: 14px;
}
.nav-section-content .nav-item i {
    font-size: 18px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: var(--text-sidebar);
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-item i {
    font-size: 20px;
    opacity: 0.8;
}

.nav-item:hover {
    background-color: var(--primary-light);
    color: #FFF;
}

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

.nav-item.active i {
    opacity: 1;
}

.nav-divider {
    height: 1px;
    background-color: rgba(255,255,255,0.1);
    margin: 12px 0;
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info .avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--primary-accent);
}

.user-info .details {
    display: flex;
    flex-direction: column;
}

.user-info .name {
    font-size: 14px;
    font-weight: 600;
    color: #FFF;
}

.user-info .role {
    font-size: 12px;
    color: rgba(255,255,255,0.6);
}

/* ==========================================
   WORKSPACE & HEADER
   ========================================== */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-header {
    height: var(--header-height);
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    flex-shrink: 0;
}

.header-title h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}

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

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text-muted);
    background-color: transparent;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.icon-btn:hover {
    background-color: var(--bg-workspace);
    color: var(--primary-accent);
}

/* ==========================================
   CONTENT AREA & MODULES
   ========================================== */
.content-area {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    position: relative;
}

.module-view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.module-view.active {
    display: block;
}

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

/* ==========================================
   UI COMPONENTS
   ========================================== */

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
    padding: 24px;
    margin-bottom: 24px;
}

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

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
}

/* Dashboard Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.metric-card {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background-color: rgba(108, 93, 211, 0.1);
    color: var(--primary-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.metric-details {
    flex: 1;
}

.metric-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn i {
    font-size: 18px;
}

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

.btn-primary:hover {
    background-color: #5b4eb8;
    box-shadow: 0 2px 4px rgba(108, 93, 211, 0.3);
}

.btn-secondary {
    background-color: #FFF;
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-workspace);
    border-color: #D1D5DB;
}

.btn-danger {
    background-color: #FEF2F2;
    color: var(--status-unpaid);
    border-color: #FEE2E2;
}

.btn-danger:hover {
    background-color: #FEE2E2;
}

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

/* Forms & Inputs */
.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 8px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: #FFF;
    color: var(--text-main);
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(108, 93, 211, 0.1);
}

.form-control:disabled {
    background-color: var(--bg-workspace);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Data Tables */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: #FFF;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}

.data-table th {
    background-color: var(--bg-workspace);
    padding: 14px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 16px;
    font-size: 14px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background-color: #F9FAFB;
}

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

/* Action Buttons inside tables */
.table-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    transition: all 0.2s;
}

.action-btn:hover {
    background-color: var(--bg-workspace);
    color: var(--primary-accent);
}

.action-btn.edit:hover { color: var(--primary-accent); }
.action-btn.delete:hover { color: var(--status-unpaid); }
.action-btn.view:hover { color: var(--status-active); }

/* Badges / Status */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-active { background-color: #D1FAE5; color: #065F46; }
.badge-archived { background-color: #F3F4F6; color: #374151; }
.badge-paid { background-color: #D1FAE5; color: #065F46; }
.badge-partial { background-color: #FEF3C7; color: #92400E; }
.badge-unpaid { background-color: #FEE2E2; color: #991B1B; }

/* Modal / Dialog */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(17, 24, 39, 0.6);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

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

.modal {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal.modal-lg { max-width: 900px; }
.modal.modal-sm { max-width: 400px; }

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

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
}

.btn-close {
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.btn-close:hover { color: var(--status-unpaid); }

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background-color: #F9FAFB;
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

/* Toolbar (Search & Filters) */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    width: 300px;
    max-width: 100%;
}

.search-box i {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 18px;
}

.search-box input {
    width: 100%;
    padding: 10px 36px 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
}

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

/* Invoice specific styles */
.invoice-items-table th {
    background-color: var(--bg-workspace);
}

.invoice-totals {
    width: 300px;
    margin-right: auto;
    margin-left: 0;
    margin-top: 24px;
}

.invoice-totals .form-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.invoice-totals label {
    margin-bottom: 0;
    font-size: 14px;
}

.invoice-totals input {
    width: 150px;
    text-align: left;
    font-weight: 700;
}

.grand-total-row {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary-accent);
    border-top: 2px solid var(--border-color);
    padding-top: 12px;
    margin-top: 12px;
}

/* Utility classes */
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
.text-danger { color: var(--status-unpaid); }
.text-success { color: var(--status-active); }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.gap-2 { gap: 8px; }
.mt-4 { margin-top: 24px; }
.mb-4 { margin-bottom: 24px; }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 48px;
    color: #D1D5DB;
    margin-bottom: 16px;
}
.empty-state h3 {
    font-size: 16px;
    color: var(--text-main);
    margin-bottom: 8px;
}

/* Loading overlay */
.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    display: none;
}
.loading-overlay.active {
    display: flex;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(108, 93, 211, 0.2);
    border-radius: 50%;
    border-top-color: var(--primary-accent);
    animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background-color: var(--bg-card);
    color: var(--text-main);
    padding: 16px 20px;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    border-right: 4px solid var(--primary-accent); /* RTL right border */
    transform: translateX(-100%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.success { border-right-color: var(--status-active); }
.toast.error { border-right-color: var(--status-unpaid); }
.toast.warning { border-right-color: var(--status-partial); }

.toast i { font-size: 20px; }
.toast.success i { color: var(--status-active); }
.toast.error i { color: var(--status-unpaid); }

/* Responsive Adjustments */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        height: auto;
        overflow-x: auto;
    }
    .sidebar-header {
        display: none;
    }
    .sidebar-nav {
        flex-direction: row;
        padding: 12px;
        align-items: center;
    }
    .nav-item {
        padding: 8px 12px;
        white-space: nowrap;
    }
    .sidebar-footer {
        display: none;
    }
}
