:root {
    --primary: #06319A;
    --primary-soft: rgba(6, 49, 154, 0.05);
    --accent: #34c759;
    --accent-soft: rgba(52, 199, 89, 0.1);
    --warning: #ff9f0a;
    --warning-soft: rgba(255, 159, 10, 0.1);
    --danger: #ff3b30;
    --danger-soft: rgba(255, 59, 48, 0.1);
    --bg: #f5f5f7;
    --card-bg: rgba(255, 255, 255, 0.8);
    --text: #1d1d1f;
    --text-soft: #86868b;
    --radius: 20px;
    --radius-sm: 12px;
    --glass: blur(20px) saturate(180%);
    --border: rgba(255, 255, 255, 0.3);
    
    /* Layout Stability */
    --sidebar-width: 280px;
    --header-height: 70px;
}

* { box-sizing: border-box; }

body { 
    font-family: 'Outfit', -apple-system, sans-serif; 
    background: var(--bg); 
    color: var(--text); 
    margin: 0; 
    padding: 0;
    line-height: 1.5;
}

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

.grid-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 20px;
}

.tile-card {
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
    transition: all 0.3s ease;
}

.tile-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 45px rgba(0,0,0,0.08);
}

.tile-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tile-icon i {
    width: 28px;
    height: 28px;
}

.tile-footer {
    margin-top: auto;
    font-weight: 800;
    font-size: 18px;
}

/* Dashboard & Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    text-align: center;
    padding: 30px !important;
}

.stat-card label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-soft);
    text-transform: uppercase;
    display: block;
    margin-bottom: 10px;
}

.stat-card p {
    font-size: 32px;
    font-weight: 800;
    margin: 0;
    letter-spacing: -1px;
}

.chart-container {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 250px;
    gap: 15px;
    margin-top: 40px;
    padding-bottom: 30px;
}

.chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    position: relative;
    min-width: 20px;
}

.chart-bar-inner {
    width: 100%;
    border-radius: 8px 8px 0 0;
    position: relative;
    transition: all 0.3s ease;
    min-height: 4px;
}

.top-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.top-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--primary-soft);
    border-radius: 12px;
    transition: all 0.2s;
}

.top-item:hover { background: rgba(0,0,0,0.02); }

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(0,0,0,0.05);
}

/* Tabs */
.tabs-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding-bottom: 15px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    position: relative;
    mask-image: linear-gradient(to right, black 90%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 90%, transparent 100%);
}

.tabs-nav::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 12px 20px;
    border-radius: 15px;
    font-weight: 700;
    color: var(--text-soft);
    cursor: pointer;
    transition: 0.3s;
    white-space: nowrap;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-btn i, .tab-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5px;
}

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

/* Settings Specific */
.lang-section {
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.lang-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    margin-bottom: 15px;
    color: var(--primary);
}

.form-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.form-header i {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 15px rgba(6, 49, 154, 0.2);
}

/* Lang Section and Form Header are now consolidated */

.lang-label {
    margin: 0 0 15px 0;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Project & Listing Styles */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.project-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: 0.3s;
}

.project-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.project-info img {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    object-fit: cover;
    background: var(--primary-soft);
}

.project-usage {
    background: var(--bg);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-ring {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    color: var(--accent);
}

/* Billing Rows */
.pricing-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 15px;
    margin-bottom: 15px;
    padding: 20px;
    background: var(--bg);
    border: 1px solid var(--primary-soft);
    border-radius: 15px;
}

.pricing-row > div {
    flex: 1;
    min-width: 120px;
}

.pricing-row > .btn-danger {
    padding: 14px;
    height: 48px;
    width: 48px;
    flex: 0 0 auto;
}

.tier-card {
    padding: 25px;
    background: var(--bg);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    margin-bottom: 25px;
}

.tier-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 15px;
    flex-wrap: wrap;
}

.tier-header input {
    font-size: 20px;
    font-weight: 800;
    border: none !important;
    background: transparent !important;
    color: var(--primary);
    width: auto;
    flex: 1;
    padding: 0;
}

.sidebar {
    width: 280px;
    background: var(--card-bg);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    border-right: 1px solid rgba(255,255,255,0.3);
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
    will-change: transform, width;
}

.sidebar-logo {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
    margin-bottom: 40px;
    padding-left: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.sidebar-links a {
    text-decoration: none;
    color: var(--text-soft);
    font-size: 15px;
    font-weight: 600;
    padding: 12px 18px;
    border-radius: 15px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-links a:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-links a.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 15px rgba(6, 49, 154, 0.2);
}

.main-content {
    flex: 1;
    margin-left: 280px;
    padding: 40px 60px; /* Increased horizontal padding */
    width: calc(100% - var(--sidebar-width));
    box-sizing: border-box;
    will-change: margin-left, width;
}

.nav-icon { width: 20px; height: 20px; stroke-width: 2.5px; }

/* Legacy Nav (Keep for non-sidbar pages if needed) */
.admin-nav { 
    display: none; 
}

.container { max-width: 1100px; margin: 40px auto; padding: 0 20px; }

.card { 
    background: var(--card-bg); backdrop-filter: var(--glass); -webkit-backdrop-filter: var(--glass);
    padding: 35px; border-radius: var(--radius); border: 1px solid rgba(255,255,255,0.3);
    box-shadow: 0 8px 32px rgba(0,0,0,0.03); margin-bottom: 25px;
}

h1 { font-size: 32px; font-weight: 800; margin-bottom: 30px; letter-spacing: -1px; }
h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; color: var(--primary); }

/* Table Responsiveness */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
    border-radius: 15px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px; /* Force scroll on small mobile */
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }

label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-soft); display: block; margin-bottom: 8px; letter-spacing: 0.5px; }

input, textarea, select { 
    width: 100%; padding: 14px; border-radius: 15px; border: 1px solid rgba(0,0,0,0.1); 
    background: rgba(255,255,255,0.5); font-family: inherit; font-size: 15px; outline: none; transition: border 0.3s;
    box-sizing: border-box;
}

input:focus, textarea:focus { border-color: var(--primary); }

input[type="color"] {
    height: 45px;
    padding: 5px;
    cursor: pointer;
}

/* Premium Color Picker */
.color-field-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.5);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 15px;
    padding: 8px 12px;
    transition: all 0.3s ease;
}

.color-field-wrapper:focus-within {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.color-preview-swatch {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer;
    flex-shrink: 0;
    background-image: linear-gradient(45deg, #ccc 25%, transparent 25%), 
                      linear-gradient(-45deg, #ccc 25%, transparent 25%), 
                      linear-gradient(45deg, transparent 75%, #ccc 75%), 
                      linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
    position: relative;
    overflow: hidden;
}

.color-preview-swatch div {
    position: absolute;
    inset: 0;
}

.color-hex-input {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
}

.btn { 
    display: inline-flex; align-items: center; justify-content: center;
    padding: 14px 28px; border-radius: 15px; cursor: pointer; font-weight: 700; border: none; 
    font-size: 15px; transition: all 0.3s ease; text-decoration: none; font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(0,0,0,0.15); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: rgba(255, 59, 48, 0.1); color: #ff3b30; }

.mobile-header { display: none; }

@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        height: 100vh;
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        flex-direction: column;
        padding: 30px 20px;
        z-index: 2100;
        background: var(--card-bg);
        border-radius: 0;
        box-shadow: 20px 0 50px rgba(0,0,0,0.1);
    }

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

    .sidebar-logo { display: flex; margin-bottom: 30px; }
    
    .sidebar-links {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }

    .sidebar-links a {
        flex-direction: row;
        padding: 12px 18px;
        font-size: 15px;
        gap: 12px;
        border-radius: 15px;
    }

    .sidebar div[style*="margin-top:auto"] {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 80px 20px 20px; /* Added top padding for mobile header */
        width: 100%;
    }

    .form-row { grid-template-columns: 1fr; gap: 15px; }
    h1 { font-size: 24px; text-align: left; margin-bottom: 20px; }
    .card { padding: 20px 15px; margin-bottom: 15px; }
    
    .tabs-nav {
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 10px;
        margin-bottom: 20px;
        gap: 8px;
    }
    
    .tabs-nav .tab-btn {
        padding: 10px 15px;
        font-size: 13px;
    }

    /* Mobile Header Toggle */
    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px 20px;
        background: var(--card-bg);
        backdrop-filter: var(--glass);
        -webkit-backdrop-filter: var(--glass);
        position: fixed;
        top: 0; left: 0; right: 0;
        z-index: 2000;
        border-bottom: 1px solid rgba(255,255,255,0.3);
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        backdrop-filter: blur(5px);
        z-index: 2050;
    }
    
    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    .chart-container {
        height: 200px;
        gap: 5px;
    }
    
    .chart-bar-inner span {
        font-size: 10px !important;
        top: -20px !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

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

    .login-card {
        padding: 30px !important;
        margin: 20px;
    }
}

/* Login Page Utilities */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    overflow: hidden;
}

.login-card {
    background: var(--card-bg);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    padding: 50px;
    border-radius: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    text-align: center;
    z-index: 10;
}

.login-logo {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1.5px;
    margin-bottom: 10px;
}

.login-subtitle {
    color: var(--text-soft);
    margin-bottom: 30px;
    font-size: 15px;
}

/* Animations */
.animate-fade {
    animation: fadeIn 0.4s ease-out;
}

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

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

.toast-animate {
    animation: toastIn 0.6s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

/* New Toast System */
.jarvis-toast {
    position: fixed;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    background: var(--primary);
    background: linear-gradient(135deg, var(--primary), #4263eb);
    color: #fff;
    padding: 14px 28px;
    border-radius: 50px;
    font-weight: 700;
    box-shadow: 0 15px 35px rgba(6, 49, 154, 0.3);
    display: flex;
    align-items: center;
    gap: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
}

/* Success Banner (Portal Dashboard) */
.success-banner {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    padding: 25px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    animation: slideDownIn 0.6s cubic-bezier(0.19, 1, 0.22, 1) forwards;
    box-shadow: 0 10px 30px rgba(52, 199, 89, 0.1);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
}

.success-icon {
    width: 48px;
    height: 48px;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 5px 15px rgba(52, 199, 89, 0.4);
}

.success-icon i {
    width: 24px;
    height: 24px;
    animation: checkPulse 2s infinite;
}

@keyframes checkPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

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

/* Form Actions Sticky */
.form-actions {
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
}
