:root {
    --primary: #4361ee;
    --primary-hover: #3a0ca3;
    --secondary: #f8f9fa;
    --success: #2ecc71;
    --success-hover: #27ae60;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --text-main: #2b2d42;
    --text-muted: #8d99ae;
    --border: #e2e8f0;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(0,0,0,0.05);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark-mode {
    --bg: #121212;
    --surface: #1e1e1e;
    --text-main: #f0f2f5;
    --text-muted: #a0a0a0;
    --border: #333333;
    --shadow: 0 10px 30px rgba(0,0,0,0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Vazirmatn', sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Login Wrapper */
.login-wrapper {
    display: none;
    width: 100%;
    height: 100vh;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    position: fixed;
    top: 0; left: 0; z-index: 100;
}
.login-wrapper.active {
    display: flex;
}
.login-card {
    background: var(--surface);
    padding: 3rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    position: relative;
}

.theme-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    box-shadow: var(--shadow);
    transition: var(--transition);
}
.theme-toggle:hover {
    transform: scale(1.1);
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--surface);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    box-shadow: 2px 0 10px rgba(0,0,0,0.02);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 3rem;
}

.mobile-menu-toggle {
    display: none;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #4cc9f0);
    border-radius: 12px;
}

.logo h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-hover);
}

.nav-links {
    list-style: none;
    flex-grow: 1;
}

.nav-links li {
    margin-bottom: 0.5rem;
}

.nav-links a {
    display: flex;
    align-items: center;
    padding: 1rem 1.2rem;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: 12px;
    font-weight: 600;
    transition: var(--transition);
}

.nav-links a:hover, .nav-links a.active {
    background: var(--primary);
    color: white;
    transform: translateX(-5px);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 12px;
    margin-top: auto;
}

.avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: bold;
}

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

.details .name {
    font-weight: 600;
    font-size: 0.9rem;
}

.details .role {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex-grow: 1;
    padding: 2rem 3rem;
    overflow-y: auto;
}

.topbar {
    margin-bottom: 2rem;
}

.topbar h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.topbar p {
    color: var(--text-muted);
}

/* Views */
.view-section {
    display: none;
    animation: fadeIn 0.4s ease-in-out;
}

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

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

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

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

.card-header p {
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Forms */
.form-card {
    max-width: 600px;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-main);
}

input[type="text"], input[type="number"], input[type="email"], input[type="password"], input[type="date"], input[type="time"], textarea {
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    transition: var(--transition);
    background: var(--bg);
    color: var(--text-main);
    font-family: inherit;
}

input[type="text"]:focus, input[type="number"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="date"]:focus, input[type="time"]:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(67, 97, 238, 0.1);
    background: var(--surface);
}

/* Buttons */
.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
}

.btn-success {
    background: var(--success);
    color: white;
    width: 100%;
    justify-content: center;
    padding: 1rem;
    margin-top: 1rem;
}

.btn-success:hover {
    background: var(--success-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--border);
}

/* Location */
.location-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.status-badge {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.status-badge.success {
    background: rgba(46, 204, 113, 0.1);
    color: var(--success);
}

.status-badge.pending {
    background: rgba(243, 156, 18, 0.1);
    color: #f39c12;
}

.status-badge.active-proj {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.status-badge.completed {
    background: rgba(46, 204, 113, 0.1);
    color: #2ecc71;
}

.status-badge.cancelled {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

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

.data-table th, .data-table td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--text-muted);
    font-weight: 600;
}

.data-table tr:hover td {
    background: rgba(240, 242, 245, 0.5);
}

/* Media Queries for Mobile Responsiveness */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 1rem;
        border-left: none;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        z-index: 20;
    }

    .logo {
        margin-bottom: 0;
        justify-content: flex-start;
        width: 100%;
        display: flex;
        align-items: center;
    }

    .mobile-menu-toggle {
        display: block !important;
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 8px;
        font-size: 1.8rem;
        color: var(--primary);
        cursor: pointer;
        padding: 0.2rem 0.8rem;
    }

    .nav-links {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        margin-top: 0;
        transition: max-height 0.4s ease-in-out, opacity 0.3s ease-in-out, margin-top 0.3s;
    }
    
    .nav-links.active {
        max-height: 500px;
        opacity: 1;
        margin-top: 1rem;
    }

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

    .nav-links li {
        margin-bottom: 0;
        width: 100%;
    }

    .nav-links a {
        padding: 0.8rem 1.2rem;
        font-size: 1rem;
        display: block;
        text-align: center;
    }

    .user-info {
        margin-top: 0;
        padding: 0;
        background: transparent;
        position: absolute;
        top: 1.5rem;
        left: 1rem;
    }
    .user-info .details, .user-info .avatar {
        display: none;
    }
    .user-info button {
        margin: 0 !important;
        padding: 0.5rem 1rem !important;
        font-size: 0.8rem;
    }

    .theme-toggle {
        top: auto;
        bottom: 20px;
        left: 20px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    }

    .main-content {
        padding: 1rem;
        padding-top: 1.5rem;
        padding-bottom: 5rem; /* space for theme toggle */
    }

    .topbar h1 {
        font-size: 1.5rem;
    }

    .card {
        padding: 1rem;
    }

    .login-card {
        padding: 1.5rem;
        margin: 1rem;
    }

    .location-wrapper {
        flex-direction: column;
        align-items: stretch;
    }

    .location-wrapper .btn {
        width: 100%;
        justify-content: center;
    }

    /* Override inline styles for dynamic elements */
    #products-checklist > div > div {
        grid-template-columns: 1fr !important;
    }

    .contact-row {
        flex-direction: column;
    }

    .contact-row button {
        padding: 0.8rem !important;
        margin-top: 0.2rem;
    }

    /* Custom product form */
    #add-custom-product-btn {
        margin-top: 0.5rem;
    }
    
    div[style*="display: flex; gap: 0.5rem;"] {
        flex-direction: column;
    }

    .table-responsive {
        border: 1px solid var(--border);
        border-radius: 10px;
    }

    .data-table th, .data-table td {
        padding: 0.8rem 0.5rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }
}

/* Custom Alert / Toast */
.custom-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--surface);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 4px solid var(--primary);
}

.custom-toast.show {
    transform: translateY(0);
    opacity: 1;
}

.custom-toast.success { border-right-color: var(--success); }
.custom-toast.error { border-right-color: #e74c3c; }
.custom-toast.info { border-right-color: var(--primary); }

/* Custom Modal Confirm */
.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    backdrop-filter: blur(3px);
}
.custom-modal-overlay.active { display: flex; }

.custom-modal {
    background: var(--surface);
    padding: 2rem;
    border-radius: 15px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.custom-modal h3 { margin-bottom: 1rem; color: var(--text-main); }
.custom-modal .modal-actions {
    display: flex; gap: 1rem; justify-content: center; margin-top: 1.5rem;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--surface);
    margin: auto;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: scaleIn 0.3s ease;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-main);
}

.close-modal {
    color: var(--text-muted);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover,
.close-modal:focus {
    color: var(--error);
    text-decoration: none;
    cursor: pointer;
}

/* TomSelect Overrides */
.ts-wrapper { direction: rtl; text-align: right; }
.ts-control { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text-main); padding: 0.8rem; }
.ts-wrapper.single .ts-control { background: var(--bg); color: var(--text-main); }
.ts-dropdown { background: var(--bg); border: 1px solid var(--border); color: var(--text-main); text-align: right; border-radius: 8px; }
.ts-dropdown .active { background: var(--surface); color: var(--primary); }
.ts-dropdown .option { padding: 0.8rem; }
.ts-control > input { color: var(--text-main); }

/* Responsive Calendar */
.cal-wrapper {
    width: 100%;
}
.cal-day-cell {
    background: var(--surface);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    cursor: pointer;
    position: relative;
    border-bottom: 1px solid var(--border);
    border-left: 1px solid var(--border);
    min-height: 100px;
    transition: background 0.2s;
}
.cal-day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.cal-day-number {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: var(--text-main);
}
.cal-day-number.today {
    background: var(--primary);
    color: white;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(67,97,238,0.4);
}
.cal-tasks-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}
.cal-tasks-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    max-height: 150px;
    scrollbar-width: none;
}
.cal-tasks-container::-webkit-scrollbar { display: none; }

.cal-task-item {
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    border-right: 3px solid;
    cursor: pointer;
    transition: all 0.2s;
}

.cal-header-cell .short-day { display: none; }

@media (max-width: 768px) {
    .cal-header-cell {
        padding: 0.5rem !important;
        font-size: 0.8rem !important;
    }
    .cal-header-cell .full-day { display: none; }
    .cal-header-cell .short-day { display: inline; }
    
    .cal-day-cell {
        min-height: 60px;
        padding: 0.2rem;
        gap: 0.1rem;
    }
    .cal-day-number {
        width: 22px;
        height: 22px;
        font-size: 0.8rem;
    }
    .cal-tasks-count { display: none; }
    
    .cal-task-item {
        border-right: 0 !important;
        border-radius: 50%;
        width: 6px;
        height: 6px;
        padding: 0;
        margin: 0 2px;
        display: inline-block;
    }
    .cal-tasks-container {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 2px;
        align-items: flex-start;
        align-content: flex-start;
    }
    .cal-task-details {
        display: none;
    }
}
