/**
 * Custom CSS for Tabler integration
 * فقط Theme Toggle که Tabler ندارد
 * و اطمینان از کارکرد Right Vertical Layout
 */

/* Sidebar Footer - تنظیمات برای نمایش در یک سطر */
.navbar-vertical .navbar-nav.mt-auto {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    /* padding: 0.5rem; */
}

.navbar-vertical .navbar-nav.mt-auto .nav-item {
    margin: 0 !important;
    flex-grow: 0; /* جلوگیری از رشد المان‌ها */
    flex-shrink: 0; /* جلوگیری از کوچک شدن المان‌ها */
}

/* کاهش ارتفاع بخش پروفایل کاربر */
.navbar-vertical .navbar-nav.mt-auto .nav-item .nav-link {
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    line-height: 1.2;
    margin: 0 !important;
}

/* حذف margin از notification و logout در footer */
.navbar-vertical .navbar-nav.mt-auto .nav-item.dropdown .nav-link,
.navbar-vertical .navbar-nav.mt-auto .nav-item:not(:first-child) .nav-link {
    margin: 0 !important;
}

.navbar-vertical .navbar-nav.mt-auto .nav-item .nav-link .avatar {
    flex-shrink: 0;
}

.navbar-vertical .navbar-nav.mt-auto .nav-item .nav-link > div {
    line-height: 1.2;
}

.navbar-vertical .navbar-nav.mt-auto .nav-item .nav-link > div > div:first-child {
    font-size: 0.875rem;
    line-height: 1.2;
}

.navbar-vertical .navbar-nav.mt-auto .nav-item .nav-link > div > div:last-child {
    font-size: 0.75rem;
    line-height: 1.2;
    margin-top: 0.125rem;
}

/* Right Vertical Layout - اطمینان از کارکرد navbar-end */
@media (min-width: 992px) {
    /* Sidebar positioning */
    .navbar-vertical.navbar-expand-lg.navbar-end {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: auto !important;
        width: 15rem !important;
        z-index: 1030 !important;
    }
    
    /* Page padding for sidebar */
    .page:has(.navbar-vertical.navbar-end) {
        padding-right: 15rem !important;
        padding-left: 0 !important;
    }
    
    /* Page wrapper margin */
    .page:has(.navbar-vertical.navbar-end) .page-wrapper {
        margin-right: 0 !important;
        margin-left: 0 !important;
    }

    .navbar-vertical.navbar-expand-lg .navbar-nav {
        flex-grow: 0;
    }
}

/* Theme Toggle - Custom */
.theme-toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Theme Toggle Wrapper - زیر لوگو */
.theme-toggle-wrapper {
    padding: 0.5rem 0;
}

.theme-toggle-label {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    cursor: pointer;
}

.theme-toggle-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 34px;
    transition: 0.3s;
    border: 1px solid rgba(0, 0, 0, 0.3);
}

.theme-toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Dark mode styles */
[data-bs-theme="dark"] .theme-toggle-slider {
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

[data-bs-theme="dark"] .theme-toggle-slider:before {
    background-color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.theme-toggle-input:checked + .theme-toggle-slider {
    background-color: rgba(0, 0, 0, 0.3);
}

[data-bs-theme="dark"] .theme-toggle-input:checked + .theme-toggle-slider {
    background-color: rgba(255, 255, 255, 0.3);
}

.theme-toggle-input:checked + .theme-toggle-slider:before {
    transform: translateX(24px);
}

.theme-icon-light,
.theme-icon-dark {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    transition: opacity 0.3s;
    z-index: 1;
}

.theme-icon-light {
    left: 6px;
    opacity: 1;
    color: #ffa500; /* Orange for sun icon */
}

.theme-icon-dark {
    right: 6px;
    opacity: 0;
    color: #4a5568; /* Dark gray for moon icon */
}

/* Dark mode icon colors */
[data-bs-theme="dark"] .theme-icon-light {
    color: #ffa500;
}

[data-bs-theme="dark"] .theme-icon-dark {
    color: #e2e8f0; /* Light gray for moon icon in dark mode */
}

.theme-toggle-input:checked ~ .theme-icon-light {
    opacity: 0;
}

.theme-toggle-input:checked ~ .theme-icon-dark {
    opacity: 1;
}

/* Action Buttons - بزرگتر کردن دکمه‌های اکشن */
.btn-actions .btn-action {
    padding: 0.5rem !important;
    min-width: 2.5rem !important;
    min-height: 2.5rem !important;
}

.btn-actions .btn-action i {
    font-size: 1.125rem !important;
    width: 1.125rem !important;
    height: 1.125rem !important;
}

/* Sidebar Menu - Hover and Active States */
.navbar-vertical .nav-link {
    transition: all 0.2s ease;
    border-radius: 0.375rem;
    margin: 0.125rem 0.5rem;
}

/* Hover State */
.navbar-vertical .nav-link:hover:not(.active) {
    background-color: rgba(var(--tblr-primary-rgb), 0.1);
    color: var(--tblr-primary);
}

[data-bs-theme="dark"] .navbar-vertical .nav-link:hover:not(.active) {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--tblr-primary);
}

/* Active State */
.navbar-vertical .nav-link.active {
    background-color: var(--tblr-primary);
    color: var(--tblr-primary-fg);
    font-weight: 500;
}

.navbar-vertical .nav-link.active .nav-link-icon {
    color: var(--tblr-primary-fg);
}

.navbar-vertical .nav-link.active .nav-link-title {
    color: var(--tblr-primary-fg);
}

/* Active State Hover */
.navbar-vertical .nav-link.active:hover {
    background-color: var(--tblr-primary);
    opacity: 0.9;
    color: var(--tblr-primary-fg);
}

/* Vehicle Plate Preview Styles */
.plate-preview-container {
    position: relative;
    width: 100%;
    height: 40px;
    /* margin: 0 auto 15px auto; */
    border: 1px solid #ddd;
    border-radius: 5px;
    overflow: hidden;
    /* box-shadow: 0 2px 8px rgba(0,0,0,0.1); */
    background-image: url('/static/images/pelak.png');
    background-size: 102% 102%;
    background-repeat: no-repeat;
    background-position: center;
}

.plate-preview-container {
    font-family: 'Vazirmatn', 'Tahoma', sans-serif;
}

.plate-preview-container input.plate-input-overlay {
    pointer-events: auto;
    background: transparent;
    border: none;
    outline: none;
    text-align: center;
    font-size: 25px;
    font-weight: bold;
    color: #000;
    font-family: 'Estedad', 'Vazirmatn', 'Tahoma', sans-serif !important;
    font-variant-numeric: persian;
    -webkit-font-feature-settings: "tnum";
    font-feature-settings: "tnum";
    padding: 6px 0 0;
    margin: 0;
    box-shadow: none;
    width: 35px;
    min-width: 30px;
    height: 100%;
}

/* Persian numerals for all numbers in display (except specific inputs) */
/* Use Tahoma or system fonts for Persian numerals since Vazirmatn has Latin numerals */
body, .card, .table, .list-group, .badge, .btn, .nav-link, .dropdown-item,
h1, h2, h3, h4, h5, h6, p, span, div, label, td, th, .form-label {
    font-variant-numeric: persian;
    -webkit-font-feature-settings: "tnum";
    font-feature-settings: "tnum";
}

/* Force Persian numerals by using Tahoma for numbers */
body, .card, .table, .list-group, .badge, .btn, .nav-link, .dropdown-item,
h1, h2, h3, h4, h5, h6, p, span, div, label, td, th, .form-label {
    font-family: 'Vazirmatn', 'Tahoma', 'Arial', sans-serif;
}

/* Use JavaScript to convert numbers to Persian in display */
/* This will be handled by a JavaScript function */

/* Number class - for displaying numbers with Persian numerals font */
.number,
.number * {
    font-family: 'Estedad', 'Vazirmatn', 'Tahoma', 'Arial', sans-serif !important;
    font-variant-numeric: persian !important;
    -webkit-font-feature-settings: "tnum" !important;
    font-feature-settings: "tnum" !important;
}

/* Plate input fields - use Estedad font */
input[name*="plate_number"],
input[name*="plate_region"],
input[name*="plate_province"],
input[name*="plate_city"],
.plate-input-overlay,
.plate-preview-container input {
    font-family: 'Estedad', 'Vazirmatn', 'Tahoma', sans-serif !important;
    font-variant-numeric: persian !important;
    -webkit-font-feature-settings: "tnum" !important;
    font-feature-settings: "tnum" !important;
}

/* But keep English numbers for inputs that need them */
input[name*="chassis"], input[type="number"], 
input[name*="kilometer"], input[name*="year"] {
    font-variant-numeric: normal;
    -webkit-font-feature-settings: normal;
    font-feature-settings: normal;
}

.plate-input-overlay input.plate-input-overlay:focus {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    outline: none !important;
    border-color: var(--tblr-primary) !important;
    box-shadow: none !important;
}

.plate-input-region {
    /* width: 120px; */
    flex-shrink: 0;
        width: 70px;
}

.plate-input-city {
    width: 50px;
    flex-shrink: 0;
}

.plate-input-number {
    width: 102px;
    flex-shrink: 0;
}

.plate-input-province {
    min-width: 30px;
}

#id_plate_region {
    width: 55px;
}

#id_plate_city {
    width: 40px;
    font-size: 26px;
    padding: 0;
}

.plate-middle-section {
    position: absolute;
    top: 5.5%;
    left: 23px;
    /* transform: translate(-50%, -50%); */
    display: flex;
    align-items: center;
    gap: 14px;
    /* direction: ltr; */
    width: 100%;
    justify-content: left;
    height: 85%;
    flex-direction: row-reverse;
}

.plate-right-section {
    position: absolute;
    top: 21%;
    right: 6%;
}

.plate-preview-number,
.plate-preview-city,
.plate-preview-region {
    min-width: 30px;
    text-align: center;
}

.plate-preview-region {
    min-width: 40px;
}

.plate-preview-city {
    min-width: 20px;
}

/* Avatar Styles */
.avatar-primary {
    background-color: #206bc4 !important;
    color: white !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Icon Sizes */
.icon-32 {
    font-size: 32px;
}

.icon-48 {
    font-size: 48px;
}

.icon-64 {
    font-size: 64px;
}

/* Text Utilities */
.text-pre-line {
    white-space: pre-line;
}

/* Button Disabled State */
.btn-disabled-custom {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Signature Container */
.signature-container {
    border: 2px solid #ddd;
    border-radius: 4px;
    background: white;
}

.signature-canvas {
    width: 100%;
    height: 200px;
    cursor: crosshair;
}

/* Damage Map Styles */
.damage-map-container {
    position: relative;
    width: 100%;
    border: 2px solid #ddd;
    background: #ffffff;
    border-radius: 4px;
    overflow: hidden;
}

.damage-map-container.editable {
    cursor: crosshair;
}

.damage-map-container.readonly {
    cursor: default;
}

#damageMapImage {
    width: 100%;
    height: auto;
    display: block;
    position: relative;
}

#damageMapSvg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

.damage-point {
    pointer-events: all;
    cursor: pointer;
}

.damage-point circle {
    cursor: pointer;
    opacity: 0.9;
    transition: opacity 0.2s, stroke-width 0.2s;
}

.damage-point circle:hover {
    opacity: 1;
    stroke-width: 3;
}

.damage-point text {
    cursor: pointer;
    pointer-events: none;
    user-select: none;
}

/* Signature Images */
.signature-image {
    max-width: 100%;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Display Utilities (for JavaScript toggling) */
.display-none {
    display: none !important;
}

.display-inline {
    display: inline !important;
}

/* Quick Search Results */
.quick-search-results {
    display: none;
    max-height: 400px;
    overflow-y: auto;
    top: 100%;
    margin-top: 4px;
    z-index: 1000;
}

.quick-search-results-mobile {
    position: absolute;
}

.quick-search-results-desktop {
    position: absolute;
    left: 0;
    right: 0;
}

/* User Info Styles */
.user-info-line {
    line-height: 1.2;
    font-size: 0.875rem;
}

.user-info-line-small {
    line-height: 1.2;
    margin-top: 0.125rem;
}

/* Code Block Styles */
.code-block-scrollable {
    max-height: 300px;
    overflow-y: auto;
}

/* Admin Styles */
.admin-setup-link {
    background-color: #28a745;
    color: white;
    padding: 8px 15px;
    border-radius: 4px;
}

.admin-list-unstyled {
    list-style: none;
    padding: 0;
}

/* License Manager Styles */
.license-check-section {
    margin-top: 30px;
}

.license-check-btn {
    padding: 12px 30px;
    font-size: 16px;
}

.license-status {
    margin-top: 15px;
}

/* Select2 RTL Support */
.select2-container {
    direction: rtl;
    text-align: right;
}

.select2-container--bootstrap-5 .select2-selection {
    border: 1px solid var(--tblr-border-color) !important;
    border-radius: var(--tblr-border-radius);
    min-height: 38px;
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    border-color: var(--tblr-primary) !important;
    box-shadow: none !important;
}

.select2-container--bootstrap-5 .select2-selection--single {
    padding: 0;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    padding-right: 12px;
    padding-left: 20px;
    line-height: 38px;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow {
    left: 8px;
    right: auto;
    width: 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Fix Select2 clear button position - prevent overlap with arrow */
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear {
    right: 30px;
    left: auto;
    width: 20px;
    height: 20px;
    margin-top: -10px;
    top: 50%;
    position: absolute;
    cursor: pointer;
    font-weight: bold;
    opacity: 0.5;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear:hover {
    opacity: 1;
}

/* Ensure arrow and clear button don't overlap */
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    padding-right: 12px;
    padding-left: 50px; /* Space for both clear and arrow */
}

.select2-container--bootstrap-5 .select2-dropdown {
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
    padding: 8px 12px;
    direction: rtl;
    text-align: right;
}

.select2-container--bootstrap-5 .select2-results__option {
    padding: 8px 12px;
    direction: rtl;
    text-align: right;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: var(--tblr-primary);
    color: white;
}

/* Fix Select2 in modals */
.modal .select2-container {
    z-index: 9999;
}

/* Fix Select2 in input-icon */
.input-icon .select2-container {
    width: 100% !important;
}

.input-icon .select2-selection {
    border: 1px solid var(--tblr-border-color) !important;
    background: transparent;
}

.input-icon .select2-selection__rendered {
    padding-right: 0;
}

/* Remove outline and use border color change for focus - Global for all fields */
/* All form inputs and selects */
.form-control:focus,
.form-select:focus,
input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="datetime-local"]:focus,
textarea:focus,
select:focus {
    outline: none !important;
    border-color: var(--tblr-primary) !important;
    box-shadow: none !important;
}

/* Select2 - remove outline and use border color */
.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    outline: none !important;
    border-color: var(--tblr-primary) !important;
    box-shadow: none !important;
}

/* Select2 search field */
.select2-search__field:focus {
    outline: none !important;
    border-color: var(--tblr-primary) !important;
    box-shadow: none !important;
}

/* Badge styles for equipment and component status */
[class*="equipment-hint-"],
[class*="component-hint-"],
.equipment-hint,
.component-hint {
    flex-grow: 1;
    text-align: left;
}

/* Form check label styles */
.form-check-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Fixed Sidebar Header and Footer */
.navbar-vertical {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.navbar-vertical .container-fluid {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.navbar-vertical .navbar-brand {
    flex-shrink: 0;
}

.navbar-vertical .theme-toggle-wrapper {
    flex-shrink: 0;
}

.navbar-vertical #sidebar-menu {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.navbar-vertical .navbar-nav.mt-auto {
    flex-shrink: 0;
    margin-top: auto !important;
    position: sticky;
    bottom: 0;
    background-color: var(--tblr-bg-surface);
    z-index: 10;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Steps Progress Indicator Styles */
.steps .step-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 2rem;
    position: relative;
    text-decoration: none;
    color: inherit;
}

.steps-counter .step-item {
    padding-top: 2.5rem;
}

.steps .step-item .step-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    display: block;
}

.steps .step-item .step-subtitle {
    font-size: 0.75rem;
    color: var(--tblr-secondary);
    margin-top: 0.25rem;
    display: block;
}

.steps .step-item.active .step-title {
    color: var(--tblr-primary);
    font-weight: 700;
}

.steps .step-item.active .step-subtitle {
    color: var(--tblr-primary);
}

/* Steps before active are automatically styled by Tabler */
.steps .step-item:not(.active) .step-title,
.steps .step-item:not(.active) .step-subtitle {
    color: var(--tblr-secondary);
}

/* Dark mode support for steps */
[data-bs-theme="dark"] .steps .step-item .step-subtitle {
    color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .steps .step-item.active .step-subtitle {
    color: var(--tblr-primary);
}

.btn-group-lg>.btn, .btn-lg {
    --tblr-btn-border-radius: var(--tblr-border-radius);
}

.footer {
    --tblr-footer-bg: var(--tblr-bg-surface);
    background-color: var(--tblr-footer-bg);
}

.select2, .selection, .select2-selection {
    background-color: var(--tblr-bg-forms) !important;
}

.select2-dropdown {
    --tblr-select-bg: var(--tblr-bg-surface);
    background-color: var(--tblr-select-bg) !important;
}