/* =========================================================================
   پرسشنامه پیش از بیهوشی — سیستم طراحی
   پالت: تیل بالینی آرام + نعنایی + کهربایی برای تاکید + مرجانی برای هشدار
   تایپوگرافی: Vazirmatn برای عنوان/متن، JetBrains Mono برای داده‌های عددی
   ========================================================================= */

:root {
    --bg: #F1F5F3;
    --bg-alt: #E7EFEC;
    --surface: #FFFFFF;
    --ink: #16262A;
    --ink-soft: #4C6763;
    --line: #D6E3DF;

    --primary: #0F5C56;
    --primary-dark: #0A413D;
    --primary-soft: #DCEEE9;
    --mint: #8FD9C4;

    --amber: #C98A2E;
    --amber-soft: #FBEEDA;

    --coral: #D64550;
    --coral-soft: #FBE4E1;

    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 9px;

    --shadow-sm: 0 1px 3px rgba(15, 45, 41, 0.08);
    --shadow-md: 0 8px 24px rgba(15, 45, 41, 0.10);
    --shadow-lg: 0 20px 48px rgba(15, 45, 41, 0.14);

    --font-display: 'Vazirmatn', Tahoma, sans-serif;
    --font-body: 'Vazirmatn', Tahoma, sans-serif;
    --font-mono: 'JetBrains Mono', Consolas, monospace;

    --step-scale: 1;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

body {
    min-height: 100vh;
    background-image:
        radial-gradient(circle at 15% 0%, var(--bg-alt) 0%, transparent 45%),
        radial-gradient(circle at 100% 30%, var(--primary-soft) 0%, transparent 40%);
    background-attachment: fixed;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 800; color: var(--primary-dark); margin: 0 0 .5em; }
p { line-height: 1.9; margin: 0 0 1em; color: var(--ink); }
.num { font-family: var(--font-mono); direction: ltr; unicode-bidi: isolate; }

a { color: var(--primary); }

/* ---------- شل صفحه ---------- */
.page-shell {
    max-width: 760px;
    margin: 0 auto;
    padding: 28px 20px 80px;
}

.site-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.site-header .badge {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 20px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.site-header .titles h1 { font-size: 1.25rem; margin: 0; }
.site-header .titles .doctor-name { color: var(--ink-soft); font-size: .92rem; font-weight: 500; }

/* ---------- موج تنفس (نشانه تصویری) ---------- */
.breath-wave-wrap {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 14px 18px 10px;
    margin-bottom: 26px;
    overflow: hidden;
}

.breath-wave-wrap svg { display: block; width: 100%; height: 46px; }

.breath-wave-wrap .wave-group {
    transform: scaleY(var(--step-scale));
    transform-origin: center;
    transition: transform 900ms cubic-bezier(.22,.9,.3,1);
}

.breath-wave-wrap .wave-path {
    fill: none;
    stroke: var(--mint);
    stroke-width: 3;
    stroke-linecap: round;
}

.breath-wave-wrap .wave-dot {
    fill: var(--primary);
    transition: cx 500ms ease, left 500ms ease;
}

.step-meta {
    display: flex;
    justify-content: space-between;
    font-size: .8rem;
    color: var(--ink-soft);
    margin-top: 4px;
}
.step-meta .step-title { font-weight: 700; color: var(--primary-dark); }

/* ---------- کارت مرحله فرم ---------- */
.step-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 30px 26px;
    margin-bottom: 20px;
}

.field { margin-bottom: 22px; }
.field label.field-label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--ink);
}
.field .help-text { font-size: .82rem; color: var(--ink-soft); margin-top: 6px; }
.field .error-text { font-size: .82rem; color: var(--coral); margin-top: 6px; font-weight: 600; display: none; }
.field.has-error .error-text { display: block; }
.field.has-error input, .field.has-error select, .field.has-error textarea {
    border-color: var(--coral) !important;
    background: var(--coral-soft) !important;
}

input[type="text"], input[type="number"], input[type="date"], select, textarea {
    width: 100%;
    font-family: var(--font-body);
    font-size: 1rem;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    background: var(--bg-alt);
    color: var(--ink);
    transition: border-color .2s, background .2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}
textarea { min-height: 90px; resize: vertical; font-family: var(--font-body); }

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.checkbox-item {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-alt);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    cursor: pointer;
}
.checkbox-item input { width: 17px; height: 17px; accent-color: var(--primary); }

/* ---------- سوال بله/خیر ---------- */
.yesno-question { margin-bottom: 26px; }
.yesno-question .q-category {
    display: inline-block;
    font-size: .74rem;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 999px;
    padding: 3px 12px;
    margin-bottom: 10px;
}
.yesno-question .q-text { font-size: 1.06rem; font-weight: 700; margin-bottom: 12px; line-height: 1.7; }

.yesno-buttons { display: flex; gap: 10px; }
.yesno-buttons button {
    flex: 1;
    padding: 13px 10px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    background: var(--bg-alt);
    font-family: var(--font-body);
    font-size: .98rem;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
    transition: all .15s;
}
.yesno-buttons button.selected-yes { background: var(--coral-soft); border-color: var(--coral); color: #9c2b34; }
.yesno-buttons button.selected-no { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
.yesno-buttons button:hover { box-shadow: var(--shadow-sm); }

.followup-field { margin-top: 12px; display: none; }
.followup-field.visible { display: block; }

/* ---------- دکمه‌های ناوبری ---------- */
.nav-buttons {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px;
}
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 13px 26px;
    border-radius: 999px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: .98rem;
    border: none;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s, background .2s;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-primary:disabled { background: #A9BDB9; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); }
.btn-submit { background: var(--amber); color: #fff; }
.btn-submit:hover { background: #A6721F; }

/* ---------- صفحه نتیجه / گزارش‌ها ---------- */
.report-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.report-tabs button {
    padding: 10px 20px;
    border-radius: 999px;
    border: 1.5px solid var(--line);
    background: var(--surface);
    font-family: var(--font-body);
    font-weight: 700;
    cursor: pointer;
    color: var(--ink-soft);
}
.report-tabs button[data-tab="patient"].active { background: var(--primary); border-color: var(--primary); color: #fff; }
.report-tabs button[data-tab="doctor"].active { background: var(--amber); border-color: var(--amber); color: #fff; }
.report-tabs button[data-tab="or"].active { background: var(--coral); border-color: var(--coral); color: #fff; }

.report-panel { display: none; }
.report-panel.active { display: block; }

.report {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 28px 26px;
    border-inline-start: 6px solid var(--line);
}
.patient-report { border-inline-start-color: var(--primary); }
.doctor-report { border-inline-start-color: var(--amber); }
.or-report { border-inline-start-color: var(--coral); }

.report .lead { color: var(--ink-soft); }
.report .footnote { font-size: .85rem; color: var(--ink-soft); margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 12px; }

.urgent-banner {
    background: var(--coral-soft);
    color: #7A1F27;
    font-weight: 800;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    border: 1.5px solid var(--coral);
}

.info-table, .answers-table { width: 100%; border-collapse: collapse; margin: 12px 0 20px; font-size: .92rem; }
.info-table th, .info-table td, .answers-table th, .answers-table td {
    text-align: right;
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
}
.info-table th { width: 34%; color: var(--ink-soft); font-weight: 700; background: var(--bg-alt); }
.answers-table th { background: var(--bg-alt); color: var(--ink-soft); }
.or-alerts li { margin-bottom: 8px; font-weight: 600; }

.print-actions { display: flex; gap: 10px; margin: 20px 0; }

/* ---------- بارگذاری/خطا ---------- */
.loading-overlay {
    position: fixed; inset: 0; background: rgba(241,245,243,.9);
    display: flex; align-items: center; justify-content: center;
    z-index: 50; flex-direction: column; gap: 14px;
}
.spinner {
    width: 40px; height: 40px; border-radius: 50%;
    border: 4px solid var(--primary-soft); border-top-color: var(--primary);
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner-error {
    background: var(--coral-soft); color: #7A1F27; border: 1.5px solid var(--coral);
    border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 18px; font-weight: 600;
}

@media (max-width: 560px) {
    .checkbox-grid { grid-template-columns: 1fr 1fr; }
    .step-card { padding: 22px 18px; }
}

/* ---------- چاپ ---------- */
@media print {
    body { background: #fff !important; }
    .no-print { display: none !important; }
    .report-panel { display: block !important; page-break-after: always; margin-bottom: 40px; }
    .report { box-shadow: none; border: 1.5px solid #ccc; }
}

/* =========================================================================
   افزوده‌های نسخه ۲: آپلود مدارک بیمار + ویرایش/ارسال پزشک
   ========================================================================= */

/* ---------- ویجت آپلود مدارک (فرم بیمار + صفحه در حال بررسی) ---------- */
.attach-dropzone {
    border: 2px dashed var(--line);
    border-radius: var(--radius-md);
    background: var(--bg-alt);
    padding: 26px 16px;
    text-align: center;
    cursor: pointer;
    color: var(--ink-soft);
    transition: border-color .15s, background .15s;
}
.attach-dropzone:hover, .attach-dropzone.drag-over {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.attach-dropzone-icon { font-size: 1.6rem; margin-bottom: 6px; }

.attach-list { list-style:none; margin: 14px 0 0; padding: 0; display:flex; flex-direction:column; gap:8px; }
.attach-item {
    display:flex; align-items:center; gap:10px;
    background: var(--surface); border:1.5px solid var(--line); border-radius: var(--radius-sm);
    padding: 8px 12px;
}
.attach-item-name { flex:1; font-size:.92rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.attach-item-size { font-size:.8rem; color: var(--ink-soft); }
.attach-item-remove {
    border:none; background:transparent; color: var(--coral); font-weight:700; cursor:pointer; font-size:1rem;
}

/* ---------- گالری مدارک در پنل پزشک ---------- */
.attachments-gallery {
    background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
    padding: 20px 22px; margin-bottom: 20px;
}
.attach-note-display { font-size:.9rem; color: var(--ink-soft); }
.attach-gallery-grid {
    display:grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px;
}
.attach-gallery-item {
    display:flex; flex-direction:column; align-items:center; gap:4px;
    text-decoration:none; color: var(--ink); text-align:center;
    border:1.5px solid var(--line); border-radius: var(--radius-sm); padding:8px; background: var(--bg-alt);
}
.attach-gallery-item:hover { border-color: var(--primary); }
.attach-gallery-item img { width:100%; height:80px; object-fit:cover; border-radius:6px; }
.attach-gallery-file {
    width:100%; height:80px; display:flex; align-items:center; justify-content:center;
    background: var(--primary-soft); border-radius:6px; font-size:1.4rem;
}
.attach-gallery-name { font-size:.72rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; width:100%; }
.attach-gallery-size { font-size:.68rem; color: var(--ink-soft); }

/* ---------- نوار وضعیت پرونده + دکمه ارسال (پنل پزشک) ---------- */
.admin-status-bar {
    display:flex; align-items:center; justify-content:space-between; gap:12px;
    background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
    padding: 12px 18px; margin-bottom: 16px;
}
.status-badge { font-weight:700; padding:5px 14px; border-radius:999px; font-size:.85rem; }
.status-badge.status-pending { background: var(--amber-soft); color:#8a5a17; }
.status-badge.status-sent { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- ویرایش نسخه بیمار/اتاق عمل توسط پزشک ---------- */
.edit-toolbar {
    display:flex; align-items:center; gap:8px; margin-bottom:10px;
    background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
    padding: 8px 12px;
}
.edit-toolbar button {
    border:1.5px solid var(--line); background: var(--bg-alt); border-radius:6px;
    padding:5px 10px; cursor:pointer; font-family: var(--font-body);
}
.edit-toolbar .edit-hint { font-size:.78rem; color: var(--ink-soft); margin-inline-start:auto; }

.report-panel[data-panel="patient"] .report[contenteditable="true"],
.report-panel[data-panel="or"] .report[contenteditable="true"] {
    outline: 2px dashed var(--mint);
    outline-offset: 4px;
    cursor: text;
}
.save-panel-btn { margin-top: 16px; }
