/**
 * Daamah Finance System - Final UI Polish
 * نظام دَعمة المالي
 *
 * Brand Colors: White + Black + Red
 * Style: Minimal. Confident. Financial. Professional.
 */

/* =============================================
   Design Tokens - Daamah Brand
   ============================================= */
:root {
    /* Brand Colors */
    --white: #ffffff;
    --black: #111111;
    --red: #dc2626;
    --red-dark: #b91c1c;
    --red-light: #fef2f2;

    /* Neutral Scale */
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #404040;
    --gray-800: #262626;
    --gray-900: #171717;

    /* Semantic */
    --success: #111111;
    --success-bg: #f5f5f5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #dc2626;
    --warning-bg: #fef2f2;

    /* Layout */
    --page-bg: #ffffff;
    --sidebar-bg: #111111;
    --card-bg: #ffffff;

    /* Text */
    --text-primary: #111111;
    --text-secondary: #525252;
    --text-muted: #737373;
    --text-inverse: #ffffff;

    /* Borders */
    --border: #e5e5e5;
    --border-dark: #d4d4d4;

    /* Dimensions */
    --sidebar-w: 260px;
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;

    /* Effects */
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --transition: 180ms ease;
}

/* =============================================
   Reset & Base
   ============================================= */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: var(--page-bg);
    color: var(--text-primary);
    line-height: 1.7;
    direction: rtl;
    font-size: 0.9375rem;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* =============================================
   Typography
   ============================================= */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    color: var(--black);
    line-height: 1.3;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

p { color: var(--text-secondary); }

a {
    color: var(--red);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--red-dark);
}

ul, ol { list-style: none; }

/* =============================================
   Layout
   ============================================= */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* =============================================
   Sidebar - Black
   ============================================= */
.sidebar {
    width: var(--sidebar-w);
    background: var(--black);
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

.sidebar-header {
    padding: 28px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--white);
}

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

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.sidebar-nav ul {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-nav ul li a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--gray-400);
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.sidebar-nav ul li a:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-nav ul li.active a {
    color: var(--white);
    background: var(--red);
    font-weight: 600;
}

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

.user-info {
    margin-bottom: 14px;
}

.user-name {
    display: block;
    font-weight: 600;
    color: var(--white);
    font-size: 0.9375rem;
    margin-bottom: 2px;
}

.user-role {
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.logout-btn {
    display: block;
    padding: 10px 16px;
    background: transparent;
    color: var(--gray-400);
    text-align: center;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.logout-btn:hover {
    background: var(--red);
    border-color: var(--red);
    color: var(--white);
}

/* =============================================
   Main Content - Wide & Breathable
   ============================================= */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-w);
    min-height: 100vh;
    background: var(--gray-50);
}

.content-header {
    background: var(--white);
    padding: 24px 40px;
    border-bottom: 1px solid var(--border);
}

.content-header h2 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--black);
}

.content-body {
    padding: 32px 40px;
}

/* =============================================
   Cards
   ============================================= */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

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

.card-header h3 {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--black);
}

.card-body {
    padding: 24px;
}

.card-footer {
    padding: 18px 24px;
    border-top: 1px solid var(--border);
    background: var(--gray-50);
}

/* =============================================
   Dashboard Stats
   ============================================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border);
    transition: box-shadow var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card .stat-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--black);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

/* Stat Colors - Red accent */
.stat-card.stat-success .stat-value {
    color: var(--black);
}

.stat-card.stat-danger .stat-value {
    color: var(--red);
}

.stat-card.stat-warning .stat-value {
    color: var(--red);
}

.stat-card.stat-info .stat-value {
    color: var(--red);
}

/* =============================================
   Forms
   ============================================= */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--black);
}

.form-group label.required::after {
    content: ' *';
    color: var(--red);
}

.form-control {
    width: 100%;
    height: 48px;
    padding: 12px 16px;
    font-size: 0.9375rem;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--text-primary);
    transition: all var(--transition);
}

.form-control:hover {
    border-color: var(--border-dark);
}

.form-control:focus {
    outline: none;
    border-color: var(--black);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

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

.form-control::placeholder {
    color: var(--gray-400);
}

textarea.form-control {
    min-height: 120px;
    height: auto;
    resize: vertical;
}

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 16px center;
    padding-left: 48px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

/* =============================================
   Buttons - Red Primary, Black Secondary
   ============================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary - Red */
.btn-primary {
    background: var(--red);
    color: var(--white);
}

.btn-primary:hover:not(:disabled) {
    background: var(--red-dark);
    color: var(--white);
}

/* Secondary - Black outline */
.btn-secondary {
    background: var(--white);
    color: var(--black);
    border: 1px solid var(--border-dark);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--black);
    border-color: var(--black);
    color: var(--white);
}

/* Success - Black */
.btn-success {
    background: var(--black);
    color: var(--white);
}

.btn-success:hover:not(:disabled) {
    background: var(--gray-800);
    color: var(--white);
}

/* Danger - Red dark */
.btn-danger {
    background: var(--red-dark);
    color: var(--white);
}

.btn-danger:hover:not(:disabled) {
    background: #991b1b;
    color: var(--white);
}

/* Warning - Red */
.btn-warning {
    background: var(--red);
    color: var(--white);
}

.btn-warning:hover:not(:disabled) {
    background: var(--red-dark);
    color: var(--white);
}

/* Sizes */
.btn-sm {
    padding: 8px 16px;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* =============================================
   Tables - Full Width, No Horizontal Scroll
   ============================================= */
.table-responsive {
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.table th,
.table td {
    padding: 16px 20px;
    text-align: right;
    vertical-align: middle;
}

.table th {
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--gray-100);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.table td {
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.table tbody tr:hover {
    background: var(--gray-50);
}

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

.table .actions {
    white-space: nowrap;
    display: flex;
    gap: 8px;
}

.table .actions .btn {
    padding: 8px 14px;
    font-size: 0.8125rem;
}

/* =============================================
   Alerts
   ============================================= */
.alert {
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    font-size: 0.9375rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--gray-100);
    color: var(--black);
    border-color: var(--border-dark);
}

.alert-danger {
    background: var(--red-light);
    color: var(--red-dark);
    border-color: #fecaca;
}

.alert-warning {
    background: var(--red-light);
    color: var(--red-dark);
    border-color: #fecaca;
}

.alert-info {
    background: var(--gray-100);
    color: var(--black);
    border-color: var(--border-dark);
}

.alert strong {
    font-weight: 700;
}

/* =============================================
   Status Badges - Black & Red
   ============================================= */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 100px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.status-draft {
    background: var(--gray-200);
    color: var(--gray-700);
}

.status-sent {
    background: var(--gray-100);
    color: var(--black);
}

.status-partial {
    background: var(--red-light);
    color: var(--red);
}

.status-paid {
    background: var(--gray-100);
    color: var(--black);
}

.status-overdue {
    background: var(--red-light);
    color: var(--red);
}

/* =============================================
   Pagination
   ============================================= */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 32px;
}

.pagination-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.875rem;
    transition: all var(--transition);
}

.pagination-link:hover {
    border-color: var(--black);
    background: var(--gray-100);
}

.pagination-link.active {
    background: var(--black);
    border-color: var(--black);
    color: var(--white);
}

/* =============================================
   Login Page
   ============================================= */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    padding: 24px;
}

.login-box {
    width: 100%;
    max-width: 440px;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 48px 44px;
    border: 1px solid var(--border);
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.login-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--black);
    margin-bottom: 10px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.login-box .form-group {
    margin-bottom: 20px;
}

.login-box .btn-primary {
    margin-top: 12px;
    height: 52px;
    font-size: 1rem;
}

/* =============================================
   Empty State
   ============================================= */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 20px;
    font-size: 1rem;
}

/* =============================================
   Invoice Items
   ============================================= */
.invoice-items {
    margin-bottom: 24px;
}

.invoice-item {
    display: grid;
    grid-template-columns: 1fr 180px 48px;
    gap: 16px;
    margin-bottom: 16px;
    align-items: start;
}

.invoice-item .form-control {
    margin-bottom: 0;
}

.btn-remove-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: var(--red-light);
    border: none;
    border-radius: var(--radius);
    color: var(--red);
    cursor: pointer;
    font-size: 1.25rem;
    transition: all var(--transition);
}

.btn-remove-item:hover {
    background: var(--red);
    color: var(--white);
}

.invoice-totals {
    background: var(--gray-100);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.invoice-totals .total-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 0.9375rem;
}

.invoice-totals .total-row.grand-total {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--black);
    border-top: 2px solid var(--border-dark);
    padding-top: 16px;
    margin-top: 12px;
}

/* =============================================
   Card Tables - Full Width
   ============================================= */
.card .table {
    margin: -24px;
    width: calc(100% + 48px);
}

.card .table th:first-child,
.card .table td:first-child {
    padding-right: 24px;
}

.card .table th:last-child,
.card .table td:last-child {
    padding-left: 24px;
}

/* =============================================
   Print Styles
   ============================================= */
@media print {
    .sidebar,
    .content-header,
    .btn,
    .actions,
    .no-print {
        display: none !important;
    }

    .main-content {
        margin: 0;
    }

    .content-body {
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 1400px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1200px) {
    .content-body {
        padding: 24px 28px;
    }

    .content-header {
        padding: 20px 28px;
    }
}

@media (max-width: 992px) {
    .form-row {
        grid-template-columns: 1fr;
    }

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

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1100;
    width: 48px;
    height: 48px;
    background: var(--black);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-shadow: var(--shadow-md);
}

.mobile-menu-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--white);
    border-radius: 2px;
    transition: all 200ms ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Mobile Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 280ms ease;
}

.sidebar-overlay.active {
    opacity: 1;
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }

    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        pointer-events: auto;
    }

    .sidebar {
        transform: translateX(100%);
        transition: transform 280ms ease;
        width: 280px;
    }

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

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

    .content-header {
        padding: 18px 20px;
        padding-right: 76px;
    }

    .content-body {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-card .stat-value {
        font-size: 1.625rem;
    }

    .invoice-item {
        grid-template-columns: 1fr;
    }

    .invoice-item > *:last-child {
        justify-self: end;
    }

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

    /* Card responsive */
    .card {
        border-radius: var(--radius);
    }

    .card-header {
        padding: 16px;
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .card-header .btn {
        width: 100%;
        justify-content: center;
    }

    .card-body {
        padding: 16px;
    }

    /* Table responsive - scroll container */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }

    .table {
        min-width: 600px;
    }

    .table th,
    .table td {
        padding: 12px 10px;
        font-size: 0.8125rem;
    }

    /* Action buttons stack */
    .table .actions {
        flex-direction: column;
        gap: 6px;
        min-width: 80px;
    }

    .table .actions .btn {
        width: 100%;
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    /* Form responsive */
    .form-row {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-actions {
        flex-direction: column;
        gap: 10px;
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* Filter forms */
    .d-flex.gap-2 {
        flex-direction: column;
    }

    .d-flex.gap-1 {
        flex-direction: column;
        width: 100%;
    }

    /* Modal responsive */
    .modal-box {
        margin: 16px;
        max-width: calc(100% - 32px);
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 16px;
    }

    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Alert responsive */
    .alert {
        padding: 12px 16px;
        font-size: 0.875rem;
    }

    /* Pagination responsive */
    .pagination {
        flex-wrap: wrap;
        gap: 4px;
    }

    .pagination-link {
        min-width: 36px;
        height: 36px;
        padding: 6px 10px;
        font-size: 0.8125rem;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .content-body {
        padding: 12px;
    }

    .card-header {
        padding: 14px;
    }

    .card-body {
        padding: 14px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card .stat-value {
        font-size: 1.375rem;
    }

    .stat-card .stat-label {
        font-size: 0.75rem;
    }

    .table {
        min-width: 500px;
    }

    .table th,
    .table td {
        padding: 10px 8px;
        font-size: 0.75rem;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.875rem;
    }

    .btn-sm {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}

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

.text-success { color: var(--black) !important; }
.text-danger { color: var(--red) !important; }
.text-warning { color: var(--red) !important; }
.text-muted { color: var(--text-muted) !important; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }

.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.align-center { align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }

.w-100 { width: 100%; }
.hidden { display: none; }
