/* ═══════════ متغیرها و پایه ═══════════ */
:root {
    --teal: #0d9488; --teal-dark: #0f766e; --teal-soft: #f0fdfa;
    --bg: #f1f5f9; --card: #fff; --border: #e2e8f0;
    --text: #0f172a; --muted: #64748b;
    --amber: #d97706; --blue: #2563eb; --green: #059669; --red: #dc2626;
    --radius: 14px; --shadow: 0 1px 3px rgba(15, 23, 42, .07);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Vazirmatn, 'Segoe UI', Tahoma, sans-serif; background: var(--bg); color: var(--text); line-height: 1.8; }
a { color: var(--teal-dark); text-decoration: none; }
.hidden { display: none !important; }
.ltr { direction: ltr; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.grow { flex: 1; }

/* ═══════════ نوار بالا ═══════════ */
.topbar { position: sticky; top: 0; z-index: 100; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 18px; padding: 10px 22px; flex-wrap: wrap; box-shadow: var(--shadow); }
.brand { font-size: 1.15rem; font-weight: 800; color: var(--teal-dark); display: flex; align-items: baseline; gap: 8px; }
.brand small { font-weight: 400; color: var(--muted); font-size: .75rem; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tabs a { padding: 7px 14px; border-radius: 10px; color: var(--muted); font-size: .88rem; font-weight: 600; transition: .15s; }
.tabs a:hover { background: var(--teal-soft); color: var(--teal-dark); }
.tabs a.active { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); color: #fff; }
.conn { display: flex; align-items: center; gap: 7px; font-size: .8rem; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(5, 150, 105, .15); }
.dot.off { background: var(--red); box-shadow: 0 0 0 4px rgba(220, 38, 38, .12); }
#btn-settings { border: 1px solid var(--border); background: #fff; border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: .95rem; }
#btn-settings:hover { background: var(--teal-soft); }

/* ═══════════ چیدمان اصلی ═══════════ */
.container { max-width: 1080px; margin: 0 auto; padding: 22px 16px 60px; }
.view-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.view-head h2 { color: var(--teal-dark); font-size: 1.25rem; }
.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 18px; }

/* ═══════════ فرم‌ها و فیلترها ═══════════ */
.filter-bar, .finder-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
input[type="text"], select, textarea {
    font-family: inherit; font-size: .88rem; color: var(--text);
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    padding: 9px 13px; outline: none; transition: .15s;
}
input[type="text"]:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 148, 136, .14); }
.filter-bar input[type="text"] { min-width: 220px; flex: 1; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 10px; }
label input, label select, label textarea { width: 100%; margin-top: 5px; font-weight: 400; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 10px; padding: 9px 13px; font-size: .83rem; margin-bottom: 10px; }

/* ═══════════ دکمه‌ها ═══════════ */
.btn { font-family: inherit; font-size: .86rem; font-weight: 700; border: none; border-radius: 10px; padding: 9px 18px; cursor: pointer; transition: .15s; }
.btn.primary { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--teal-dark); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--teal-soft); }
.btn.small { padding: 6px 12px; font-size: .8rem; }
.btn.mini { padding: 4px 10px; font-size: .74rem; border-radius: 8px; }
.btn.blue { background: #dbeafe; color: var(--blue); }
.btn.green { background: #d1fae5; color: var(--green); }
.btn.amber { background: #fef3c7; color: var(--amber); }
.btn.red { background: #fee2e2; color: var(--red); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link-danger { background: none; border: none; color: var(--red); font-size: .78rem; cursor: pointer; font-family: inherit; padding: 0; }
.link-danger:hover { text-decoration: underline; }

/* ═══════════ کارت‌ها و پنل‌ها ═══════════ */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h3 { font-size: .98rem; color: var(--text); margin-bottom: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 16px; }
.cards-grid.tight { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 11px; }
.card-head { display: flex; align-items: center; gap: 11px; }
.avatar { width: 46px; height: 46px; min-width: 46px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; justify-content: center; }
.avatar.big { width: 58px; height: 58px; font-size: 1.45rem; }
.card .name { font-weight: 700; font-size: .95rem; }
.rating { font-size: .8rem; white-space: nowrap; }
.stars { color: #f59e0b; letter-spacing: 1px; }
.stars-off { color: #cbd5e1; }
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #f1f5f9; border: 1px solid var(--border); color: #334155; font-size: .76rem; border-radius: 999px; padding: 3px 11px; }
.chip.big { font-size: .82rem; padding: 5px 14px; }
.chip.teal { background: var(--teal-soft); border-color: #99f6e4; color: var(--teal-dark); font-weight: 700; }
.card-actions { display: flex; gap: 8px; margin-top: auto; }

/* ═══════════ کارت‌های آمار و نمودار میله‌ای ═══════════ */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); }
.stat-icon { font-size: 1.6rem; }
.stat-val { font-size: 1.35rem; font-weight: 800; line-height: 1.3; }
.stat-label { font-size: .78rem; color: var(--muted); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: .82rem; }
.bar-label { width: 120px; min-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .5s ease; }
.bar-val { min-width: 40px; text-align: left; color: var(--muted); font-weight: 700; }

/* ═══════════ جدول‌ها ═══════════ */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl th { text-align: right; font-size: .76rem; color: var(--muted); background: #f8fafc; padding: 9px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 10px 11px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tbl tr:hover td { background: #fafcfd; }
.actions-cell { white-space: nowrap; display: flex; gap: 5px; flex-wrap: wrap; }

/* ═══════════ نشان‌ها ═══════════ */
.badge { display: inline-block; font-size: .74rem; font-weight: 700; padding: 3px 11px; border-radius: 999px; white-space: nowrap; }
.badge.green { background: #d1fae5; color: var(--green); }
.badge.blue { background: #dbeafe; color: var(--blue); }
.badge.amber { background: #fef3c7; color: var(--amber); }
.badge.red { background: #fee2e2; color: var(--red); }
.badge.gray { background: #f1f5f9; color: #475569; }

/* ═══════════ صفحه‌بندی ═══════════ */
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; padding: 6px 0 14px; font-size: .83rem; color: var(--muted); }

/* ═══════════ حالت‌های بارگذاری/خالی/خطا ═══════════ */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 34px 10px; font-size: .88rem; }
.spin { width: 22px; height: 22px; border: 3px solid #cbd5e1; border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { border: 2px dashed var(--border); border-radius: var(--radius); text-align: center; color: var(--muted); padding: 28px; font-size: .88rem; }
.errorbox { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: var(--radius); padding: 16px; font-size: .88rem; }
.error-view { text-align: center; padding: 44px 20px; }
.error-view .big-icon { font-size: 3rem; margin-bottom: 10px; }
.center-row { display: flex; justify-content: center; gap: 10px; margin-top: 12px; }

/* ═══════════ جستجوی هوشمند ═══════════ */
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.mode-switch button { font-family: inherit; font-size: .92rem; font-weight: 700; padding: 15px; border-radius: var(--radius); border: 2px solid var(--border); background: #fff; cursor: pointer; transition: .15s; color: var(--muted); }
.mode-switch button.active { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); box-shadow: 0 4px 14px -6px rgba(13, 148, 136, .4); }
.finder-panel h3 { margin-bottom: 14px; }
.finder-row.wrap { flex-wrap: wrap; }
.finder-row select { min-width: 230px; }
.finder-row input[type="text"] { min-width: 200px; }
.pills { display: inline-flex; background: #f1f5f9; border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.pills button { font-family: inherit; border: none; background: none; padding: 6px 15px; border-radius: 8px; cursor: pointer; font-size: .82rem; font-weight: 700; color: var(--muted); }
.pills button.active { background: var(--teal-dark); color: #fff; }
.search-select { position: relative; flex: 1; min-width: 240px; }
.search-select input { width: 100%; }
.suggestions { position: absolute; top: calc(100% + 5px); right: 0; left: 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px -10px rgba(15, 23, 42, .25); z-index: 50; overflow: hidden; max-height: 300px; overflow-y: auto; }
.sugg { padding: 9px 14px; cursor: pointer; font-size: .86rem; display: flex; justify-content: space-between; gap: 8px; }
.sugg:hover { background: var(--teal-soft); }
.result-head { margin-bottom: 12px; font-size: .9rem; }
.add-doctor-row { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.add-doctor-row select { flex: 1; min-width: 220px; }

/* ═══════════ تب‌های کوچک مودال بیمار ═══════════ */
.tabs-mini { display: flex; gap: 6px; margin: 14px 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tabs-mini button { font-family: inherit; border: none; background: none; cursor: pointer; font-size: .86rem; font-weight: 700; color: var(--muted); padding: 6px 13px; border-radius: 9px; }
.tabs-mini button.active { background: var(--teal-soft); color: var(--teal-dark); }

/* ═══════════ مودال‌ها ═══════════ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; backdrop-filter: blur(2px); }
.modal { background: #fff; border-radius: 18px; padding: 22px 24px; width: min(520px, 96vw); max-height: 90vh; overflow-y: auto; animation: pop .18s ease; }
.modal.modal-lg { width: min(760px, 96vw); }
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { font-size: 1.02rem; }
.modal-head .close { border: none; background: #f1f5f9; width: 32px; height: 32px; border-radius: 9px; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
.modal-head .close:hover { background: #fee2e2; color: var(--red); }
body.modal-open { overflow: hidden; }

/* ═══════════ پیام‌های شناور ═══════════ */
#toasts { position: fixed; bottom: 18px; left: 18px; z-index: 1200; display: flex; flex-direction: column; gap: 9px; max-width: 360px; }
.toast { background: #fff; border: 1px solid var(--border); border-right: 4px solid var(--green); border-radius: 12px; padding: 11px 15px; font-size: .85rem; box-shadow: 0 10px 30px -10px rgba(15, 23, 42, .3); animation: slide-in .25s ease; }
.toast.error { border-right-color: var(--red); }
.toast.out { opacity: 0; transition: .3s; }
@keyframes slide-in { from { transform: translateX(-16px); opacity: 0; } }

/* ═══════════ واکنش‌گرا ═══════════ */
@media (max-width: 760px) {
    .topbar { justify-content: center; }
    .dash-grid, .grid-2, .mode-switch { grid-template-columns: 1fr; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .filter-bar input[type="text"] { min-width: 150px; }
    .bar-label { width: 90px; min-width: 90px; }
}
