/* === TF Modal Overlay === */
.tf-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2000; /* מעל sidebar */
    display: none;
}

.tf-modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.tf-modal {
    position: relative !important;
    display: flex;
    flex-direction: column;

    background: var(--bg-card);
    color: var(--text-primary);
    width: 900px;
    max-width: 95vw;
    max-height: 90vh;

    margin: 0 !important;
    padding: 0 !important;

    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);

    overflow: hidden;
    animation: tfModalIn 0.25s ease-out;
    z-index: 100000;
}

.tf-modal-header,
.tf-modal-footer {
    padding: 16px 20px;
    background: var(--bg-surface);
    border-color: var(--border-color);
    z-index: 2;
    flex-shrink: 0;
}

.tf-modal-header {
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tf-modal-header h2,
.tf-modal-header .modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: var(--primary, #40e0d0);
}

.tf-modal-footer {
    border-top: 1px solid #eee;
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.tf-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Grid layout for form rows */
.tf-modal-body .grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

/* Mobile - single column */
@media (max-width: 768px) {
    .tf-modal-body .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Close button */
.tf-modal-header .popup-close,
.tf-modal-header .tf-modal-close {
    position: static;
    font-size: 22px;
    cursor: pointer;
    color: #666;
    margin-left: auto;
    margin-right: 0;
    padding: 0;
    background: none;
    border: none;
    line-height: 1;
    z-index: 100001;
    pointer-events: auto;
}

.tf-modal-header .popup-close:hover,
.tf-modal-header .tf-modal-close:hover {
    color: #333;
}

/* Form elements - Modern SaaS 2025 styling */
.tf-modal label {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 6px;
    font-weight: 500;
    display: block;
}

.tf-modal input,
.tf-modal select,
.tf-modal textarea,
.tf-modal .form-control,
.tf-modal .form-select {
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    padding: 10px 12px;
}

.tf-modal h2,
.tf-modal .modal-title {
    font-size: 18px;
    font-weight: 600;
}

.tf-modal .btn-primary {
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 500;
}

/* Form row - 2 columns on desktop, 1 on mobile */
.tf-modal-body .form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 0;
}

.tf-modal-body .form-row .form-group {
    margin-bottom: 0;
}

/* Mobile - single column */
@media (max-width: 768px) {
    .tf-modal-body .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }
    
    .tf-modal-body .form-row .form-group {
        margin-bottom: 1rem;
    }
}

/* Animation */
@keyframes tfModalIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Mobile */
@media (max-width: 640px) {
    .tf-modal {
        max-width: 95%;
        max-height: 90vh;
    }
    
    .tf-modal-header,
    .tf-modal-footer {
        padding: 12px 16px;
    }
    
    .tf-modal-body {
        padding: 16px;
    }
}

/* Mobile drawer behavior */
@media (max-width: 768px){
  .tf-modal-overlay{ align-items: flex-end !important; }
  .tf-modal{ width: 100% !important; max-width: none !important; border-radius: 16px 16px 0 0; }
}

/* === Form Grid Layout === */
.tf-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    align-items: start;
}

/* Ensure form-group doesn't override grid */
.tf-form-grid .form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
}

/* Form inputs/selects/textarea fill available width */
.tf-form-grid .form-group input,
.tf-form-grid .form-group select,
.tf-form-grid .form-group textarea {
    width: 100%;
    box-sizing: border-box;
}

/* Full-width fields (span both columns) */
.tf-form-grid .full-width {
    grid-column: 1 / -1;
}

/* Mobile - single column */
@media (max-width: 768px) {
    .tf-form-grid {
        grid-template-columns: 1fr;
    }
    
    .tf-form-grid .full-width {
        grid-column: 1;
    }
}

/* Legacy support - keep old classes working */
.tf-modal .popup-content {
    background: transparent;
    padding: 0;
    box-shadow: none;
    border-radius: 0;
    max-width: none;
    max-height: none;
    overflow: visible;
}

/* 🔥 Force TF Modal to ignore app layout */
.tf-modal-overlay,
.tf-modal {
    flex: none !important;
    grid-area: unset !important;
    float: none !important;
}

/* Modal inputs – dark aware */
[data-theme="dark"] .tf-modal input,
[data-theme="dark"] .tf-modal select,
[data-theme="dark"] .tf-modal textarea {
    background: var(--input-bg);
    color: var(--input-text);
    border-color: var(--input-border);
}

/* === TF Modal – Dark Mode === */
[data-theme="dark"] .tf-modal,
[data-theme="dark"] .tf-modal-content {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

[data-theme="dark"] .tf-modal-header,
[data-theme="dark"] .tf-modal-footer {
  background-color: var(--bg-surface);
  border-color: var(--border-color);
}

[data-theme="dark"] .tf-modal label,
[data-theme="dark"] .tf-modal .form-label {
  color: var(--text-secondary);
}

[data-theme="dark"] .tf-modal .form-control,
[data-theme="dark"] .tf-modal select,
[data-theme="dark"] .tf-modal textarea {
  background-color: var(--input-bg);
  color: var(--input-text);
  border-color: var(--input-border);
}

[data-theme="dark"] .tf-modal .form-control::placeholder {
  color: var(--text-muted);
}

/* === Reset Password Modal (login page) === */
.tf-modal-reset.hidden {
  display: none !important;
}

.tf-modal-reset {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tf-modal-reset-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
}

.tf-modal-reset-content {
  position: relative;
  background: #ffffff;
  border-radius: 16px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
  margin: 10vh auto;
  z-index: 2;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.tf-modal-reset-content.small {
  max-width: 380px;
}

.tf-modal-reset-title {
  margin-bottom: 8px;
  font-size: 20px;
}

.tf-modal-reset-subtitle {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 24px;
}

.tf-modal-reset-close {
  position: absolute;
  top: 12px;
  left: 12px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  color: #666;
}

.tf-modal-reset-content form label {
  display: block;
  margin-bottom: 6px;
}

.tf-modal-reset-content form input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 16px;
  box-sizing: border-box;
}

.tf-modal-reset-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #eee;
}

.tf-modal-reset-footer a {
  color: #0f766e;
  text-decoration: none;
}

/* =========================
   Dark mode – Modal (tf-modal only)
========================= */

[data-theme="dark"] .tf-modal {
  background: var(--bg-card);
  color: var(--text-primary);
}

body.dark .tf-modal-header {
  background: #1b1f23;
  border-bottom: 1px solid #2c3136;
}

body.dark .tf-modal-footer {
  background: #1b1f23;
  border-top: 1px solid #2c3136;
}

body.dark .tf-modal-header h2,
body.dark .tf-modal-header h3 {
  color: #ffffff;
}

/* ===== Treatment Details – Dark Mode ===== */

[data-theme="dark"] .treatment-details {
  background: var(--bg-card);
  color: var(--text-primary);
}

[data-theme="dark"] .treatment-details-row {
  color: var(--text-secondary);
}

[data-theme="dark"] .treatment-details-label {
  color: var(--text-muted);
}

[data-theme="dark"] .treatment-details .status-badge {
  background: rgba(31, 181, 168, 0.15);
  color: var(--accent-primary);
}

/* ===== Drawer Footer Buttons – Dark Mode ===== */

[data-theme="dark"] .tf-modal-footer .btn {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

[data-theme="dark"] .tf-modal-footer .btn:hover {
  background: var(--table-row-hover);
}

[data-theme="dark"] .tf-modal-footer .btn-primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}

[data-theme="dark"] .tf-modal-footer .btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* === Dynamic fields (message templates) === */
.dynamic-fields {
  margin-bottom: 8px;
}

.dynamic-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.dynamic-buttons button {
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}

.dynamic-buttons button:hover {
  background: var(--primary);
  color: #fff;
}

/* Drawer overlay base */
.tf-modal-overlay.tf-drawer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  background: rgba(0,0,0,0.35);
  transition: background 0.2s ease;
  align-items: stretch;
}

.tf-modal-overlay.tf-drawer.active {
  display: flex !important;
}

/* RTL: drawer on LEFT. LTR: drawer on RIGHT */
html[dir="rtl"] .tf-modal-overlay.tf-drawer.active { justify-content: flex-start; }
html[dir="ltr"] .tf-modal-overlay.tf-drawer.active { justify-content: flex-end; }

/* Drawer panel sizing */
.tf-modal-overlay.tf-drawer .tf-modal.tf-drawer-panel {
  width: min(560px, 92vw);
  height: 100vh;
  border-radius: 0;
}

/* Header / Footer spacing */
.tf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

.tf-modal-title { margin: 0; font-size: 18px; font-weight: 700; }
.tf-modal-close { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; }

.tf-modal-body { padding: 16px; overflow: auto; height: calc(100vh - 64px - 74px); }
.tf-modal-footer { padding: 12px 16px; border-top: 1px solid rgba(0,0,0,0.08); background: #fff; }

/* KPI layout */
.tp-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tp-kpi { border: 1px solid rgba(0,0,0,0.08); border-radius: 10px; padding: 12px; background: #fff; }
.tp-kpi-label { font-size: 12px; opacity: 0.7; margin-bottom: 6px; }
.tp-kpi-value { font-size: 18px; font-weight: 700; }

.tp-sep { border: 0; border-top: 1px solid rgba(0,0,0,0.08); margin: 16px 0; }

.tp-meta-row { display: flex; gap: 10px; padding: 6px 0; }
.tp-meta-label { width: 70px; opacity: 0.7; }
.tp-meta-value { font-weight: 600; }

.tp-section-title { margin: 0 0 10px; font-size: 14px; font-weight: 700; }
.tp-textarea { width: 100%; border-radius: 10px; border: 1px solid rgba(0,0,0,0.12); padding: 10px; direction: rtl; text-align: right; }

/* Sticky actions */
.tp-sticky-actions { display: flex; gap: 10px; justify-content: flex-start; }
html[dir="rtl"] .tp-sticky-actions { justify-content: flex-end; }

/* Button styles in drawer */
.tp-sticky-actions .btn {
  min-width: 100px;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tp-sticky-actions .btn-primary {
  background: var(--primary, #0f766e);
  color: white;
  border: 1px solid var(--primary, #0f766e);
}

.tp-sticky-actions .btn-primary:hover {
  background: var(--primary-dark, #0d5f57);
}

.tp-sticky-actions .btn-secondary {
  background: transparent;
  color: var(--text-primary, #333);
  border: 1px solid rgba(0,0,0,0.2);
}

.tp-sticky-actions .btn-secondary:hover {
  background: rgba(0,0,0,0.05);
}

.tp-sticky-actions .btn-danger {
  background: #dc2626;
  color: white;
  border: 1px solid #dc2626;
}

.tp-sticky-actions .btn-danger:hover {
  background: #b91c1c;
}

/* Dark mode support for drawer */
[data-theme="dark"] .tf-modal-overlay.tf-drawer {
  background: rgba(0,0,0,0.6);
}

[data-theme="dark"] .tf-modal-overlay.tf-drawer .tf-modal-header,
[data-theme="dark"] .tf-modal-overlay.tf-drawer .tf-modal-footer {
  background: var(--bg-surface);
  border-color: var(--border-color);
}

[data-theme="dark"] .tf-modal-overlay.tf-drawer .tp-kpi {
  background: var(--bg-surface);
  border-color: var(--border-color);
}

[data-theme="dark"] .tf-modal-overlay.tf-drawer .tp-textarea {
  background: var(--input-bg);
  color: var(--input-text);
  border-color: var(--input-border);
}

[data-theme="dark"] .tp-sticky-actions .btn-secondary {
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] .tp-sticky-actions .btn-secondary:hover {
  background: var(--table-row-hover);
}

/* === HARD RESET: Drawer must NOT translate in RTL === */

.tf-modal-overlay.tf-drawer .tf-modal {
    transform: none !important;
    right: 0 !important;
    left: auto !important;
}
