/* ==========================================================================
   MODERN BRANCH TRACKER — LIGHT THEME
   Optimized, Cleaned, and Engineered CSS
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. FONTS & RESET
   -------------------------------------------------------------------------- */
@font-face {
    font-family: 'YekanBakh';
    src: url('/fonts/YekanBakh-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

*, *::before, *::after { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
}

/* --------------------------------------------------------------------------
   2. CSS VARIABLES (DESIGN TOKENS)
   -------------------------------------------------------------------------- */
:root {
    /* Colors */
    --bg:           #f8fafc;
    --bg-2:         #ffffff;
    --bg-3:         #ffffff;
    --bg-h:         #f1f5f9;
    --brd:          #e2e8f0;
    --brd-dark:     #cbd5e1;
    --txt:          #1e293b;
    --txt-2:        #475569;
    --txt-3:        #94a3b8;
    
    /* Brand & States */
    --accent:       #3b82f6;
    --accent-h:     #2563eb;
    --accent-light: #dbeafe;
    --ok:           #10b981;
    --ok-light:     #d1fae5;
    --warn:         #f59e0b;
    --warn-light:   #fef3c7;
    --err:          #ef4444;
    --err-light:    #fee2e2;
    --purple:       #8b5cf6;
    
    /* Dimensions & Layout */
    --side-w:       220px;
    --rad:          12px;
    --rad-sm:       8px;
    
    /* Shadows */
    --shadow:       0 1px 3px rgba(0,0,0,.08);
    --shadow-md:    0 4px 12px rgba(0,0,0,.1);
}

/* --------------------------------------------------------------------------
   3. GLOBAL STYLES
   -------------------------------------------------------------------------- */
body {
    font-family: 'YekanBakh', sans-serif; /* Applied YekanBakh as Primary Font */
    background: var(--bg);
    color: var(--txt);
    direction: rtl;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
   4. LAYOUT: SIDEBAR
   -------------------------------------------------------------------------- */
.sidebar {
    position: fixed;
    inset: 0 0 0 auto;
    width: var(--side-w);
    background: var(--bg-2);
    border-left: 1px solid var(--brd);
    box-shadow: -2px 0 8px rgba(0,0,0,.04);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--brd);
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { font-size: 15px; font-weight: 700; color: var(--txt); }

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--rad-sm);
    color: var(--txt-2);
    text-decoration: none;
    font-size: 13.5px;
    transition: all .15s ease-in-out;
}

.nav-item:hover { background: var(--bg-h); color: var(--txt); }
.nav-item.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--brd);
    font-size: 12px;
    color: var(--txt-3);
}

/* --------------------------------------------------------------------------
   5. LAYOUT: MAIN CONTENT & TOPBAR
   -------------------------------------------------------------------------- */
.main-content {
    margin-right: var(--side-w);
    padding: 0 24px 24px;
    min-height: 100vh;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--brd);
    margin-bottom: 20px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 50;
}

.top-bar h1 { font-size: 20px; font-weight: 700; color: var(--txt); }
.top-bar-actions { display: flex; align-items: center; gap: 12px; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-2);
    border: 1px solid var(--brd);
    border-radius: var(--rad-sm);
    padding: 7px 12px;
    box-shadow: var(--shadow);
}

.search-box input {
    background: none;
    border: none;
    color: var(--txt);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    width: 180px;
}

.search-box input::placeholder { color: var(--txt-3); }
.search-box svg { color: var(--txt-3); }

/* --------------------------------------------------------------------------
   6. COMPONENTS: BUTTONS
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--rad-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s ease-in-out;
    box-shadow: var(--shadow);
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); box-shadow: var(--shadow-md); }

.btn-secondary { background: var(--bg-2); color: var(--txt); border: 1px solid var(--brd); }
.btn-secondary:hover { background: var(--bg-h); border-color: var(--brd-dark); }

.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Fixed Syntax Error in btn-icon */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: var(--txt-3);
    transition: all .15s ease-in-out;
}

.btn-icon:hover { color: var(--txt-2); background: var(--bg-h); }
.btn-icon.edit:hover { color: var(--accent); background: var(--accent-light); }
.btn-icon.delete:hover { color: var(--err); background: var(--err-light); }

.btn-close {
    background: none;
    border: none;
    color: var(--txt-3);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all .15s ease-in-out;
}
.btn-close:hover { background: var(--bg-h); color: var(--txt); }

/* --------------------------------------------------------------------------
   7. COMPONENTS: DASHBOARD CARDS (KPIs, Activity, Perf)
   -------------------------------------------------------------------------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.kpi-card {
    background: var(--bg-2);
    border: 1px solid var(--brd);
    border-radius: var(--rad);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--shadow);
    transition: box-shadow .15s;
}

.kpi-card:hover { box-shadow: var(--shadow-md); }
.kpi-label { font-size: 12px; color: var(--txt-3); font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 800; color: var(--txt); }
.kpi-sub { font-size: 11px; color: var(--txt-2); }

.card {
    background: var(--bg-2);
    border: 1px solid var(--brd);
    border-radius: var(--rad);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.card-header { 
    padding: 14px 18px; 
    border-bottom: 1px solid var(--brd); 
    background: var(--bg-h);
}
.card-header h3 { font-size: 14px; font-weight: 600; color: var(--txt); }

/* --------------------------------------------------------------------------
   8. COMPONENTS: KANBAN PIPELINE
   -------------------------------------------------------------------------- */
.pipeline-bar-container {
    display: flex;
    height: 40px;
    border-radius: var(--rad-sm);
    overflow: hidden;
    margin: 16px 0;
    box-shadow: var(--shadow);
}

.pipeline-bar-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    transition: flex .3s ease;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    padding: 0 6px;
}

.pipeline-board {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 16px;
    min-height: calc(100vh - 120px);
}

.pipeline-column {
    min-width: 220px;
    max-width: 260px;
    flex-shrink: 0;
    background: var(--bg-2);
    border: 1px solid var(--brd);
    border-radius: var(--rad);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.pipeline-column-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--brd);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    background: var(--bg-h);
    border-radius: var(--rad) var(--rad) 0 0;
}

.pipeline-column-header .col-count {
    background: var(--bg-2);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    color: var(--txt-2);
    border: 1px solid var(--brd);
}

.pipeline-column-body {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    background: var(--bg-h);
    border-radius: 0 0 var(--rad) var(--rad);
}

.pipeline-card {
    background: var(--bg-2);
    border: 1px solid var(--brd);
    border-radius: var(--rad-sm);
    padding: 12px;
    cursor: pointer;
    transition: all .15s;
    box-shadow: var(--shadow);
}

.pipeline-card:hover { 
    border-color: var(--accent); 
    transform: translateY(-2px); 
    box-shadow: var(--shadow-md);
}

.pipeline-card .pc-name { font-size: 13px; font-weight: 600; color: var(--txt); margin-bottom: 4px; }
.pipeline-card .pc-code { font-size: 11px; color: var(--txt-3); }
.pipeline-card .pc-city { font-size: 11px; color: var(--txt-2); margin-top: 4px; }
.pipeline-card .pc-days { font-size: 10px; color: var(--warn); margin-top: 6px; font-weight: 500; }

/* --------------------------------------------------------------------------
   9. COMPONENTS: TABLES & BADGES
   -------------------------------------------------------------------------- */
.status-filter-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }

.status-filter-tab {
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--brd);
    background: var(--bg-2);
    color: var(--txt-2);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: all .15s;
}

.status-filter-tab:hover { border-color: var(--accent); color: var(--accent); }
.status-filter-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--brd);
    border-radius: var(--rad);
    background: var(--bg-2);
    box-shadow: var(--shadow);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.data-table th {
    background: var(--bg-h);
    padding: 10px 12px;
    text-align: right;
    font-weight: 600;
    font-size: 12px;
    color: var(--txt-2);
    white-space: nowrap;
    border-bottom: 1px solid var(--brd);
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--brd);
    vertical-align: middle;
    color: var(--txt);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-h); }

.th-center, .td-center { text-align: center !important; }
.row-actions { display: flex; gap: 2px; }

/* Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; }

.days-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.days-ok { background: var(--ok-light); color: #059669; }
.days-warn { background: var(--warn-light); color: #d97706; }
.days-danger { background: var(--err-light); color: #dc2626; }

/* --------------------------------------------------------------------------
   10. MODALS & FORMS
   -------------------------------------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(2px);
    z-index: 1000;
    align-items: flex-start;
    justify-content: center;
    padding: 30px;
    overflow-y: auto;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-2);
    border: 1px solid var(--brd);
    border-radius: 16px;
    width: 100%;
    max-width: 680px;
    direction: rtl;
    box-shadow: 0 20px 50px rgba(0,0,0,.15);
}

.modal-sm { max-width: 420px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--brd);
    background: var(--bg-h);
    border-radius: 16px 16px 0 0;
}
.modal-header h2 { font-size: 16px; color: var(--txt); }
.modal-body { padding: 16px 20px; max-height: 70vh; overflow-y: auto; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--brd);
    background: var(--bg-h);
    border-radius: 0 0 16px 16px;
}

/* Form Elements */
.form-section { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--brd); }
.form-section:last-child { border-bottom: none; }
.form-section h4 { font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 12px; }

.form-row { display: flex; gap: 12px; margin-bottom: 10px; }
.form-group { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.form-group.full-width { flex-basis: 100%; }
.form-group label { font-size: 12px; color: var(--txt-2); font-weight: 500; }

.form-group input,
.form-group select,
.form-group textarea {
    background: var(--bg);
    border: 1px solid var(--brd);
    border-radius: var(--rad-sm);
    padding: 8px 12px;
    color: var(--txt);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: all .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { 
    border-color: var(--accent); 
    box-shadow: 0 0 0 3px var(--accent-light);
}
.form-group textarea { resize: vertical; }

.fetch-status { font-size: 12px; margin-top: 6px; }
.fetch-status.loading { color: var(--warn); }
.fetch-status.success { color: var(--ok); }
.fetch-status.error { color: var(--err); }

/* Map Lock Overlay */
.map-lock-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999; /* <--- این عدد تغییر کرد تا حتما روی نقشه قرار بگیرد */
    transition: opacity 0.3s ease;
}

.map-lock-overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}


/* --------------------------------------------------------------------------
   11. WIDGETS: ACTIVITY, ALERTS, ISSUES & TIMELINE
   -------------------------------------------------------------------------- */
/* Activity */
.activity-list { max-height: 300px; overflow-y: auto; }
.activity-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--brd); font-size: 13px; }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.activity-text { flex: 1; color: var(--txt-2); }
.activity-text strong { color: var(--txt); }
.activity-time { font-size: 11px; color: var(--txt-3); white-space: nowrap; }

/* Alerts */
.alerts-list { padding: 0; }
.alert-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--brd); font-size: 13px; }
.alert-item:last-child { border-bottom: none; }
.alert-item.warn { border-right: 3px solid var(--warn); background: var(--warn-light); }
.alert-item.danger { border-right: 3px solid var(--err); background: var(--err-light); }
.alert-item svg { flex-shrink: 0; }

/* Performance */
.perf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.perf-card { background: var(--bg-2); border: 1px solid var(--brd); border-radius: var(--rad); padding: 20px; box-shadow: var(--shadow); }
.perf-card h4 { font-size: 14px; margin-bottom: 14px; color: var(--txt); }
.perf-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.perf-bar-label { font-size: 12px; color: var(--txt-2); width: 120px; text-align: left; flex-shrink: 0; }
.perf-bar-track { flex: 1; height: 10px; background: var(--brd); border-radius: 5px; overflow: hidden; }
.perf-bar-fill { height: 100%; border-radius: 5px; transition: width .5s; }
.perf-bar-value { font-size: 12px; color: var(--txt-3); width: 50px; flex-shrink: 0; }

/* Issues */
.issues-header { margin-bottom: 16px; }
.issues-list { display: flex; flex-direction: column; gap: 8px; }
.issue-item { background: var(--bg-2); border: 1px solid var(--brd); border-radius: 10px; padding: 14px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.issue-priority { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.issue-priority.low { background: var(--ok); }
.issue-priority.medium { background: var(--warn); }
.issue-priority.high { background: #f97316; }
.issue-priority.critical { background: var(--err); }
.issue-info { flex: 1; }
.issue-title { font-size: 13px; font-weight: 600; color: var(--txt); }
.issue-meta { font-size: 11px; color: var(--txt-3); margin-top: 3px; }
.issue-status-badge { padding: 3px 10px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.issue-status-badge.open { background: var(--err-light); color: var(--err); }
.issue-status-badge.resolved { background: var(--ok-light); color: var(--ok); }

/* Timeline (History Modal) */
.timeline { position: relative; padding-right: 20px; }
.timeline::before { content: ''; position: absolute; right: 6px; top: 0; bottom: 0; width: 2px; background: var(--brd); }
.timeline-item { position: relative; padding: 8px 0 16px 0; padding-right: 24px; }
.timeline-item::before { content: ''; position: absolute; right: -17px; top: 12px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); background: var(--bg-2); }
.timeline-item .tl-time { font-size: 11px; color: var(--txt-3); }
.timeline-item .tl-text { font-size: 13px; color: var(--txt-2); margin-top: 2px; }
.timeline-item .tl-note { font-size: 11px; color: var(--txt-3); font-style: italic; margin-top: 2px; }

/* --------------------------------------------------------------------------
   12. NOTIFICATIONS & EXPORT
   -------------------------------------------------------------------------- */
/* Toast */
.toast-container { position: fixed; bottom: 20px; left: 20px; z-index: 9999; display: flex; flex-direction: column-reverse; gap: 8px; }
.toast { padding: 10px 18px; border-radius: 10px; font-size: 13px; font-family: inherit; color: #fff; box-shadow: var(--shadow-md); direction: rtl; }
.toast.success { background: var(--ok); }
.toast.error { background: var(--err); }
.toast.info { background: var(--accent); }
.toast.warning { background: var(--warn); color: #000; }

/* Export */
.export-card { background: var(--bg-2); border: 1px solid var(--brd); border-radius: var(--rad); padding: 24px; max-width: 600px; box-shadow: var(--shadow); }
.export-card h3 { margin-bottom: 8px; color: var(--txt); }
.export-card code { background: var(--bg-h); padding: 2px 6px; border-radius: 4px; font-size: 12px; color: var(--accent); }
.csv-preview { background: var(--bg); border: 1px solid var(--brd); border-radius: var(--rad-sm); padding: 14px; font-family: monospace; font-size: 11px; direction: ltr; text-align: left; overflow: auto; white-space: pre; color: var(--txt-2); max-height: 200px; }

/* --------------------------------------------------------------------------
   13. UTILITIES & ANIMATIONS
   -------------------------------------------------------------------------- */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 60px 20px; color: var(--txt-3); }
.view-section { display: none; }
.view-section.active { display: block; }

/* Scrollbar Styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--brd-dark); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--txt-3); }

/* Keyframes */
@keyframes ping {
    75%, 100% { transform: scale(2.5); opacity: 0; }
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}

/* --------------------------------------------------------------------------
   14. RESPONSIVE DESIGN (MOBILE)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar .logo-text, .sidebar .nav-item span, .sidebar-footer { display: none; }
    .nav-item { justify-content: center; padding: 10px; }
    .main-content { margin-right: 60px; padding: 0 12px 12px; }
    .top-bar { flex-wrap: wrap; gap: 10px; }
    .form-row { flex-direction: column; }
    .pipeline-board { flex-direction: column; }
    .pipeline-column { max-width: 100%; min-width: 100%; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
