/* style.css */

/* --- Base & Variables --- */
@font-face {
    font-family: 'YekanBakh';
    src: url('fonts/YekanBakh-Regular.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

:root {
    /* --- Main Theme Colors --- */
    --app-primary: #2E7D32;
    --app-secondary: #1565C0;
    --app-accent: #FF9800;
    --app-danger: #d32f2f;
    --app-purple: #512DA8;

    /* --- Background & Surface --- */
    --app-bg: #f5f5f5;
    --app-bg-light: #f5f7fa;
    --app-surface: #ffffff;

    /* --- Text & Borders --- */
    --app-text: #333;
    --app-text-muted: #666;
    --app-border: #e0e0e0;
    
    /* --- Shadows --- */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
}

/* --- Reset & Global --- */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

*:focus:not(:focus-visible) { outline: none; }
*:focus-visible { outline: 2px solid var(--app-secondary); outline-offset: 2px; }

/* Custom Scrollbar for better UI */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #bbb; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #888; }

body {
    margin: 0;
    padding: 0;
    font-family: 'YekanBakh', system-ui, sans-serif;
    color: var(--app-text);
    height: 100vh;
    overflow: hidden;
    background: var(--app-bg);
}

input, select, button, textarea {
    font-family: inherit;
}

.container { display: flex; height: 100%; position: relative; }

/* --- Loading Overlay --- */
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.95); backdrop-filter: blur(4px); z-index: 9999; display: flex; justify-content: center; align-items: center; }
.loading-box { width: 320px; text-align: center; }
.loading-spinner { width: 40px; height: 40px; border: 4px solid #eee; border-top-color: var(--app-primary); border-radius: 50%; margin: 0 auto 15px; animation: spin 0.8s infinite linear; }
.loading-text { font-size: 0.95rem; color: var(--app-text-muted); margin-bottom: 10px; font-weight: bold; }
.progress-track { height: 6px; background: var(--app-border); border-radius: 3px; overflow: hidden; margin-bottom: 5px; }
.progress-fill { height: 100%; background: var(--app-primary); width: 0%; transition: width 0.3s ease; }
.progress-percent { font-weight: bold; color: var(--app-primary); font-size: 0.9rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Sidebar Header & User Info --- */
.sidebar { width: 340px; background: var(--app-surface); border-left: 1px solid var(--app-border); display: flex; flex-direction: column; z-index: 2000; transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: var(--shadow-sm); }
.sidebar-header { padding: 15px; border-bottom: 3px solid var(--app-primary); display: flex; justify-content: space-between; align-items: center; }
.sidebar-header h2 { margin: 0; font-size: 1.2rem; color: var(--app-primary); }
.close-sidebar-btn { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--app-text-muted); }

.user-info-bar { display: flex; align-items: center; justify-content: space-between; background: var(--app-bg-light); border-bottom: 1px solid var(--app-border); padding: 12px 16px; }
.user-info-content { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-icon { font-size: 18px; }
.user-display-name { font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role-badge { font-size: 10px; font-weight: bold; padding: 4px 8px; border-radius: 12px; }
.user-role-badge.admin-badge { background: #dbeafe; color: #1d4ed8; }
.user-role-badge.area-sup { background: #dcfce7; color: #15803d; }
.user-role-badge.regional-mgr { background: #fef3c7; color: #b45309; }
.logout-link { text-decoration: none; font-size: 13px; font-weight: bold; color: var(--app-danger); opacity: 0.8; transition: 0.2s; }
.logout-link:hover { opacity: 1; text-decoration: underline; }

/* --- Sidebar Content & Filters --- */
.sidebar-content { flex: 1; overflow-y: auto; padding: 15px; }
.filter-section, .dropdown-section, .radius-control, .control-group { background: #fafafa; padding: 12px; border-radius: 8px; border: 1px solid #eee; margin-bottom: 12px; }
h3, h4 { margin: 0 0 10px; font-size: 0.95rem; color: var(--app-text); font-weight: bold; }

/* Brands */
.brand-list { display: grid; gap: 8px; }
.brand-checkbox { background: var(--app-surface); padding: 6px 10px; border-radius: 6px; border: 1px solid var(--app-border); transition: 0.2s; display: inline-flex; }
.brand-checkbox:hover { border-color: #ccc; }
.brand-checkbox label { display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; font-size: 0.9rem; margin-right: 8px; flex: 1; }
.brand-checkbox label img { width: 24px; height: 24px; object-fit: contain; }

/* Dropdowns */
.custom-select { position: relative; }
.select-search { width: 100%; padding: 10px; border: 1px solid var(--app-border); border-radius: 6px; transition: 0.2s; }
.select-search:focus { border-color: var(--app-primary); box-shadow: 0 0 0 2px rgba(46,125,50,0.1); }
.select-dropdown { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--app-surface); border: 1px solid #ccc; border-radius: 6px; z-index: 3000; max-height: 200px; overflow-y: auto; display: none; box-shadow: var(--shadow-md); }
.select-option { padding: 10px; cursor: pointer; border-bottom: 1px solid #f5f5f5; font-size: 0.9rem; }
.select-option:hover { background: #e3f2fd; color: var(--app-secondary); }

/* Toggles */
.toggle-switch { display: flex; background: var(--app-border); padding: 3px; border-radius: 6px; }
.toggle-switch input { display: none; }
.toggle-switch label { flex: 1; text-align: center; padding: 8px 4px; font-size: 0.85rem; cursor: pointer; border-radius: 4px; transition: 0.2s; color: var(--app-text-muted); }
.toggle-switch input:checked + label { background: var(--app-surface); color: var(--app-text); font-weight: bold; box-shadow: var(--shadow-sm); }

/* Radius Slider */
.radius-slider-container { text-align: center; }
.radius-slider { width: 100%; cursor: pointer; accent-color: var(--app-secondary); margin-top: 5px; }
#radius-value { color: var(--app-secondary); font-weight: bold; font-size: 0.9rem; }

/* Action Buttons */
.controls { display: grid; gap: 10px; margin-top: 15px; }
.control-btn { padding: 12px; border: none; border-radius: 6px; color: var(--app-surface); cursor: pointer; font-weight: bold; transition: 0.2s; font-size: 0.95rem; }
.control-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.control-btn:active { transform: translateY(0); }
.control-btn.success { background: var(--app-primary); }
.control-btn.warning { background: var(--app-accent); }
.control-btn.reset { background: var(--app-danger); }
.control-btn.primary { background: var(--app-purple); }

/* --- Opportunity Analysis UI --- */
#opp-grid-size { width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ccc; margin-bottom: 10px; }
.filter-buttons { display: flex; gap: 5px; margin-top: 5px; }
.filter-chip { flex: 1; padding: 6px; font-size: 11px; background: var(--app-surface); border: 1px solid #ccc; border-radius: 12px; cursor: pointer; transition: 0.2s; font-weight: bold; }
.filter-chip:hover { background: var(--app-bg-light); }
.filter-chip.active { background: #333; color: #fff !important; border-color: #333 !important; }

/* --- Main Map Area --- */
#map-container { flex: 1; position: relative; display: flex; flex-direction: column; }
#map { flex: 1; width: 100%; }

/* --- Floating Store Search --- */
#store-search-wrapper { position: absolute; top: 15px; right: 15px; z-index: 1000; width: 320px; }
.search-input-group { display: flex; background: var(--app-surface); border-radius: 8px; box-shadow: var(--shadow-md); overflow: hidden; border: 2px solid transparent; transition: 0.3s; }
.search-input-group:focus-within { border-color: var(--app-primary); }
#store-code-input { flex: 1; border: none; padding: 12px 15px; font-size: 0.95rem; outline: none; background: transparent; }
#store-search-btn { background: #f8f9fa; border: none; border-right: 1px solid var(--app-border); padding: 0 15px; cursor: pointer; font-weight: bold; transition: 0.2s; }
#store-search-btn:hover { background: #e9ecef; color: var(--app-primary); }
#search-results-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--app-surface); margin-top: 5px; border-radius: 8px; box-shadow: var(--shadow-md); list-style: none; padding: 0; max-height: 250px; overflow-y: auto; display: none; }
#search-results-dropdown li { padding: 10px 15px; border-bottom: 1px solid #f0f0f0; cursor: pointer; font-size: 0.85rem; display: flex; align-items: center; transition: 0.2s; }
#search-results-dropdown li:hover { background: #f0f7f0; }
.sr-code { font-weight: bold; color: var(--app-primary); margin-left: 10px; background: #e8f5e9; padding: 3px 6px; border-radius: 4px; font-size: 0.75rem; }

/* --- Info Panel (Bottom Left) --- */
.info-panel { position: absolute; bottom: 20px; left: 20px; width: 360px; z-index: 1000; display: flex; flex-direction: column; gap: 12px; pointer-events: none; }
.info-panel > * { pointer-events: auto; background: rgba(255,255,255,0.96); border-radius: 10px; box-shadow: var(--shadow-md); backdrop-filter: blur(8px); }

.visible-stats { padding: 15px; max-height: 35vh; overflow-y: auto; border: 1px solid var(--app-border); }
.visible-stats h4 { margin: 0 0 12px; font-size: 0.9rem; border-bottom: 1px solid #eee; padding-bottom: 8px; color: var(--app-text-muted); }
.stat-row { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 6px; }
.stat-name { display: flex; align-items: center; gap: 6px; }
.stat-total { text-align: center; font-weight: bold; border-top: 1px dashed #ccc; padding-top: 10px; margin-top: 10px; font-size: 0.95rem; color: var(--app-primary); }

/* --- Details Card (RENT FIXED) --- */
#daily-details-box { display: none; border-top: 4px solid var(--app-primary); overflow: hidden; }
.dd-header { background: var(--app-primary); color: var(--app-surface); padding: 12px 15px; display: flex; justify-content: space-between; align-items: center; }
.dd-title { margin: 0; font-size: 1.05rem; }
.dd-badge { background: rgba(255,255,255,0.25); padding: 3px 8px; border-radius: 4px; font-size: 0.85rem; font-family: monospace; margin-left: 35px;}

.dd-body { padding: 15px; }
.dd-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 15px; }
.dd-meta-item { background: var(--app-bg-light); padding: 10px; border-radius: 6px; display: flex; flex-direction: column; font-size: 0.8rem; border: 1px solid #eee; text-align: center; }
.dd-meta-val { font-weight: bold; color: var(--app-text); margin-top: 4px; font-size: 0.9rem; }

.details-table { width: 100%; font-size: 0.85rem; border-collapse: collapse; margin-bottom: 15px; }
.details-table th { background: #E8F5E9; padding: 8px; text-align: center; color: var(--app-primary); border-radius: 4px 4px 0 0; }
.details-table td { border-bottom: 1px solid #eee; padding: 8px; text-align: center; }
.row-head { text-align: right; background: #fafafa; font-weight: bold; color: var(--app-text-muted); }
.text-online { color: var(--app-secondary); }
.fw-bold { font-weight: bold; }

/* Rent Section */
.rent-container { background: #FFF8E1; border: 1px solid #FFE0B2; border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.rent-header { color: #F57C00; font-size: 0.85rem; font-weight: bold; border-bottom: 1px dashed #FFCC80; padding-bottom: 6px; text-align: right; }
.rent-main { text-align: center; color: #D84315; }
.rent-amount { font-size: 1.3rem; font-weight: 900; }
.rent-unit { font-size: 0.8rem; color: #8D6E63; margin-right: 4px; }
.rent-details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rent-box { background: rgba(255,255,255,0.8); padding: 8px; border-radius: 6px; text-align: center; border: 1px solid #FFE0B2; }
.rent-val { display: block; font-weight: bold; color: #BF360C; font-size: 1rem; }
.rent-lbl { font-size: 0.75rem; color: #795548; margin-top: 2px; }

/* --- Map Markers, Clusters & Tooltips --- */
.daily-tooltip-container { background: transparent; border: none; box-shadow: none; }
.dt-tooltip { font-family: 'YekanBakh', sans-serif; background: var(--app-surface); border: 1px solid var(--app-primary); padding: 6px; border-radius: 6px; text-align: center; min-width: 90px; box-shadow: var(--shadow-sm); }
.dt-row { display: block; font-size: 11px; font-weight: bold; }
.dt-row.sales { color: var(--app-danger); border-bottom: 1px dashed #eee; padding-bottom: 4px; margin-bottom: 4px; }
.dt-row.trans { color: var(--app-secondary); }

.marker-cluster div { width: 30px; height: 30px; margin-left: 5px; margin-top: 5px; text-align: center; border-radius: 50%; color: #fff; line-height: 30px; font-family: Arial, sans-serif; font-weight: bold; font-size: 13px; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.marker-cluster-canbo { background: rgba(0,0,0,0.3); } .marker-cluster-canbo div { background: rgba(0,0,0,0.9); }
.marker-cluster-okcs { background: rgba(198,40,40,0.3); } .marker-cluster-okcs div { background: rgba(198,40,40,0.9); }
.marker-cluster-seven { background: rgba(13,71,161,0.3); } .marker-cluster-seven div { background: rgba(13,71,161,0.9); }
.marker-cluster-dailymarket { background: rgba(46,125,50,0.3); } .marker-cluster-dailymarket div { background: rgba(46,125,50,0.9); }
.marker-cluster-minoo { background: rgba(229,57,53,0.3); } .marker-cluster-minoo div { background: rgba(229,57,53,0.9); }
.marker-cluster-amiran { background: rgba(183,216,43,0.4); } .marker-cluster-amiran div { background: rgba(183,216,43,0.9); color: #333; }
.marker-cluster-beheshti { background: rgba(255,89,0,0.3); } .marker-cluster-beheshti div { background: rgba(255,89,0,0.9); }
.marker-cluster-gandoom { background: rgba(112,36,123,0.3); } .marker-cluster-gandoom div { background: rgba(112,36,123,0.9); }

/* Neshan/Leaflet Overrides */
.leaflet-tooltip-top:before { margin-bottom: -4px !important; }
.popup-content { font-family: 'YekanBakh', sans-serif !important; text-align: right !important; direction: rtl; }
.leaflet-container a { color: var(--app-secondary) !important; }
a.leaflet-popup-close-button { background: #ff7676 !important; border-radius: 0 7px 0 7px; color: white !important; padding: 4px; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }

/* Popup Content styling */
.popup-row { border-bottom: 1px dashed #e9e9e9; padding: 6px 0; font-size: 0.85rem; }
.popup-row:last-of-type { border-bottom: none; }
.popup-nav-btn { margin-top: 12px; }
.neshan-nav-link { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; background-color: #42B983; color: #fff !important; border-radius: 8px; text-decoration: none; font-size: 0.9rem; font-weight: bold; transition: 0.2s; direction: ltr; }
.neshan-nav-link:hover { background-color: #369b6f; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(66, 185, 131, 0.3); }

/* --- Mobile Styling --- */
.mobile-menu-btn { display: none; position: absolute; top: 15px; left: 15px; z-index: 1100; background: var(--app-surface); border: none; padding: 10px 15px; border-radius: 20px; box-shadow: var(--shadow-md); align-items: center; gap: 8px; cursor: pointer; color: var(--app-text); font-weight: bold; }

@media (max-width: 768px) {
    .mobile-menu-btn { display: flex; }
    
    .sidebar { position: fixed; inset: 0; width: 100%; transform: translateX(100%); z-index: 3000; }
    .sidebar.open { transform: translateX(0); }
    .close-sidebar-btn { display: block; }
    
    /* Fixed Mobile Search Bar Positioning */
    #store-search-wrapper {
        top: 15px;
        right: 15px;
        left: 15px;
        width: auto;
        max-width: none;
        padding-left: 110px; /* Space for the mobile menu button */
    }
    
    .info-panel { left: 0; right: 0; bottom: 0; width: 100%; gap: 0; padding: 0; }
    .info-panel > * { border-radius: 16px 16px 0 0; border: none; border-top: 1px solid var(--app-border); }
    .visible-stats { max-height: 30vh; }
    .details-card { max-height: 60vh; overflow-y: auto; }
}


/* --- Opportunity Action Button Styles --- */
#btn-run-opportunity {
    width: 100%; /* دکمه تمام عرض باکس را پر می‌کند */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: bold;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 15px;
    font-family: inherit;
}

#btn-run-opportunity.state-idle {
    background-color: var(--app-purple);
    color: var(--app-surface);
    box-shadow: 0 4px 10px rgba(81, 45, 168, 0.2);
}
#btn-run-opportunity.state-idle:hover {
    background-color: #4527a0;
    transform: translateY(-1px);
}

#btn-run-opportunity.state-loading {
    background-color: #e0e0e0;
    color: #757575;
    cursor: not-allowed;
    pointer-events: none; 
    box-shadow: none;
}

#btn-run-opportunity.state-active {
    background-color: var(--app-surface);
    color: var(--app-danger);
    border: 1px solid var(--app-danger);
}
#btn-run-opportunity.state-active:hover {
    background-color: #ffebee;
}


/* --- Sales Range Slider --- */
.sales-range-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.range-values {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--app-secondary);
}
.multi-range-slider {
    position: relative;
    width: 100%;
    height: 30px;
}
.multi-range-slider input[type="range"] {
    position: absolute;
    width: 100%;
    pointer-events: none;
    appearance: none;
    background: transparent;
    z-index: 2;
}
/* Track styling (optional visual line) */
.multi-range-slider::before {
    content: "";
    position: absolute;
    width: 100%;
    height: 4px;
    background: var(--app-border);
    top: 42%;
    transform: translateY(-50%);
    border-radius: 2px;
    z-index: 1;
}
.multi-range-slider input[type="range"]::-webkit-slider-thumb {
    pointer-events: all;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--app-primary);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
