/* 
===============================================
  نسخه‌یار - استایل‌های اصلی (طراحی پزشکی)
  - طراحی مینیمال و مدرن برای محیط پزشکی
  - تمرکز بر خوانایی و نمایش حرفه‌ای نسخه‌ها
  - بهینه‌سازی برای تمام دستگاه‌ها
===============================================
*/

/* --- تعریف فونت‌ها --- */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

/* --- متغیرهای CSS --- */
:root {
    /* رنگ‌های اصلی (پزشکی و بهداشتی) */
    --primary-color: #1565C0;
    /* آبی پزشکی کلاسیک */
    --primary-hover: #0D47A1;
    /* حالت Hover تیره‌تر */
    --secondary-color: #4CAF50;
    /* سبز بهداشتی برای موفقیت */
    --medical-accent: #00BCD4;
    /* آبی فیروزه‌ای پزشکی */

    /* رنگ‌های پس‌زمینه (تمیز و استریل) */
    --bg-color: #F8FAFB;
    /* پس‌زمینه اصلی، خاکستری خیلی روشن */
    --bg-card: #FFFFFF;
    /* سفید خالص برای کارت‌ها */
    --bg-form: #FAFBFC;
    /* کمی روشن‌تر از پس‌زمینه اصلی */
    --bg-document: #FFFFFF;
    /* رنگ پس‌زمینه نسخه‌ها */
    --bg-prescription-type: #E3F2FD;
    /* پس‌زمینه کارت انتخاب نوع نسخه */

    /* رنگ‌های متن (حرفه‌ای و خوانا) */
    --text-primary: #1565C0;
    /* متن اصلی، همرنگ Primary پزشکی */
    --text-secondary: #546E7A;
    /* متن ثانویه، خاکستری متوسط */
    --text-muted: #9E9E9E;
    /* متن‌های غیرفعال یا کم‌رنگ‌تر */
    --text-document: #2E3440;
    /* متون رسمی نسخه‌ها */
    --text-navbar: #FFFFFF;
    /* رنگ متن در نوار ناوبری */
    --text-footer: #ffffff;
    /* رنگ متن در فوتر */

    /* رنگ‌های حاشیه (ظریف و پزشکی) */
    --border-color: #E1F5FE;
    /* خطوط ظریف آبی روشن */
    --border-color-light: #F1F8FF;
    /* خطوط بسیار روشن */
    --border-color-dark: #B3E5FC;
    /* خطوط واضح‌تر */

    /* سایه‌ها */
    --shadow-sm: 0 1px 3px rgba(21, 101, 192, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(21, 101, 192, 0.1), 0 2px 4px -1px rgba(21, 101, 192, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(21, 101, 192, 0.12), 0 4px 6px -2px rgba(21, 101, 192, 0.08);

    /* اندازه‌ها */
    --border-radius-sm: 0.375rem;
    --border-radius-md: 0.5rem;
    --border-radius-lg: 0.75rem;

    /* انیمیشن */
    --transition-speed: 0.15s;
}

/* --- استایل‌های عمومی --- */
html {
    font-size: 16px;
    height: 100%;
}

body {
    font-family: 'Vazirmatn', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* --- ناوبری --- */
.navbar {
    background-color: var(--primary-color) !important;
    padding: 0.75rem 0;
    box-shadow: 0 2px 4px rgba(21, 101, 192, 0.15);
}

.navbar-brand {
    font-weight: 500;
    font-size: 1.3rem;
    color: var(--text-navbar) !important;
}

.navbar-brand img {
    height: 38px;
    width: auto;
    transition: transform var(--transition-speed) ease;
}

.navbar-brand:hover img {
    transform: scale(1.05);
}

.navbar .btn-outline-primary {
    color: var(--text-navbar);
    border-color: rgba(255, 255, 255, 0.3);
}

.navbar .btn-outline-primary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.navbar .user-info {
    color: var(--text-navbar);
    font-weight: 500;
}

/* --- محتوای اصلی --- */
main {
    flex: 1;
    padding: 2rem 1rem;
}

.card-container {
    background-color: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    width: 100%;
    margin: 0 auto;
    border: 1px solid var(--border-color-light);
}

@media (max-width: 768px) {
    .card-container {
        padding: 1.5rem;
    }
}

@media (max-width: 576px) {
    .card-container {
        padding: 1.25rem;
        border-radius: var(--border-radius-md);
    }
}

/* --- لوگو --- */
.logo {
    max-width: 100px;
    height: auto;
    margin-bottom: 1rem;
    transition: transform 0.2s ease;
}

.logo:hover {
    transform: scale(1.05);
}

/* --- انتخاب نوع نسخه --- */
.prescription-type-card {
    margin-bottom: 1rem;
}

.prescription-type-card .form-check-input {
    display: none;
}

.prescription-type-card .card {
    border: 2px solid var(--border-color);
    transition: all var(--transition-speed) ease;
    cursor: pointer;
    background-color: var(--bg-prescription-type);
}

.prescription-type-card .card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.prescription-type-card .form-check-input:checked+.form-check-label .card {
    border-color: var(--primary-color);
    background-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
}

.prescription-icon {
    color: var(--primary-color);
    transition: color var(--transition-speed) ease;
}

.prescription-type-card .form-check-input:checked+.form-check-label .prescription-icon {
    color: white;
}

/* --- فرم‌ها --- */
.form-floating>.form-control {
    border: 1px solid var(--border-color);
    transition: all var(--transition-speed) ease;
    font-size: 0.95rem;
}

.form-floating>.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15);
}

.form-floating>.form-control,
.form-floating>.form-control:focus {
    background-color: var(--bg-form);
}

.form-floating>label {
    color: var(--text-secondary);
    padding-right: 1rem;
}

textarea {
    resize: none;
    min-height: 180px !important;
    line-height: 1.7 !important;
}

.textarea-wrapper {
    position: relative;
}

.speech-btn {
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 5;
}

.speech-btn svg {
    width: 20px;
    height: 20px;
    fill: #6c757d;
    transition: fill var(--transition-speed) ease;
}

.speech-btn:hover svg {
    fill: var(--primary-color);
}

.speech-btn.recording svg {
    fill: #dc3545;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

/* --- دکمه‌ها --- */
.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-speed) ease;
    font-weight: 500;
    padding: 0.6rem 1.5rem;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background-color: transparent;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-speed) ease;
}

.btn-outline-primary:hover {
    background-color: var(--primary-hover);
    color: white;
}

.btn-outline-success {
    color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-outline-success:hover {
    background-color: var(--secondary-color);
    color: white;
}

/* --- نمایش نسخه پزشکی --- */
.document-container {
    margin-top: 2rem;
    position: relative;
    animation: fadeIn 0.4s ease-out forwards;
}

.document-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.75rem;
}

.document-title {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--primary-color);
    margin: 0;
}

.document-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.document-content {
    background-color: var(--bg-document);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 1.75rem;
    color: var(--text-document);
    line-height: 1.95;
    /* افزایش فاصله خطوط برای خوانایی بهتر */
    text-align: justify;
    direction: rtl;
    font-size: 0.95rem;
    white-space: normal;
    box-shadow: var(--shadow-sm);
}

.document-content table {
    margin: 1rem 0;
    font-size: 0.9rem;
}

/* تیترهای داخل محتوای نسخه (Markdown headings) */
.document-content h2,
.document-content h3 {
    color: var(--primary-color);
    font-weight: 700;
    line-height: 1.4;
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    position: relative;
    padding-right: 0.75rem;
    /* برای RTL: نوار تاکید در راست */
}

.document-content h2::before,
.document-content h3::before {
    content: "";
    position: absolute;
    right: 0;
    top: 0.35rem;
    bottom: 0.35rem;
    width: 4px;
    border-radius: 4px;
    background: linear-gradient(180deg, var(--primary-color), var(--medical-accent));
}

.document-content p {
    margin: 0 0 0.75rem;
}

.document-content ul,
.document-content ol {
    margin: 0 0 1rem 0;
}

.document-content li {
    margin: 0.25rem 0;
    line-height: 1.9;
}

.document-content blockquote {
    border-right: 3px solid var(--border-color-dark);
    background: #f7fbff;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-sm);
    margin: 0.75rem 0;
}

/* جدول‌ها باید LTR و از چپ به راست باشند */
.document-content table {
    direction: ltr;
    /* ستون‌ها از چپ به راست */
    text-align: left;
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
}

.document-content table thead th {
    background: #f5f9ff;
    color: #174ea6;
    font-weight: 700;
}

.document-content table th,
.document-content table td {
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.document-content table tbody tr:nth-child(even) {
    background: #fbfdff;
}

/* اسکرول افقی برای جدول‌ها در موبایل */
.document-content .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* اکشن‌های سند و فوتر کمی ظریف‌تر */
.document-header {
    gap: 0.75rem;
}

.document-footer {
    margin-top: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: left;
    /* در RTL، تاریخ در گوشه چپ بهتر دیده می‌شود */
}

.document-content table {
    width: 100%;
    border-collapse: collapse;
    direction: rtl;
}

.document-content table th,
.document-content table td {
    border: 1px solid var(--border-color-dark);
    padding: 0.5rem 0.75rem;
    vertical-align: top;
}

.document-content table thead th {
    background-color: #e3f2fd;
    color: #0d47a1;
}

.document-content table tbody tr:nth-child(even) {
    background-color: #fafcff;
}

.document-content table tbody tr:hover {
    background-color: #f1f8ff;
}

.document-content .table-primary th {
    background-color: var(--primary-color) !important;
    color: white;
}

.document-footer {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-style: italic;
}

/* --- پیام‌های خطا --- */
.alert {
    border-radius: var(--border-radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
    border-right: 4px solid transparent;
    animation: fadeIn 0.3s ease-out forwards;
}

.alert-danger {
    background-color: #ffebee;
    border-color: #f44336;
    color: #c62828;
}

.alert-info {
    background-color: #e3f2fd;
    border-color: var(--primary-color);
    color: var(--primary-hover);
}

.alert-warning {
    background-color: #fff3e0;
    border-color: #ff9800;
    color: #e65100;
}

.alert-success {
    background-color: #e8f5e8;
    border-color: var(--secondary-color);
    color: #2e7d32;
}

/* --- فوتر --- */
footer {
    background-color: var(--primary-color);
    padding: 1rem 0;
    box-shadow: 0 -2px 4px rgba(21, 101, 192, 0.1);
    color: var(--text-footer);
    margin-top: 2rem;
}

/* --- صفحه لاگین --- */
.login-container {
    max-width: 400px;
    margin: 3rem auto;
}

/* --- ریسپانسیو --- */
@media (max-width: 992px) {
    .card-container {
        max-width: 100%;
    }

    .document-header {
        flex-direction: column;
        gap: 1rem;
    }

    .document-actions {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    main {
        padding: 1.5rem 1rem;
    }

    .btn-primary {
        padding: 0.5rem 1.25rem;
    }

    .document-content {
        padding: 1.25rem;
    }

    .document-actions {
        flex-direction: column;
        width: 100%;
    }

    .document-actions .btn {
        width: 100%;
    }
}

@media (max-width: 576px) {
    main {
        padding: 1rem 0.75rem;
    }

    h3 {
        font-size: 1.3rem;
    }

    .document-title {
        font-size: 1.1rem;
    }

    .document-content {
        padding: 1rem;
        font-size: 0.9rem;
    }

    .prescription-type-card {
        margin-bottom: 0.5rem;
    }
}

/* --- انیمیشن‌ها --- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- دکمه کپی --- */
.copy-button {
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-speed) ease;
}

.copy-button svg {
    margin-left: 0.25rem;
    width: 16px;
    height: 16px;
}

/* --- نشانگر بارگذاری --- */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
    vertical-align: -0.125em;
}

/* --- استایل‌های اضافی --- */
.text-right {
    text-align: right !important;
}

.prescription-placeholder {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    background-color: #f8f9fa;
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius-md);
    font-weight: 300;
}

/* --- جداول نسخه --- */
.table-responsive {
    border-radius: var(--border-radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

/* --- چاپ نسخه --- */
@media print {
    body * {
        visibility: hidden;
    }

    .document-content,
    .document-content * {
        visibility: visible;
    }

    .document-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        padding: 0;
        margin: 0;
        border: none;
        box-shadow: none;
        background: white;
    }

    .document-header,
    .document-actions,
    .document-footer {
        display: none;
    }

    .table {
        border: 1px solid #000 !important;
    }

    .table th,
    .table td {
        border: 1px solid #000 !important;
    }
}