/* ============================================
   کارشیو | Carchive - Main Styles
   Theme: Light Blue / White / Dark Blue
   Mobile-First Responsive + RTL
   ============================================ */

:root {
    /* Primary Colors */
    --primary-dark: #0d47a1;
    --primary: #1565c0;
    --primary-light: #1976d2;
    --primary-lighter: #42a5f5;
    
    /* Backgrounds */
    --bg-main: #f5f9fc;
    --bg-card: #ffffff;
    --bg-light-blue: #e3f2fd;
    --bg-soft: #f0f7ff;
    
    /* Text */
    --text-dark: #1a237e;
    --text-primary: #0d47a1;
    --text-secondary: #546e7a;
    --text-muted: #90a4ae;
    --text-white: #ffffff;
    
    /* Accents */
    --success: #2e7d32;
    --success-bg: #e8f5e9;
    --warning: #f9a825;
    --warning-bg: #fff8e1;
    --danger: #c62828;
    --danger-bg: #ffebee;
    --info: #0288d1;
    --info-bg: #e1f5fe;
    
    /* Borders & Shadows */
    --border-color: #e0e7ef;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    --shadow-sm: 0 2px 8px rgba(13, 71, 161, 0.08);
    --shadow: 0 4px 16px rgba(13, 71, 161, 0.12);
    --shadow-lg: 0 8px 24px rgba(13, 71, 161, 0.15);
    
    /* Spacing */
    --nav-height: 56px;
    --bottom-nav-height: 64px;
    --side-menu-width: 280px;
    
    /* Transitions */
    --transition: all 0.25s ease;
}

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

html {
    font-size: 14px; /* پایه کوچکتر برای موبایل - خوانایی بهتر در صفحات کوچک */
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

@media (min-width: 768px) {
    html {
        font-size: 15.5px;
    }
}

@media (min-width: 1024px) {
    html {
        font-size: 16px;
    }
}

body {
    font-family: 'Vazirmatn', 'Tahoma', 'Segoe UI', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-dark);
    line-height: 1.65;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    font-weight: 400;
    letter-spacing: -0.01em;
}

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

ul, ol {
    list-style: none;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    border: none;
    outline: none;
    background: none;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Utility */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

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

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* Loading Screen */
.loading-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: white;
}

.loading-content {
    text-align: center;
}

.logo-loader {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 1.5s infinite;
}

.loading-content h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.loading-content p {
    font-size: 1rem;
    opacity: 0.85;
    letter-spacing: 2px;
    margin-bottom: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

/* Top Navbar */
.top-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 100;
}

.navbar-right, .navbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary-dark);
}

.brand i {
    color: var(--primary);
    font-size: 1.2rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background: transparent;
    transition: var(--transition);
    cursor: pointer;
    position: relative;
}

.icon-btn:hover, .icon-btn:active {
    background: var(--bg-light-blue);
    color: var(--primary);
}

.badge-container .badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Side Menu (Drawer) */
.side-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--side-menu-width);
    max-width: 85vw;
    height: 100%;
    height: 100dvh;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.side-menu.open {
    transform: translateX(0);
}

.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 71, 161, 0.4);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.menu-overlay.show {
    opacity: 1;
    visibility: visible;
}

.side-menu-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    padding: 1.5rem 1.25rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

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

.avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    overflow: hidden;
    flex-shrink: 0;
}

.user-details h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.user-details p {
    font-size: 0.8rem;
    opacity: 0.85;
}

.close-btn {
    color: white !important;
    background: rgba(255,255,255,0.15) !important;
}

.side-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.side-nav ul li a {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1.25rem;
    color: var(--text-secondary);
    font-weight: 500;
    transition: var(--transition);
    border-right: 3px solid transparent;
}

.side-nav ul li a i {
    width: 22px;
    text-align: center;
    font-size: 1.1rem;
}

.side-nav ul li a:hover,
.side-nav ul li.active a {
    background: var(--bg-light-blue);
    color: var(--primary-dark);
    border-right-color: var(--primary);
}

.side-menu-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

.btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

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

/* Content Area */
.content-area {
    padding-top: calc(var(--nav-height) + 1rem);
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 2.75rem);
    padding-left: 1rem;
    padding-right: 1rem;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-card);
    box-shadow: 0 -2px 12px rgba(13, 71, 161, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 400;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    flex: 1;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    transition: var(--transition);
    position: relative;
}

.nav-item i {
    font-size: 1.25rem;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

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

@media (min-width: 768px) {
    .card-title {
        font-size: 1.05rem;
    }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

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

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

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline:hover {
    background: var(--bg-light-blue);
}

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

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

.btn-sm {
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.15rem;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-soft);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-dark);
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23546e7a' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 1rem center;
    padding-left: 2.5rem;
}

/* Toggle Switch for visibility */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    width: 44px;
    height: 24px;
    background: #cfd8dc;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    top: 2px;
    right: 2px;
    transition: var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::after {
    transform: translateX(-20px);
}

/* Alert Banner (for missing docs) */
.alert-banner {
    background: var(--warning-bg);
    border: 1px solid #ffe082;
    border-radius: var(--border-radius-sm);
    padding: 0.85rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1rem;
    color: #f57f17;
}

.alert-banner.danger {
    background: var(--danger-bg);
    border-color: #ef9a9a;
    color: var(--danger);
}

.alert-banner.info {
    background: var(--info-bg);
    border-color: #81d4fa;
    color: var(--info);
}

.alert-banner i {
    font-size: 1.2rem;
    margin-top: 0.1rem;
}

.alert-banner .alert-content {
    flex: 1;
}

.alert-banner .alert-content strong {
    display: block;
    margin-bottom: 0.2rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1.1rem;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.stat-card .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.6rem;
    font-size: 1.15rem;
}

.stat-card .stat-icon.blue { background: var(--bg-light-blue); color: var(--primary); }
.stat-card .stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-card .stat-icon.orange { background: var(--warning-bg); color: var(--warning); }
.stat-card .stat-icon.red { background: var(--danger-bg); color: var(--danger); }

.stat-card .stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

@media (min-width: 768px) {
    .stat-card .stat-value {
        font-size: 1.4rem;
    }
    .stat-card .stat-label {
        font-size: 0.8rem;
    }
}

/* Page Header */
.page-header {
    margin-bottom: 1.25rem;
}

.page-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.2rem;
}

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

@media (min-width: 768px) {
    .page-header h1 {
        font-size: 1.35rem;
    }
    .page-header p {
        font-size: 0.9rem;
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    opacity: 0.4;
    color: var(--primary-lighter);
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 1.25rem);
    left: 1.25rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 16px rgba(13, 71, 161, 0.4);
    cursor: pointer;
    z-index: 90;
    transition: var(--transition);
    border: none;
}

.fab:hover, .fab:active {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(13, 71, 161, 0.5);
}

/* Badge / Tag */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.tag-success { background: var(--success-bg); color: var(--success); }
.tag-warning { background: var(--warning-bg); color: #e65100; }
.tag-danger { background: var(--danger-bg); color: var(--danger); }
.tag-info { background: var(--info-bg); color: var(--info); }
.tag-primary { background: var(--bg-light-blue); color: var(--primary); }

/* List Item (cars, customers) */
.list-item {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: 1rem;
    align-items: center;
    transition: var(--transition);
    cursor: pointer;
}

.list-item:active {
    transform: scale(0.98);
    background: var(--bg-soft);
}

.list-item .item-img {
    width: 72px;
    height: 72px;
    border-radius: var(--border-radius-sm);
    object-fit: cover;
    background: var(--bg-light-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-lighter);
    font-size: 1.8rem;
    flex-shrink: 0;
}

.list-item .item-body {
    flex: 1;
    min-width: 0;
}

.list-item .item-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-dark);
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item .item-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.list-item .item-price {
    font-weight: 700;
    color: var(--primary);
    font-size: 0.95rem;
    white-space: nowrap;
}

/* Progress Steps (for sales process) */
.steps {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    position: relative;
}

.steps::before {
    content: '';
    position: absolute;
    top: 16px;
    right: 20px;
    left: 20px;
    height: 3px;
    background: var(--border-color);
    z-index: 0;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
    flex: 1;
}

.step-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 3px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.step.active .step-circle {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.step.completed .step-circle {
    border-color: var(--success);
    background: var(--success);
    color: white;
}

.step-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    max-width: 60px;
}

.step.active .step-label {
    color: var(--primary);
    font-weight: 600;
}

/* Responsive - Tablet and up */
@media (min-width: 768px) {
    .content-area {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
        max-width: 900px;
        margin: 0 auto;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .bottom-nav {
        display: none;
    }
    
    .content-area {
        padding-bottom: 2rem;
    }
    
    .fab {
        bottom: 2rem;
        left: 2rem;
    }
}

@media (min-width: 1024px) {
    .side-menu {
        transform: translateX(0);
        box-shadow: none;
        border-left: 1px solid var(--border-color);
    }
    
    .menu-overlay {
        display: none !important;
    }
    
    #menu-toggle {
        display: none;
    }
    
    .content-area {
        margin-right: var(--side-menu-width);
        max-width: none;
    }
    
    .top-navbar {
        right: var(--side-menu-width);
    }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    }
}

/* مودال‌های پایین‌صفحه باید بالای منوی پایین بایستند */
#pay-modal,
#cb-detail-modal,
#cub-detail-modal,
#hist-detail-modal,
[id$="-modal"] {
    z-index: 1200 !important;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px)) !important;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}
#pay-modal > div,
#cb-detail-modal > div,
#cub-detail-modal > div,
#hist-detail-modal > div,
[id$="-modal"] > div {
    margin-bottom: 0;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    max-height: calc(92vh - var(--bottom-nav-height) - env(safe-area-inset-bottom, 0px));
}

html, body {
    min-height: 100%;
    overscroll-behavior-y: none;
}
body {
    padding-bottom: 0;
}


/* Brand logo in top navbar */
.top-navbar .brand {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}
.top-navbar .brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: contain;
    background: rgba(255,255,255,0.12);
}
