/* ========== فونت فارسی ========== */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');

/* ========== متغیرهای تم ========== */
:root {
    --bg: #f0f4f8;
    --surface: rgba(255, 255, 255, 0.85);
    --surface-solid: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --accent: #2e7d32;           /* جایگزین با PHP می‌شود */
    --accent-rgb: 46, 125, 50;   /* جایگزین با PHP می‌شود */
    --accent-light: #4caf50;     /* جایگزین با PHP می‌شود */
    --accent-hover: #1b5e20;     /* جایگزین با PHP می‌شود */
    --danger: #dc2626;
    --success: #16a34a;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.15);
    --radius: 16px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --chart-grid: #e2e8f0;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: rgba(30, 41, 59, 0.75);
    --surface-solid: #1e293b;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --border: #334155;
    --accent: #4caf50;
    --accent-hover: #66bb6a;
    --accent-light: #81c784;
    --danger: #ef5350;
    --success: #66bb6a;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.5);
    --chart-grid: #475569;
}

/* ========== پایه ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
    background-color: var(--bg);
    background-image: 
        radial-gradient(circle at 20% 20%, var(--accent-light) 0%, transparent 25%),
        radial-gradient(circle at 80% 80%, var(--accent) 0%, transparent 30%);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    padding: 20px;
    direction: rtl;
    text-align: right;
    transition: background-color var(--transition), color var(--transition);
    animation: fadeInPage 0.8s ease-out;
}

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

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

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* ========== کارت‌ها ========== */
.card {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
    animation: slideUp 0.6s ease-out both;
}
.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

/* ========== لینک‌ها ========== */
a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover {
    color: var(--accent-hover);
}

/* ========== دکمه‌ها ========== */
button, .btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #ffffff;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-family: 'Vazirmatn', sans-serif;
    font-weight: 500;
    transition: all var(--transition);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    display: inline-block;
    text-align: center;
    line-height: 1.5;
}
button:hover, .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    filter: brightness(1.05);
    color: #ffffff;
}
button:active, .btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}
button:active::after {
    width: 300px;
    height: 300px;
}

/* کلاس‌های کمکی برای دکمه‌های رنگی خاص */
.btn-blue { background: linear-gradient(135deg, #3498db, #2980b9); }
.btn-red { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.btn-green { background: linear-gradient(135deg, #2ecc71, #27ae60); }
.btn-gray { background: linear-gradient(135deg, #95a5a6, #7f8c8d); }

/* دکمه‌های کوچک */
.btn-sm {
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 8px;
}

/* دکمه اعمال (استفاده در نمودارها) */
.apply-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    padding: 10px 20px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.5;
    margin: 0;
    flex-shrink: 0;
    min-width: 80px;
    border-radius: 8px;
    font-family: 'Vazirmatn', sans-serif;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
.apply-btn:hover {
    background: linear-gradient(135deg, var(--accent-hover), var(--accent));
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    filter: brightness(1.05);
}
.apply-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* ========== فرم‌ها ========== */
input, select, textarea {
    background-color: var(--surface-solid);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    margin: 8px 0;
    width: 100%;
    max-width: 100%;
    font-family: 'Vazirmatn', sans-serif;
    text-align: right;
    transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.2);
}
textarea {
    min-height: 100px;
    resize: vertical;
}

/* ========== جدول‌ها ========== */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 15px 0;
    border-radius: 12px;
    overflow: hidden;
}
th {
    background: rgba(var(--accent-rgb), 0.15);
    color: var(--text);
    font-weight: 700;
    padding: 14px 16px;
    text-align: right;
    border-bottom: 2px solid var(--border);
}
td {
    padding: 12px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}
tr:last-child td {
    border-bottom: none;
}
tbody tr:hover td {
    background: rgba(var(--accent-rgb), 0.05);
}

/* ========== هشدارها ========== */
.alert {
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 16px;
    animation: slideUp 0.4s ease-out;
    font-weight: 500;
}
.alert-error {
    background: #fee2e2;
    color: var(--danger);
    border-right: 4px solid var(--danger);
}
.alert-success {
    background: #dcfce7;
    color: var(--success);
    border-right: 4px solid var(--success);
}

/* ========== نمودار ========== */
.chart-container {
    max-width: 100%;
    margin: 20px auto;
    padding: 20px;
    background: var(--surface-solid);
    border-radius: 12px;
    border: 1px solid var(--border);
    transition: transform var(--transition);
}
.chart-container:hover {
    transform: scale(1.01);
}

/* ========== اسکرول‌بار ========== */
::-webkit-scrollbar {
    width: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg);
}
::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-hover);
}

/* ========== پرینت ========== */
@media print {
    body { background: white !important; color: black !important; }
    .no-print { display: none !important; }
    .print-only { display: block !important; }
    .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
    .navbar { display: none !important; }
    table { border-collapse: collapse; width: 100%; }
    th, td { border: 1px solid #000 !important; padding: 8px; }
}

/* ========== ریسپانسیو ========== */
@media (max-width: 768px) {
    body { padding: 10px; }
    .container { padding: 0; }
    .card { padding: 18px; margin-bottom: 15px; }
    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    tr { margin-bottom: 15px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
        border-bottom: 1px solid var(--border);
    }
    td::before {
        content: attr(data-label);
        font-weight: bold;
        color: var(--text-secondary);
        margin-left: 10px;
    }
    td:last-child { border-bottom: none; }
    input, select, textarea, button { font-size: 16px; }
    .chart-container { padding: 10px; }
    .apply-btn { width: 100%; min-width: unset; }
}

@media (max-width: 480px) {
    .card { padding: 15px; }
    button, .btn { padding: 10px 20px; width: 100%; }
    .card h2, .card h3 { font-size: 1.3rem; }
}

/* ========== نقطه‌های اعلان (هدر) ========== */
.notification-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    background: var(--danger);
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* ========== چت ========== */
.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 220px);
    min-height: 300px;
}
.chat-header-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-shrink: 0;
}
.chat-header-bar .btn-back {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 10px;
    min-height: 0;
}
.chat-input-area {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}
.chat-input-area textarea {
    flex: 1;
    min-height: 50px;
    resize: none;
}
.chat-input-area button {
    white-space: nowrap;
}
.conversation-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.conversation-list .chat-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
    border-radius: 10px;
    cursor: pointer;
}
.conversation-list .chat-item:hover {
    background: rgba(var(--accent-rgb), 0.05);
}
.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 20px;
    flex-shrink: 0;
    margin-left: 12px;
    text-decoration: none;
}
.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; color: var(--text); margin-bottom: 3px; }
.chat-last {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}
.chat-meta {
    text-align: left;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}
.chat-time { color: var(--text-secondary); font-size: 11px; white-space: nowrap; }
.chat-unread {
    background: var(--accent);
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}
.message-row { display: flex; margin-bottom: 8px; }
.message-row.sent { justify-content: flex-end; }
.message-row.received { justify-content: flex-start; }
.message-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 15px;
    position: relative;
    word-wrap: break-word;
}
.message-bubble.sent {
    background: var(--accent);
    color: white;
    border-bottom-left-radius: 5px;
}
.message-bubble.received {
    background: var(--surface-solid);
    color: var(--text);
    border-bottom-right-radius: 5px;
    border: 1px solid var(--border);
}
.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 3px;
    text-align: left;
}
.message-bubble.sent .message-time { color: rgba(255,255,255,0.7); }
.day-separator {
    text-align: center;
    margin: 10px 0;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    position: relative;
}
.day-separator::before,
.day-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: var(--border);
}
.day-separator::before { right: 0; }
.day-separator::after { left: 0; }
.day-separator span {
    background: var(--bg);
    padding: 0 10px;
    position: relative;
    z-index: 1;
    border-radius: 10px;
}

/* ========== دکمه‌های رنگ پیشنهادی ========== */
.suggested-color-btn {
    width: 35px;
    height: 35px;
    border-radius: 8px;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    margin: 0;
    background-image: none;
}
.suggested-color-btn.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.3);
    transform: scale(1.1);
}
.suggested-color-btn:hover {
    transform: scale(1.1);
}

/* انتخاب رنگ سفارشی */
.custom-color-picker {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
}
.custom-color-picker label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 5px;
}
.custom-color-picker input[type="color"] {
    width: 60px;
    height: 40px;
    padding: 2px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    background: var(--surface-solid);
}
.suggested-colors {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.suggested-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-left: 5px;
}

/* ========== پنل‌های مشاهده‌پذیری ========== */
.visibility-panel {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 15px;
}
.visibility-panel h4 {
    margin: 0 0 10px 0;
    color: var(--text);
}
.visibility-options {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}
.visibility-options label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: background var(--transition);
}
.visibility-options label:hover {
    background: rgba(var(--accent-rgb), 0.05);
}
.visibility-options input[type="radio"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

/* ========== فرم بازه تاریخ (نمودارها) ========== */
.date-range-form {
    margin-top: 15px;
    padding: 10px;
    background: var(--surface-solid);
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}
.date-range-form .date-label {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 30px;
}
.date-range-form select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-solid);
    color: var(--text);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 14px;
    width: auto;
    min-width: 80px;
    flex-shrink: 1;
}
.date-range-form select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.2);
}

/* دکمه اعمال داخل فرم تاریخ */
.date-range-form .apply-btn {
    flex-shrink: 0;
}

/* ========== دکمه‌های تغییر حالت ========== */
.stats-toggle,
.chart-toggle {
    display: inline-flex;
    gap: 0;
    margin-bottom: 10px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.toggle-btn {
    padding: 8px 16px;
    background: var(--surface-solid);
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 14px;
}
.toggle-btn.active {
    background: var(--accent);
    color: white;
}
.toggle-btn:not(.active):hover {
    background: rgba(var(--accent-rgb), 0.1);
}

/* ========== ریسپانسیو تکمیلی برای فرم تاریخ ========== */
@media (max-width: 768px) {
    .date-range-form {
        flex-direction: column;
        align-items: stretch;
        flex-wrap: nowrap;
    }
    .date-range-form .date-label {
        width: auto;
        margin-bottom: 0;
        white-space: nowrap;
    }
    .date-range-form select {
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
    }
    .date-range-form .apply-btn {
        width: 100%;
        min-width: unset;
    }
}

/* ========== ریسپانسیو تکمیلی (سایر) ========== */
@media (max-width: 768px) {
    .color-selection-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .suggested-colors {
        width: 100%;
    }
    .visibility-options {
        flex-direction: column;
        gap: 8px;
    }
    .chat-wrapper {
        height: calc(100dvh - 160px);
    }
    .chat-input-area {
        flex-direction: column;
    }
    .chat-input-area textarea {
        width: 100%;
    }
    .chat-input-area button {
        width: 100%;
    }
}
/* ========== اصلاح نمایش دکمه چشم در فیلد رمز عبور ========== */
.input-group {
    position: relative;
    display: block;
    width: 100%;
}

.input-group input {
    padding-left: 40px; /* فاصله برای آیکون چشم */
    padding-right: 16px; /* حفظ فاصله از راست */
    width: 100%;
    box-sizing: border-box;
}

.toggle-password {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: auto !important;
    min-width: unset !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    z-index: 2;
    transition: color var(--transition);
}

.toggle-password:hover {
    color: var(--accent);
    background: none !important;
    filter: none !important;
    transform: translateY(-50%) !important;
}

.toggle-password svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

/* موبایل */
@media (max-width: 768px) {
    .input-group input {
        padding-left: 40px;
        padding-right: 12px;
    }
    .toggle-password {
        left: 8px;
    }
}