:root{--primary:#7c3aed;--secondary:#14b8a6;--bg:#f5f3ff;--card:#fff;--text:#1f2937;--muted:#6b7280;--radius:22px}
*{font-family:Vazirmatn,Tahoma,sans-serif}
body{background:linear-gradient(135deg,#faf7ff,#effaf9);color:var(--text)}

/* ===== DARK MODE ===== */
[data-bs-theme="dark"] body,
html[data-bs-theme="dark"] body{
    background:#0f172a !important;color:#e5e7eb !important;
}
html[data-bs-theme="dark"] .sidebar,
html[data-bs-theme="dark"] .topbar,
html[data-bs-theme="dark"] .card,
html[data-bs-theme="dark"] .stat,
html[data-bs-theme="dark"] .auth-card{
    background:rgba(15,23,42,.92) !important;
    border-color:rgba(255,255,255,.08) !important;
}
html[data-bs-theme="dark"] .nav-link{color:#d1d5db}
html[data-bs-theme="dark"] .nav-link:hover,
html[data-bs-theme="dark"] .nav-link.active{
    background:linear-gradient(135deg,rgba(124,58,237,.22),rgba(20,184,166,.22));
    color:#a78bfa;
}
html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select{
    background:#1e293b !important;color:#e5e7eb !important;border-color:#374151 !important;
}
html[data-bs-theme="dark"] .form-control:focus,
html[data-bs-theme="dark"] .form-select:focus{
    border-color:var(--primary) !important;
    box-shadow:0 0 0 .2rem rgba(124,58,237,.25);
}
html[data-bs-theme="dark"] .table{color:#e5e7eb}
html[data-bs-theme="dark"] .table>thead{border-color:rgba(255,255,255,.1)}
html[data-bs-theme="dark"] .dropdown-menu{
    background:#1e293b;border-color:#374151;
}
html[data-bs-theme="dark"] .dropdown-item{color:#d1d5db}
html[data-bs-theme="dark"] .dropdown-item:hover{background:#374151;color:#fff}
html[data-bs-theme="dark"] .dropdown-item-text{color:#9ca3af}
html[data-bs-theme="dark"] .border-bottom{border-color:rgba(255,255,255,.08) !important}
html[data-bs-theme="dark"] .text-muted{color:#9ca3af !important}
html[data-bs-theme="dark"] .meta{
    background:rgba(124,58,237,.08) !important;
    border-color:rgba(255,255,255,.08) !important;
}
html[data-bs-theme="dark"] .timeline>div{background:rgba(124,58,237,.08)}
html[data-bs-theme="dark"] .timeline{border-color:rgba(124,58,237,.3)}
html[data-bs-theme="dark"] .alert-danger{background:rgba(220,38,38,.15);border-color:rgba(220,38,38,.3);color:#fca5a5}
html[data-bs-theme="dark"] .btn-soft{
    background:rgba(124,58,237,.15);border-color:rgba(124,58,237,.2);color:#a78bfa;
}
html[data-bs-theme="dark"] .btn-outline-primary{color:#a78bfa;border-color:#a78bfa}
html[data-bs-theme="dark"] .btn-outline-primary:hover{background:#a78bfa;color:#0f172a}
html[data-bs-theme="dark"] .btn-outline-danger{color:#fca5a5;border-color:#fca5a5}
html[data-bs-theme="dark"] .btn-outline-danger:hover{background:#dc2626;color:#fff}
html[data-bs-theme="dark"] .badge{opacity:.9}

/* ===== LAYOUT ===== */
.app-shell{min-height:100vh}
.sidebar{
    position:fixed;right:0;top:0;bottom:0;width:280px;
    background:rgba(255,255,255,.88);backdrop-filter:blur(18px);
    border-left:1px solid rgba(124,58,237,.12);padding:22px;z-index:20;overflow:auto;
}
.brand{display:flex;align-items:center;gap:12px;margin-bottom:22px}
.brand-logo{
    width:48px;height:48px;border-radius:16px;
    background:linear-gradient(135deg,var(--primary),var(--secondary));
    display:grid;place-items:center;color:#fff;font-size:24px;overflow:hidden;
}
.brand-logo img{width:100%;height:100%;object-fit:cover}
.brand small{display:block;color:var(--muted)}

/* ===== NAV ===== */
.nav-link{
    display:flex;gap:10px;align-items:center;color:#374151;
    border-radius:14px;padding:11px 13px;margin:4px 0;text-decoration:none;
}
.nav-link:hover,.nav-link.active{
    background:linear-gradient(135deg,rgba(124,58,237,.12),rgba(20,184,166,.12));color:var(--primary);
}

/* ===== MAIN ===== */
.main{margin-right:280px;min-height:100vh}
.topbar{
    height:78px;display:flex;align-items:center;justify-content:space-between;
    padding:14px 26px;position:sticky;top:0;
    background:rgba(250,247,255,.85);backdrop-filter:blur(16px);
    z-index:10;border-bottom:1px solid rgba(124,58,237,.08);
}
.topbar h1{font-size:22px;margin:0;font-weight:800}
.topbar span{font-size:12px;color:var(--muted)}
.top-actions{display:flex;align-items:center;gap:10px}
.content{padding:24px}

/* ===== CARDS & STATS ===== */
.card,.stat,.auth-card{
    background:rgba(255,255,255,.88);border:1px solid rgba(124,58,237,.12);
    border-radius:var(--radius);box-shadow:0 18px 45px rgba(31,41,55,.06);
}
.stat{padding:20px;min-height:120px;display:flex;flex-direction:column;justify-content:center;gap:6px}
.stat i{font-size:25px;color:var(--primary)}
.stat span,.meta span{color:var(--muted);font-size:13px}
.stat b{font-size:22px}

/* ===== BUTTONS ===== */
.btn-primary{background:linear-gradient(135deg,var(--primary),#9f67ff);border:0;border-radius:14px}
.btn-primary:hover{filter:brightness(1.1)}
.btn-soft{
    background:rgba(124,58,237,.08);border:1px solid rgba(124,58,237,.12);
    color:var(--primary);border-radius:14px;
}
.btn-soft:hover{background:rgba(124,58,237,.15)}

/* ===== FORMS ===== */
.form-control,.form-select{
    border-radius:14px;padding:.75rem 1rem;border-color:rgba(124,58,237,.16);
}
.form-control:focus,.form-select:focus{
    border-color:var(--primary);
    box-shadow:0 0 0 .2rem rgba(124,58,237,.15);
}

/* ===== TABLE ===== */
.table{--bs-table-bg:transparent}
.empty{text-align:center;color:var(--muted);padding:30px}

/* ===== META BOX ===== */
.meta{
    border:1px solid rgba(124,58,237,.1);border-radius:16px;
    padding:14px;background:rgba(124,58,237,.03);height:100%;
}
.meta b{display:block;margin-top:5px}

/* ===== TIMELINE ===== */
.timeline{border-right:3px solid rgba(124,58,237,.2);padding-right:18px}
.timeline>div{position:relative;margin:16px 0;padding:12px 16px;background:rgba(124,58,237,.04);border-radius:16px}
.timeline>div:before{content:"";position:absolute;right:-26px;top:18px;width:13px;height:13px;background:var(--primary);border-radius:50%}
.timeline time{display:block;color:var(--muted);font-size:12px;text-align:right}
.date-time{display:inline-block;direction:ltr;unicode-bidi:isolate;white-space:nowrap}

/* ===== AUTH ===== */
.auth-main{min-height:100vh;display:grid;place-items:center;padding:20px}
.auth-card{max-width:440px;width:100%;padding:34px}
.auth-card h1{font-size:24px;font-weight:900;margin-bottom:24px;text-align:center}

/* ===== THEME TOGGLE ===== */
#themeToggle{
    transition:all .2s ease;
}
#themeToggle:hover{
    transform:scale(1.1);
}
#themeToggle i{
    transition:transform .3s ease;
}

/* ===== RESPONSIVE ===== */
@media(max-width:991px){
    .sidebar{transform:translateX(100%);transition:.25s}
    .sidebar.open{transform:translateX(0)}
    .main{margin-right:0}
    .topbar{padding:12px}
    .top-actions{gap:6px}
    .top-actions .btn-primary{display:none}
    .content{padding:14px}
    .table{min-width:780px}
}

/* ===== INVENTORY ALARM ===== */
.alert-card{
    background:rgba(255,255,255,.92);
    border:1px solid rgba(124,58,237,.12);
    border-radius:var(--radius);
    box-shadow:0 18px 45px rgba(31,41,55,.06);
    padding:20px;
}
.inventory-alert{
    border:1px solid rgba(220,38,38,.18);
    background:linear-gradient(135deg,rgba(254,242,242,.95),rgba(255,255,255,.92));
}
.table-danger-light{
    --bs-table-bg: rgba(254,226,226,.55);
}
.bg-warning-subtle{
    background:linear-gradient(135deg,rgba(254,249,195,.9),rgba(255,255,255,.9)) !important;
}
.result-chip{
    display:inline-block;
    background:rgba(124,58,237,.08);
    border:1px solid rgba(124,58,237,.12);
    border-radius:10px;
    padding:4px 10px;
    font-size:12px;
    max-width:180px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

/* ===== FOLLOWUP PAGE ===== */
.followup-page .stat-followup{
    min-height:96px;
    padding:16px 18px;
    transition:transform .15s ease, box-shadow .15s ease;
}
.followup-page .stat-followup:hover{
    transform:translateY(-2px);
    box-shadow:0 14px 30px rgba(31,41,55,.1);
}
.followup-group-card{
    border-radius:var(--radius);
    overflow:hidden;
}
.followup-group-card .card-header{
    padding:14px 18px;
    border-bottom:1px solid rgba(124,58,237,.1);
    background:rgba(124,58,237,.03);
}
.followup-table{
    font-size:14px;
}
.followup-table thead th{
    font-weight:700;
    font-size:13px;
    color:var(--muted);
    white-space:nowrap;
    border-bottom-width:1px;
}
.followup-table tbody td{
    vertical-align:middle;
}
.followup-action-form{
    background:rgba(124,58,237,.04);
    border:1px solid rgba(124,58,237,.08);
    border-radius:12px;
    padding:6px 8px;
}
.followup-action-form .form-select-sm,
.followup-action-form .form-control-sm{
    border-radius:10px;
    font-size:13px;
    padding:.35rem .6rem;
}
.empty-state{
    max-width:520px;
    margin:0 auto;
}
.empty-state i{
    width:72px;height:72px;
    display:grid;place-items:center;
    background:linear-gradient(135deg,rgba(124,58,237,.12),rgba(20,184,166,.12));
    border-radius:20px;
    margin:0 auto;
    color:var(--primary);
}

html[data-bs-theme="dark"] .alert-card,
html[data-bs-theme="dark"] .inventory-alert{
    background:rgba(15,23,42,.92) !important;
    border-color:rgba(255,255,255,.08) !important;
}
html[data-bs-theme="dark"] .inventory-alert{
    background:linear-gradient(135deg,rgba(127,29,29,.18),rgba(15,23,42,.92)) !important;
    border-color:rgba(220,38,38,.35) !important;
}
html[data-bs-theme="dark"] .table-danger-light{
    --bs-table-bg: rgba(127,29,29,.18);
}
html[data-bs-theme="dark"] .followup-group-card .card-header{
    background:rgba(124,58,237,.08);
    border-color:rgba(255,255,255,.08);
}
html[data-bs-theme="dark"] .followup-action-form{
    background:rgba(124,58,237,.08);
    border-color:rgba(255,255,255,.08);
}
html[data-bs-theme="dark"] .result-chip{
    background:rgba(124,58,237,.15);
    border-color:rgba(124,58,237,.25);
    color:#c4b5fd;
}

/* ===== IMPROVED RESPONSIVE FOR FOLLOWUP ===== */
@media(max-width:768px){
    .followup-table{
        min-width:900px;
    }
    .followup-action-form{
        padding:8px;
    }
    .followup-action-form .d-flex{
        flex-direction:column !important;
        align-items:stretch !important;
    }
    .followup-action-form select,
    .followup-action-form input{
        width:100% !important;
        min-width:unset !important;
    }
}

/* ===== JALALI DATEPICKER - Persian Calendar Overrides ===== */
jdp-container{
    z-index:99999 !important;
    font-family:Vazirmatn,Tahoma,sans-serif !important;
    border-radius:18px !important;
    box-shadow:0 20px 50px rgba(31,41,55,.18) !important;
    border:1px solid rgba(124,58,237,.12) !important;
    overflow:hidden;
}
jdp-container .jdp-day-name{
    color:var(--muted) !important;
    font-weight:600 !important;
}
jdp-container .jdp-days .jdp-day.selected,
jdp-container .jdp-days .jdp-day.jdp-selected{
    background:linear-gradient(135deg,var(--primary),#9f67ff) !important;
    color:#fff !important;
    border-radius:12px !important;
}
jdp-container .jdp-days .jdp-day:hover{
    background:rgba(124,58,237,.12) !important;
    border-radius:12px !important;
}
jdp-container .jdp-months .jdp-month.selected{
    background:var(--primary) !important;
    color:#fff !important;
    border-radius:12px !important;
}
jdp-container .jdp-years .jdp-year.selected{
    background:var(--primary) !important;
    color:#fff !important;
}
jdp-container .jdp-footer{
    background:rgba(124,58,237,.04) !important;
    border-top:1px solid rgba(124,58,237,.08) !important;
}
jdp-container button{
    border-radius:10px !important;
    font-family:Vazirmatn !important;
}
.input-group .input-group-text{
    border-radius:14px;
    background:rgba(124,58,237,.08);
    border-color:rgba(124,58,237,.16);
    color:var(--primary);
}
.input-group .form-control[data-jdp]{
    border-radius:14px !important;
    cursor:pointer;
    background-image:none !important;
}
html[data-bs-theme="dark"] jdp-container{
    background:#1e293b !important;
    border-color:rgba(255,255,255,.12) !important;
    color:#e5e7eb !important;
}
html[data-bs-theme="dark"] jdp-container .jdp-header{
    background:#0f172a !important;
    color:#e5e7eb !important;
}
html[data-bs-theme="dark"] .input-group .input-group-text{
    background:rgba(124,58,237,.15);
    border-color:#374151;
    color:#a78bfa;
}

/* ===== CUSTOMER BIRTH-MONTH FILTER ===== */
.customer-filter-form{display:grid;grid-template-columns:minmax(180px,1fr) minmax(220px,1fr);gap:14px;flex:1;min-width:0;align-items:start}
.customer-search-field{min-width:0}
.customer-filter-form .form-label{display:block;font-size:.9rem;margin-bottom:6px}
.customer-search-field>.form-control{width:100%;box-sizing:border-box}
.customer-birth-filter{min-width:0;margin:0;padding:10px 14px 14px;border:1px solid rgba(124,58,237,.18);border-radius:16px;background:rgba(124,58,237,.025)}
.customer-birth-filter .form-select{width:100%;box-sizing:border-box}
.customer-birth-filter .form-text{font-size:.76rem;line-height:1.8;margin-top:8px}
.customer-filter-actions{grid-column:1/-1;display:flex;flex-wrap:wrap;gap:8px}
html[data-bs-theme="dark"] .customer-birth-filter{background:rgba(124,58,237,.06);border-color:#475569}
@media(max-width:1199px){.customer-filter-form{grid-template-columns:minmax(0,1fr)}}
@media(max-width:767px){.customer-filter-form{flex-basis:100%}}

/* ===== SORTABLE TABLE HEADERS ===== */
.table th .sort-link, .table th > button[aria-label^="مرتب‌سازی"]{display:inline-flex;align-items:center;gap:.35rem;color:inherit;text-decoration:none;white-space:nowrap;cursor:pointer}
.table th .sort-link:hover, .table th > button[aria-label^="مرتب‌سازی"]:hover{color:var(--primary)!important}
.table th .sort-link:focus-visible, .table th > button[aria-label^="مرتب‌سازی"]:focus-visible{outline:2px solid var(--primary);outline-offset:3px;border-radius:3px}
.table th .sort-indicator{font-size:.8em;opacity:.7}
.table th[aria-sort="ascending"] .sort-indicator, .table th[aria-sort="descending"] .sort-indicator{color:var(--primary);opacity:1}

/* ===== FOLLOW-UP MATRIX ===== */
/* Customers are rows and follow-up turns are columns, so the table is wider than
   the viewport by design: the customer column stays pinned while the rest scrolls. */
.matrix-scroll{max-height:75vh}
.matrix-table{border-collapse:separate;border-spacing:0;min-width:100%}
.matrix-table thead th{position:sticky;top:0;z-index:2;background:var(--bs-tertiary-bg,#f8f9fa);white-space:nowrap;border-bottom:2px solid var(--bs-border-color,#dee2e6)}
.matrix-customer-head,.matrix-customer{position:sticky;inset-inline-start:0;z-index:1;background:var(--bs-body-bg,#fff);min-width:180px;max-width:220px;text-align:start}
.matrix-customer-head{z-index:3}
.matrix-customer{border-inline-end:2px solid var(--bs-border-color,#dee2e6)}
.matrix-turn-head{min-width:210px}
.matrix-cell{vertical-align:top;min-width:210px;max-width:260px}
.matrix-empty{color:var(--bs-secondary-color,#6c757d);text-align:center}
.matrix-date{margin-top:.35rem;font-size:.8rem;color:var(--bs-secondary-color,#6c757d)}
.matrix-result{margin-top:.35rem;font-size:.85rem;line-height:1.75;white-space:normal;overflow-wrap:anywhere}
.matrix-link{display:inline-block;margin-top:.4rem;font-size:.78rem;text-decoration:none}
.matrix-priority{font-weight:400}

/* ===== PRINT ===== */
@media print{
    .sidebar,.topbar,.btn,form{display:none!important}
    .main{margin:0}
    .card,.stat{box-shadow:none;border:1px solid #ddd}
    .content{padding:0}
}
