:root {
    --primary: #4f46e5;
    --primary-light: #eef2ff;
    --primary-dark: #4338ca;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #0f172a;
    --sidebar-bg: #ffffff;
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
    --info: #0ea5e9;
    --gray: #64748b;
    --gray-light: #f8fafc;
    --border: #e2e8f0;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: #ffffff;
    color: var(--text);
    padding: 0;
    position: fixed;
    height: 100vh;
    z-index: 100;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e2e8f0;
}

.sidebar .logo {
    padding: 1.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid #f1f5f9;
}

.sidebar .logo a {
    background: transparent;
    padding: 0;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    transition: 0.2s;
}

.sidebar .logo a:hover {
    background: transparent;
    opacity: 0.8;
}

.sidebar .logo img {
    max-height: 40px;
    max-width: 100%;
    width: auto;
    object-fit: contain;
    transition: transform 0.2s;
}

/* Auth Pages Logo */
.auth-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.auth-logo img {
    max-height: 100px;
    width: auto;
    object-fit: contain;
}

.sidebar ul { 
    list-style: none; 
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar ul li a {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #64748b;
    font-size: 14px;
    text-decoration: none;
    border-radius: 0.5rem;
    margin-bottom: 0.25rem;
    transition: 0.2s;
    font-weight: 500;
}

.sidebar ul li a i {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.75rem;
    opacity: 0.8;
}

.sidebar ul li a:hover {
    background: #f1f5f9;
    color: var(--text);
}

.sidebar ul li a:hover i {
    opacity: 1;
}

.sidebar ul li a.active {
    background: var(--primary);
    color: #ffffff;
    font-weight: 600;
}

.sidebar ul li a.active i {
    opacity: 1;
    color: #ffffff;
}

.sidebar ul li:last-child {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid #f1f5f9;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid #f1f5f9;
    background: #ffffff;
    margin-top: auto;
    flex-shrink: 0;
}

.user-profile-vertical {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.user-info-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.user-info-center .name {
    font-size: 0.875rem;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -0.01em;
}

.role-badge-pill {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.role-badge-pill.role-staff { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }
.role-badge-pill.role-manager { background: #e0f2fe; color: #0ea5e9; border: 1px solid #bae6fd; }
.role-badge-pill.role-admin { background: #dcfce7; color: #10b981; border: 1px solid #bbf7d0; }
.role-badge-pill.role-super_admin { background: #eef2ff; color: #4f46e5; border: 1px solid #c7d2fe; }

.logout-button-full {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.85rem;
    background: #ffffff;
    color: #ef4444;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 700;
    border-radius: 12px;
    border: 1px solid #fee2e2;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.logout-button-full:hover {
    background: #ef4444;
    color: #ffffff;
    border-color: #ef4444;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.logout-button-full i {
    width: 1.2rem;
    height: 1.2rem;
}

/* Skeleton Loader */
.skeleton {
    background: #e2e8f0;
    background: linear-gradient(110deg, #ececec 8%, #f5f5f5 18%, #ececec 33%);
    border-radius: 5px;
    background-size: 200% 100%;
    animation: 1.5s shine linear infinite;
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
}

.skeleton-text:last-child {
    margin-bottom: 0;
    width: 80%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

@keyframes shine {
    to {
        background-position-x: -200%;
    }
}

/* Main Content */
.content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem;
    min-height: 100vh;
    animation: pageFadeIn 0.3s ease-out;
}

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

header {
    margin-bottom: 2rem;
}

header h1 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #e2e8f0;
    background: white;
    color: var(--text);
    transition: 0.2s;
}

.btn:hover {
    background: #f1f5f9;
}

.btn-primary {
    background: #2563EB;
    color: white;
    border: none;
}

.btn-primary:hover {
    background: #1d4ed8;
}

/* Standardized Button Colors */
.btn-amber { background-color: #F59E0B !important; color: white !important; border: none !important; }
.btn-amber:hover { background-color: #D97706 !important; }
.btn-blue { background-color: #2563EB !important; color: white !important; border: none !important; }
.btn-blue:hover { background-color: #1D4ED8 !important; }

.btn-indigo { background-color: #4F46E5 !important; color: white !important; border: none !important; }
.btn-indigo:hover { background-color: #4338CA !important; }

.btn-teal { background-color: #0D9488 !important; color: white !important; border: none !important; }
.btn-teal:hover { background-color: #0F766E !important; }

.btn-green { background-color: #16A34A !important; color: white !important; border: none !important; }
.btn-green:hover { background-color: #15803D !important; }

.btn-orange { background-color: #EA580C !important; color: white !important; border: none !important; }
.btn-orange:hover { background-color: #C2410C !important; }

.btn-gray { background-color: #374151 !important; color: white !important; border: none !important; }
.btn-gray:hover { background-color: #1F2937 !important; }

/* KPI Row */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--primary);
}

.kpi-card.kpi-clients::before { background: var(--info); }
.kpi-card.kpi-projects::before { background: var(--primary); }
.kpi-card.kpi-subscriptions::before { background: var(--success); }
.kpi-card.kpi-mrr::before { background: var(--warning); }

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.kpi-card.kpi-clients:hover { box-shadow: 0 10px 15px -3px rgba(14, 165, 233, 0.2); }
.kpi-card.kpi-projects:hover { box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.2); }
.kpi-card.kpi-subscriptions:hover { box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.2); }
.kpi-card.kpi-mrr:hover { box-shadow: 0 10px 15px -3px rgba(245, 158, 11, 0.2); }

.kpi-card .title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--gray);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-card .number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.kpi-card .subtitle {
    font-size: 0.75rem;
    color: var(--gray);
    margin-top: 0.25rem;
}

/* Grid Layout */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: all 0.3s ease;
    border: 1px solid var(--border);
}

.card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.card h3 { 
    margin-bottom: 1.5rem; 
    font-size: 1.125rem; 
    font-weight: 600;
    display: flex; 
    align-items: center; 
    gap: 0.75rem; 
    color: var(--text);
}

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

/* Form Styles */
.form-section {
    margin-bottom: 2.5rem;
}

.form-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #f1f5f9;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

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

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #64748b;
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    height: 45px;
    padding: 0 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    font-size: 0.95rem;
    color: #1e293b;
    transition: all 0.2s;
}

textarea.form-control {
    height: auto;
    padding: 1rem;
    min-height: 100px;
}

.form-control:focus {
    outline: none;
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0 1rem;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-right: none;
    border-radius: 0.75rem 0 0 0.75rem;
    color: #64748b;
    font-weight: 500;
}

.input-group .form-control {
    border-radius: 0 0.75rem 0.75rem 0;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid #f1f5f9;
}

.btn-secondary {
    background: #E5E7EB;
    color: #374151;
    border: none;
}

.btn-secondary:hover {
    background: #d1d5db;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: #fff;
    max-width: 600px;
    margin: 5vh auto;
    border-radius: 1rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@media (max-width: 768px) {
    .modal {
        align-items: flex-end;
        display: none; /* Flex when active */
    }
    .modal[style*="display: block"] {
        display: flex !important;
    }
    .modal-content {
        margin: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 1.5rem 1.5rem 0 0;
        max-height: 90vh;
        display: flex;
        flex-direction: column;
        animation: bottomSheetSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    @keyframes bottomSheetSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .modal-body {
        flex: 1;
        overflow-y: auto;
        padding: 1.5rem;
    }
    .modal-header {
        padding: 1.25rem 1.5rem;
    }
    .modal-footer {
        padding: 1.25rem 1.5rem;
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
    }
}

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #1e293b;
}

.modal-body {
    padding: 2rem;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 1.5rem 2rem;
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Subscription Summary */
.subscription-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
}

@media (max-width: 1024px) {
    .subscription-layout {
        grid-template-columns: 1fr;
    }
}

.summary-panel {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.5rem;
    position: sticky;
    top: 2rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
}

.summary-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text);
}

.summary-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

.summary-label {
    color: var(--gray);
}

.summary-value {
    font-weight: 500;
    color: var(--text);
    text-align: right;
}

.summary-total {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 2px dashed #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.summary-total-label {
    font-weight: 600;
    color: var(--text);
}

.summary-total-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

.btn-secondary {
    background: #E5E7EB;
    color: #374151;
    border: none;
}

.btn-secondary:hover {
    background: #d1d5db;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th { 
    text-align: left; 
    padding: 1rem; 
    border-bottom: 2px solid #f1f5f9; 
    font-size: 0.75rem; 
    color: #475569; 
    text-transform: uppercase; 
    letter-spacing: 0.05em; 
    font-weight: 700;
}

td { 
    padding: 1rem; 
    border-bottom: 1px solid #f1f5f9; 
    font-size: 0.9rem; 
}

table tr:nth-child(even) {
    background-color: #f8fafc;
}

table tr:hover {
    background: #F1F5F9;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.draft { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.badge.sent { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }
.badge.paid { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.badge.partially-paid { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge.partial { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge.overdue { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

.badge.ok { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.badge.outdated { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge.missing { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* Highlights */
.highlight-today { background: #fee2e2 !important; }
.highlight-soon { background: #ffedd5 !important; }
.highlight-week { background: #fef9c3 !important; }

/* Utilities */
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-success { color: var(--success); }
.text-gray { color: var(--gray); }

.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* Mobile App Layout */
.top-app-bar {
    display: none;
}
.bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .sidebar {
        display: none !important;
    }
    .content {
        margin-left: 0 !important;
        padding: 1rem !important;
        padding-bottom: 80px !important; /* Space for bottom nav */
        padding-top: 70px !important; /* Space for top app bar */
    }
    body {
        background: #f8fafc;
    }
    
    /* Top App Bar */
    .top-app-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: #ffffff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 1rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        z-index: 50;
    }
    
    /* Bottom Navigation */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: #ffffff;
        display: flex;
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -1px 10px rgba(0,0,0,0.05);
        z-index: 50;
        padding-bottom: env(safe-area-inset-bottom);
        border-top: 1px solid #f1f5f9;
    }
    
    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #64748b;
        text-decoration: none;
        font-size: 10px;
        font-weight: 500;
        flex: 1;
        height: 100%;
        transition: color 0.2s;
    }
    
    .bottom-nav-item i {
        width: 24px;
        height: 24px;
        margin-bottom: 4px;
    }
    
    .bottom-nav-item.active {
        color: var(--primary);
    }
    
    /* Hide desktop header elements */
    header h1 {
        display: none;
    }
    
    /* Cards instead of tables */
    table {
        display: block;
        width: 100%;
    }
    table thead {
        display: none;
    }
    table tbody {
        display: block;
        width: 100%;
    }
    table tr {
        display: block;
        background: #ffffff;
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 1rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        border: 1px solid #f1f5f9;
        position: relative;
    }
    table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid #f8fafc;
        font-size: 0.875rem;
        text-align: right;
    }
    table td:last-child {
        border-bottom: none;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid #f1f5f9;
        justify-content: flex-end;
        gap: 0.5rem;
    }
    table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        font-size: 0.75rem;
        text-transform: uppercase;
        text-align: left;
        margin-right: 1rem;
    }
    
    /* Forms */
    .form-grid {
        grid-template-columns: 1fr;
    }
    .form-control {
        height: 48px; /* Larger touch target */
        font-size: 16px; /* Prevent iOS zoom */
    }
    .btn {
        min-height: 44px;
        justify-content: center;
        margin-bottom: 0.5rem;
    }
    .quick-actions {
        flex-direction: column;
    }
    .quick-actions .btn {
        width: 100%;
    }
    
    /* RTL Support */
    html[dir="rtl"] .bottom-nav {
        flex-direction: row-reverse;
    }
    html[dir="rtl"] .top-app-bar {
        flex-direction: row-reverse;
    }
    html[dir="rtl"] table td {
        text-align: left;
    }
    html[dir="rtl"] table td::before {
        text-align: right;
        margin-right: 0;
        margin-left: 1rem;
    }
}

@media print {
    .sidebar, nav.sidebar, .no-print, .logout-button-full, .sidebar-footer, [class*="no-print"] {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        height: 0 !important;
        width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        position: absolute !important;
        top: -9999px !important;
    }
    .content {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        position: static !important;
    }
    body {
        background: white !important;
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .card, .bg-white {
        box-shadow: none !important;
        border: 1px solid #e2e8f0 !important;
    }
}
