/* Reset & Variables */
:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-background: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f8fafc;
    --bg-input: #ffffff;
    --bg-hover: rgba(15, 118, 110, 0.05);
    --surface-base: #f8fafc;
    --surface-raised: #ffffff;
    --surface-overlay: rgba(255, 255, 255, 0.88);
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    --accent: #0f766e; /* Deep Teal */
    --accent-light: #ccfbf1;
    --accent-hover: #115e59;
    --primary: #0f766e;
    --primary-accent: #0d9488;
    --success: #10b981;
    --warning: #f59e0b;
    --destructive: #ef4444;
    
    --border-color: #e2e8f0;
    --border-subtle: rgba(148, 163, 184, 0.35);
    
    /* Status Colors */
    --color-success: #10b981; /* Emerald green */
    --color-success-bg: #d1fae5;
    
    --color-warning: #f59e0b; /* Amber/orange */
    --color-warning-bg: #fef3c7;
    
    --color-danger: #ef4444; /* Red */
    --color-danger-bg: #fee2e2;

    --color-info: #3b82f6; /* Blue */
    --color-info-bg: #dbeafe;

    /* Appointment Status Specific Colors (Optimized for High Contrast & Readability) */
    --status-pendiente-bg: #fffbeb;
    --status-pendiente-text: #92400e;
    --status-pendiente-border: #f59e0b;
    --status-pendiente-hover: #fef3c7;

    --status-confirmada-bg: #f0f9ff;
    --status-confirmada-text: #0369a1;
    --status-confirmada-border: #0ea5e9;
    --status-confirmada-hover: #e0f2fe;

    --status-completada-bg: #f0fdf4;
    --status-completada-text: #15803d;
    --status-completada-border: #22c55e;
    --status-completada-hover: #dcfce7;

    --status-cancelada-bg: #fef2f2;
    --status-cancelada-text: #991b1b;
    --status-cancelada-border: #ef4444;
    --status-cancelada-hover: #fee2e2;
    
    /* Layout */
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 10px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 20px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.1);
}

[data-theme="dark"] {
    --bg-primary: #0b0f19;
    --bg-secondary: #111827;
    --bg-card: #1e293b;
    --bg-background: #090d16;
    --bg-surface: #111827;
    --bg-surface-elevated: #1e293b;
    --bg-input: #0f172a;
    --bg-hover: rgba(20, 184, 166, 0.08);
    --surface-base: #0b0f19;
    --surface-raised: #111827;
    --surface-overlay: rgba(17, 24, 39, 0.88);
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    
    --accent: #14b8a6; /* Brighter Teal for Dark Mode */
    --accent-light: #115e59;
    --accent-hover: #2dd4bf;
    --primary: #14b8a6;
    --primary-accent: #2dd4bf;
    --success: #34d399;
    --warning: #fbbf24;
    --destructive: #f87171;
    
    --border-color: #1e293b;
    --border-subtle: rgba(51, 65, 85, 0.65);
    
    --color-success: #34d399;
    --color-success-bg: rgba(52, 211, 153, 0.15);
    
    --color-warning: #fbbf24;
    --color-warning-bg: rgba(251, 191, 36, 0.15);
    
    --color-danger: #f87171;
    --color-danger-bg: rgba(248, 113, 113, 0.15);

    --color-info: #60a5fa;
    --color-info-bg: rgba(96, 165, 250, 0.15);

    /* Appointment Status Specific Colors - Dark Mode (Vibrant & Crisp) */
    --status-pendiente-bg: rgba(245, 158, 11, 0.18);
    --status-pendiente-text: #fde047;
    --status-pendiente-border: rgba(251, 191, 36, 0.65);
    --status-pendiente-hover: rgba(245, 158, 11, 0.28);

    --status-confirmada-bg: rgba(14, 165, 233, 0.18);
    --status-confirmada-text: #38bdf8;
    --status-confirmada-border: rgba(56, 189, 248, 0.65);
    --status-confirmada-hover: rgba(14, 165, 233, 0.28);

    --status-completada-bg: rgba(34, 197, 94, 0.18);
    --status-completada-text: #4ade80;
    --status-completada-border: rgba(74, 222, 128, 0.65);
    --status-completada-hover: rgba(34, 197, 94, 0.28);

    --status-cancelada-bg: rgba(239, 68, 68, 0.18);
    --status-cancelada-text: #fca5a5;
    --status-cancelada-border: rgba(248, 113, 113, 0.65);
    --status-cancelada-hover: rgba(239, 68, 68, 0.28);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Scrollbar customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Login Page Styling */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1.5rem;
    background: radial-gradient(circle at 10% 20%, rgba(15, 118, 110, 0.15) 0%, transparent 40%), 
                radial-gradient(circle at 90% 80%, rgba(15, 118, 110, 0.12) 0%, transparent 40%),
                var(--bg-primary);
    transition: var(--transition);
}

.login-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 440px;
    padding: 2.5rem;
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    height: 4.5rem;
    width: auto;
    margin-bottom: 1rem;
    border-radius: var(--border-radius-sm);
    object-fit: contain;
}

.login-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
}

.login-header h2 span {
    color: var(--accent);
    font-weight: 300;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.login-error-msg {
    color: var(--color-danger);
    background-color: var(--color-danger-bg);
    border-radius: var(--border-radius-sm);
    padding: 0.65rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 1rem;
    border-left: 3px solid var(--color-danger);
}

/* App Layout Container */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-area h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.logo-area h1 span {
    color: var(--accent);
    font-weight: 300;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Base Centered Button System (Prevents overflow, broken baseline, & ensures true center) */
.btn,
.tab-btn,
.btn-toggle-view,
.btn-card-action,
.btn-icon-square,
.card-cita-btn,
.btn-chip,
.btn-tool,
.btn-tbl-action,
.btn-tbl-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
}

/* Ensure inline display: none and hidden utilities strictly take precedence */
[style*="display: none"],
[style*="display:none"],
.is-hidden {
    display: none !important;
}

.btn {
    gap: 0.45rem;
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon svg {
    width: 1.1rem;
    height: 1.1rem;
}

.btn-primary {
    background-color: var(--accent);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.btn-danger {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: transparent;
}

.btn-danger:hover {
    background-color: var(--color-danger);
    color: #ffffff;
}

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1.5px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    user-select: none;
    position: relative;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.stat-card:active {
    transform: scale(0.98);
}

.stat-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18), var(--shadow-sm);
    background: var(--bg-primary);
}

.stat-card.active::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--accent);
}

.stat-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 1.5rem;
    height: 1.5rem;
}

.icon-blue {
    background-color: var(--color-info-bg);
    color: var(--color-info);
}

.icon-green {
    background-color: var(--color-success-bg);
    color: var(--color-success);
}

.icon-yellow {
    background-color: var(--color-warning-bg);
    color: var(--color-warning);
}

.icon-red {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
}

.icon-teal {
    background-color: rgba(13, 148, 136, 0.12);
    color: #0d9488;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

/* Search Container */
.search-container {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 300px;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 1rem;
    width: 1.25rem;
    height: 1.25rem;
    color: var(--text-muted);
    pointer-events: none;
}

.search-wrapper input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.75rem;
    font-family: inherit;
    font-size: 0.95rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
}

.search-wrapper input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
}

.btn-clear {
    position: absolute;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    line-height: 1;
}

.btn-clear:hover {
    color: var(--text-primary);
}

.filter-wrapper {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.filter-wrapper label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.filter-wrapper select {
    padding: 0.65rem 1.75rem 0.65rem 1rem;
    font-family: inherit;
    font-size: 0.9rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
}

.filter-wrapper select:focus {
    border-color: var(--accent);
}

/* Patient Grid */
.patient-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 1.5rem;
    min-height: 250px;
}

/* Patient Card */
.patient-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition);
}

.patient-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
}

.card-header {
    padding: 1.25rem 1.25rem 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.card-title-group {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.card-name {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.card-ficha-badge {
    align-self: flex-start;
    background-color: var(--accent-light);
    color: var(--accent-hover);
    padding: 0.15rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
@media (prefers-color-scheme: dark) {
    .card-ficha-badge {
        background-color: rgba(20, 184, 166, 0.2);
        color: #2dd4bf;
    }
}

.card-status-dot {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    margin-top: 0.4rem;
}

.card-status-dot.al-dia { background-color: var(--color-success); box-shadow: 0 0 8px var(--color-success); }
.card-status-dot.proximamente { background-color: var(--color-warning); box-shadow: 0 0 8px var(--color-warning); }
.card-status-dot.vencido { background-color: var(--color-danger); box-shadow: 0 0 8px var(--color-danger); }

.card-body {
    padding: 0 1.25rem 1.25rem 1.25rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.info-row svg {
    width: 1rem;
    height: 1rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.info-row a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
}

.info-row a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.card-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0;
}

.control-status-container {
    background: var(--bg-primary);
    border-radius: var(--border-radius-sm);
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.control-status-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.35rem;
}

.control-dates {
    display: flex;
    justify-content: space-between;
    font-size: 0.825rem;
    font-weight: 500;
}

.date-block {
    display: flex;
    flex-direction: column;
}

.date-block span:first-child {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.status-indicator-badge {
    align-self: center;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-indicator-badge.al-dia { background-color: var(--color-success-bg); color: var(--color-success); }
.status-indicator-badge.proximamente { background-color: var(--color-warning-bg); color: var(--color-warning); }
.status-indicator-badge.vencido { background-color: var(--color-danger-bg); color: var(--color-danger); }

.card-footer {
    background: var(--bg-primary);
    padding: 0.65rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    gap: 0.5rem;
    flex-wrap: wrap;
}

.footer-actions-left {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-card-action {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--surface-raised);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-card-action:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.btn-card-action.btn-edit:hover {
    background-color: rgba(2, 132, 199, 0.12);
    color: #0284c7;
    border-color: rgba(2, 132, 199, 0.35);
}

.btn-card-action.btn-delete:hover {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: rgba(239, 68, 68, 0.35);
}

.btn-card-action.btn-whatsapp {
    color: #16a34a;
    border-color: rgba(22, 163, 74, 0.25);
    background: rgba(22, 163, 74, 0.06);
}

.btn-card-action.btn-whatsapp:hover {
    background-color: rgba(22, 163, 74, 0.18);
    color: #15803d;
    border-color: rgba(22, 163, 74, 0.45);
}

.btn-card-action svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.card-cita-btn {
    height: 34px;
    padding: 0 0.7rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--accent);
    background-color: rgba(15, 118, 110, 0.08);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 600;
    gap: 0.35rem;
    cursor: pointer;
    transition: var(--transition);
}

.card-cita-btn:hover {
    background-color: var(--accent);
    color: #ffffff;
}

.card-footer .btn-primary {
    height: 34px;
    padding: 0 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
}

/* Table View Actions Uniformity */
.btn-tbl-action {
    height: 30px !important;
    padding: 0 0.65rem !important;
    font-size: 0.76rem !important;
}

.btn-tbl-icon {
    width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 5rem 2rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 2px dashed var(--border-color);
}

.empty-icon {
    width: 4rem;
    height: 4rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.empty-state p {
    color: var(--text-muted);
    max-width: 400px;
}

/* Modals / Dialogs */
.modal-dialog {
    border: none;
    border-radius: var(--border-radius);
    padding: 0;
    max-width: 600px;
    width: calc(100% - 2rem);
    margin: auto;
    box-shadow: var(--shadow-xl);
    background-color: var(--bg-card);
    color: var(--text-primary);
}

.modal-dialog::backdrop {
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    transition: var(--transition);
}

.modal-content {
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.btn-close:hover {
    color: var(--text-primary);
}

.modal-content form {
    padding: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.col-span-2 {
    grid-column: span 2;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input, 
.form-group textarea, 
.form-group select {
    padding: 0.65rem 0.85rem;
    font-family: inherit;
    font-size: 0.9rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
}

.form-group input:focus, 
.form-group textarea:focus, 
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
}

.form-help {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

/* Treatment Table Styling */
.treatment-table th {
    font-weight: 600;
    color: var(--text-secondary);
}

.treatment-table td, 
.treatment-table th {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.treatment-table tbody tr:hover {
    background-color: var(--bg-primary);
}

/* Animations & Responsive */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.patient-card {
    animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .col-span-2 {
        grid-column: span 1;
    }
    .app-header {
        flex-direction: column;
        align-items: stretch;
    }
    .header-main-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .header-primary-actions {
        flex-wrap: wrap;
        width: 100%;
        justify-content: flex-start;
        gap: 0.5rem;
    }
    .header-tools-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .header-tools-cluster {
        flex-wrap: wrap;
        width: 100%;
        gap: 0.4rem;
    }
}

/* User Management Layout Styles */
.user-layout {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
}
.users-list-container {
    border-right: 1px solid var(--border-color);
    padding-right: 1rem;
    max-height: 350px;
    display: flex;
    flex-direction: column;
}
@media (max-width: 640px) {
    .user-layout {
        grid-template-columns: 1fr;
    }
    .users-list-container {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-right: 0;
        padding-bottom: 1.5rem;
    }
}

/* ==========================================
   NAVIGATION TABS & AGENDA MODULE STYLING
   ========================================== */

.views-navigation-container {
    max-width: 1400px;
    margin: 0 auto 1.5rem auto;
    padding: 0 1.5rem;
}

.main-tabs {
    display: inline-flex;
    background-color: var(--bg-secondary);
    padding: 0.35rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    gap: 0.35rem;
    box-shadow: var(--shadow-sm);
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: calc(var(--border-radius) - 4px);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

.tab-btn.active {
    background-color: var(--accent);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

.tab-btn.active .tab-icon {
    stroke: #ffffff;
}

.tab-icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    transition: var(--transition);
}

.tab-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 12px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
}

.tab-btn.active .tab-badge {
    background-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.stat-icon.icon-teal {
    background-color: rgba(15, 118, 110, 0.15);
    color: var(--accent);
}

/* Agenda Toolbar */
.agenda-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    background-color: var(--bg-secondary);
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.agenda-date-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

.btn-chip {
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-chip:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.btn-chip.active {
    background-color: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 2px 4px rgba(15, 118, 110, 0.25);
}

.date-input-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 0.4rem;
}

.date-input-wrapper .date-icon {
    position: absolute;
    left: 0.65rem;
    width: 15px;
    height: 15px;
    color: var(--text-muted);
    pointer-events: none;
}

.date-input-wrapper input[type="date"] {
    padding: 0.4rem 0.75rem 0.4rem 2rem;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}

.date-input-wrapper input[type="date"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.2);
}

.agenda-actions-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

/* Agenda Header Banner */
.agenda-header-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.agenda-banner-info h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.agenda-banner-info p {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* Citas List & Cards */
.citas-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.cita-card {
    display: grid;
    grid-template-columns: 130px 1fr auto;
    gap: 1.25rem;
    align-items: center;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.cita-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* Status Border Colors & Accents */
.cita-card.status-pendiente {
    border-left-color: var(--status-pendiente-border);
}
.cita-card.status-confirmada {
    border-left-color: var(--status-confirmada-border);
}
.cita-card.status-completada {
    border-left-color: var(--status-completada-border);
}
.cita-card.status-cancelada {
    border-left-color: var(--status-cancelada-border);
    opacity: 0.85;
}

[data-theme="dark"] .cita-card.status-pendiente {
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.08) 0%, var(--bg-card) 22%);
}
[data-theme="dark"] .cita-card.status-confirmada {
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.08) 0%, var(--bg-card) 22%);
}
[data-theme="dark"] .cita-card.status-completada {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.08) 0%, var(--bg-card) 22%);
}
[data-theme="dark"] .cita-card.status-cancelada {
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.08) 0%, var(--bg-card) 22%);
    opacity: 0.8;
}

/* Cita Time Block */
.cita-time-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem;
    background-color: var(--bg-primary);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    text-align: center;
}

.cita-time-main {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.cita-duration-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.cita-date-sub {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    margin-top: 0.35rem;
    text-transform: capitalize;
}

/* Cita Main Block */
.cita-main-block {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cita-patient-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.cita-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cita-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cita-avatar-placeholder {
    width: 22px;
    height: 22px;
    color: var(--text-muted);
}

.cita-patient-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.cita-patient-name:hover {
    color: var(--accent);
    text-decoration: underline;
}

.cita-badge-ficha {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    background-color: var(--accent-light);
    color: var(--accent);
}

[data-theme="dark"] .cita-badge-ficha {
    background-color: rgba(20, 184, 166, 0.2);
    color: #2dd4bf;
}

.cita-motivo-tag {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.cita-doctor-tag {
    font-size: 0.82rem;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.cita-notas-box {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-style: italic;
    background: var(--bg-primary);
    padding: 0.4rem 0.75rem;
    border-radius: var(--border-radius-sm);
    border-left: 2px solid var(--border-color);
    margin-top: 0.2rem;
}

.cita-contact-links {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.2rem;
}

.btn-contact-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.25rem 0.55rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    transition: var(--transition);
}

.btn-contact-link:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.btn-contact-link.whatsapp:hover {
    color: #10b981;
    border-color: #10b981;
    background-color: rgba(16, 185, 129, 0.08);
}

/* Cita Actions Block */
.cita-actions-block {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
}

.cita-status-select {
    display: inline-flex;
    align-items: center;
    padding: 0.42rem 1.85rem 0.42rem 0.85rem;
    font-size: 0.83rem;
    font-weight: 700;
    letter-spacing: 0.015em;
    border-radius: 9999px;
    border: 1.5px solid transparent;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 11px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.cita-status-select:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.12);
}

.cita-status-select:focus {
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.28);
}

/* Ensure the native options list is ALWAYS high-contrast and completely legible across all browsers/themes */
.cita-status-select option,
#citaEstado option,
#filterCitasStatus option {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
}

/* Status variants */
.cita-status-select.status-pendiente {
    background-color: var(--status-pendiente-bg);
    color: var(--status-pendiente-text);
    border-color: var(--status-pendiente-border);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2392400e' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}
.cita-status-select.status-pendiente:hover {
    background-color: var(--status-pendiente-hover);
}
[data-theme="dark"] .cita-status-select.status-pendiente {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23fde047' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.15);
}

.cita-status-select.status-confirmada {
    background-color: var(--status-confirmada-bg);
    color: var(--status-confirmada-text);
    border-color: var(--status-confirmada-border);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%230369a1' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}
.cita-status-select.status-confirmada:hover {
    background-color: var(--status-confirmada-hover);
}
[data-theme="dark"] .cita-status-select.status-confirmada {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2338bdf8' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    box-shadow: 0 0 10px rgba(14, 165, 233, 0.15);
}

.cita-status-select.status-completada {
    background-color: var(--status-completada-bg);
    color: var(--status-completada-text);
    border-color: var(--status-completada-border);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2315803d' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}
.cita-status-select.status-completada:hover {
    background-color: var(--status-completada-hover);
}
[data-theme="dark"] .cita-status-select.status-completada {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%234ade80' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.15);
}

.cita-status-select.status-cancelada {
    background-color: var(--status-cancelada-bg);
    color: var(--status-cancelada-text);
    border-color: var(--status-cancelada-border);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23991b1b' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}
.cita-status-select.status-cancelada:hover {
    background-color: var(--status-cancelada-hover);
}
[data-theme="dark"] .cita-status-select.status-cancelada {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23fca5a5' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.15);
}

/* Compact variant for tables */
.cita-status-select.cita-status-sm {
    padding: 0.25rem 1.5rem 0.25rem 0.65rem;
    font-size: 0.78rem;
    background-position: right 0.45rem center;
    background-size: 9px;
}

.cita-action-buttons {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-icon-square {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon-square:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
    background-color: var(--bg-secondary);
}

.btn-icon-square.danger:hover {
    color: var(--color-danger);
    border-color: var(--color-danger);
    background-color: var(--color-danger-bg);
}

/* Patient Dialog Quick Cita Button on cards */
.card-cita-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.35rem 0.7rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--accent);
    background-color: transparent;
    color: var(--accent);
    cursor: pointer;
    transition: var(--transition);
}

.card-cita-btn:hover {
    background-color: var(--accent);
    color: #ffffff;
}

/* Responsive Agenda */
@media (max-width: 860px) {
    .cita-card {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .cita-time-block {
        flex-direction: row;
        justify-content: space-between;
        padding: 0.6rem 1rem;
    }
    .cita-actions-block {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        border-top: 1px solid var(--border-color);
        padding-top: 0.75rem;
    }
}

/* =========================================
   Searchable Combobox Component (Patient Picker)
   ========================================= */
.combobox-wrapper {
    position: relative;
    width: 100%;
}

.combobox-input-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.combobox-icon-search {
    position: absolute;
    left: 0.85rem;
    width: 1.1rem;
    height: 1.1rem;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 2;
}

.combobox-input {
    width: 100%;
    padding: 0.65rem 4.5rem 0.65rem 2.4rem !important;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    transition: var(--transition);
}

.combobox-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-clear-combobox {
    position: absolute;
    right: 2.3rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.35rem;
    line-height: 1;
    z-index: 2;
}

.btn-clear-combobox:hover {
    color: var(--color-danger);
}

.btn-toggle-combobox {
    position: absolute;
    right: 0.35rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    z-index: 2;
}

.btn-toggle-combobox svg {
    width: 1.1rem;
    height: 1.1rem;
    transition: transform 0.2s ease;
}

.btn-toggle-combobox:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.combobox-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 230px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    padding: 0.35rem 0;
}

.combobox-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.combobox-item:last-child {
    border-bottom: none;
}

.combobox-item:hover,
.combobox-item.highlighted {
    background-color: var(--bg-primary);
}

.combobox-item.selected {
    background-color: rgba(37, 99, 235, 0.08);
    border-left: 3px solid var(--accent);
}

.combobox-item-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
}

.combobox-item-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.combobox-item-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.combobox-item-name {
    font-size: 0.92rem;
    color: var(--text-primary);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.combobox-item-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.combobox-item-ficha {
    background: rgba(37, 99, 235, 0.1);
    color: var(--accent);
    font-weight: 700;
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.combobox-empty {
    padding: 0.85rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* =========================================
   View Mode Toggle (List vs Calendar)
   ========================================= */
.view-mode-toggle {
    display: inline-flex;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 2px;
    gap: 2px;
}

.btn-toggle-view {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.8rem;
    font-size: 0.84rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-toggle-view:hover {
    color: var(--text-primary);
}

.btn-toggle-view.active {
    background-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* =========================================
   Calendar View Module
   ========================================= */
.calendar-wrapper {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-top: 0.5rem;
}

.calendar-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
    background-color: var(--bg-secondary);
}

.calendar-nav-controls {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.calendar-month-title h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: capitalize;
    margin: 0;
}

.calendar-legend {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.legend-dot.status-pendiente {
    background-color: var(--status-pendiente-border);
    box-shadow: 0 0 6px var(--status-pendiente-border);
}

.legend-dot.status-confirmada {
    background-color: var(--status-confirmada-border);
    box-shadow: 0 0 6px var(--status-confirmada-border);
}

.legend-dot.status-completada {
    background-color: var(--status-completada-border);
    box-shadow: 0 0 6px var(--status-completada-border);
}

.legend-dot.status-cancelada {
    background-color: var(--status-cancelada-border);
    box-shadow: 0 0 6px var(--status-cancelada-border);
}

.calendar-grid-container {
    padding: 1rem 1.25rem 1.25rem 1.25rem;
}

.calendar-weekdays-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    padding: 0.6rem 0;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-top-left-radius: var(--border-radius-sm);
    border-top-right-radius: var(--border-radius-sm);
}

.calendar-days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background-color: var(--border-color);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: var(--border-radius-sm);
    border-bottom-right-radius: var(--border-radius-sm);
    overflow: hidden;
}

.calendar-day-cell {
    background-color: var(--bg-primary);
    min-height: 110px;
    padding: 0.45rem;
    display: flex;
    flex-direction: column;
    transition: background-color 0.15s ease;
    cursor: pointer;
    position: relative;
}

.calendar-day-cell:hover {
    background-color: var(--bg-secondary);
}

.calendar-day-cell.other-month {
    background-color: rgba(0, 0, 0, 0.02);
    opacity: 0.45;
}

.calendar-day-cell.is-today {
    background-color: rgba(37, 99, 235, 0.04);
}

.day-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.day-number {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.calendar-day-cell.is-today .day-number {
    background-color: var(--accent);
    color: #ffffff;
    font-weight: 700;
}

.day-citas-badge {
    font-size: 0.68rem;
    font-weight: 700;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 0.05rem 0.35rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.cal-citas-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    overflow-y: auto;
    max-height: 80px;
}

.cal-cita-pill {
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: transform 0.1s ease, filter 0.1s ease;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cal-cita-pill:hover {
    transform: scale(1.02);
    filter: brightness(0.95);
}

.cal-cita-pill.status-pendiente {
    background-color: var(--status-pendiente-bg);
    color: var(--status-pendiente-text);
    border-left: 3.5px solid var(--status-pendiente-border);
    font-weight: 700;
}

.cal-cita-pill.status-confirmada {
    background-color: var(--status-confirmada-bg);
    color: var(--status-confirmada-text);
    border-left: 3.5px solid var(--status-confirmada-border);
    font-weight: 700;
}

.cal-cita-pill.status-completada {
    background-color: var(--status-completada-bg);
    color: var(--status-completada-text);
    border-left: 3.5px solid var(--status-completada-border);
    font-weight: 700;
}

.cal-cita-pill.status-cancelada {
    background-color: var(--status-cancelada-bg);
    color: var(--status-cancelada-text);
    border-left: 3.5px solid var(--status-cancelada-border);
    text-decoration: line-through;
    opacity: 0.85;
    font-weight: 700;
}

.cal-cita-time {
    font-size: 0.67rem;
    opacity: 0.85;
    flex-shrink: 0;
}

.cal-cita-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .calendar-header-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    .calendar-day-cell {
        min-height: 70px;
        padding: 0.25rem;
    }
    .cal-cita-pill {
        font-size: 0.65rem;
        padding: 0.15rem 0.3rem;
    }
}

/* ==========================================
   Modern Toast Notification System
   ========================================== */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 420px;
    width: calc(100% - 3rem);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 0.9rem 1.25rem;
    border-radius: var(--border-radius);
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-xl);
    border-left: 5px solid var(--accent);
    font-size: 0.95rem;
    line-height: 1.45;
    opacity: 0;
    transform: translateX(50px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.hide {
    opacity: 0;
    transform: translateY(-20px);
}

.toast-icon {
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 0.15rem;
}

.toast-content {
    flex: 1;
    word-break: break-word;
}

.toast-close {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.25rem;
    line-height: 1;
    padding: 0 0 0 0.5rem;
    transition: color 0.15s ease;
}

.toast-close:hover {
    color: var(--text-primary);
}

.toast-success {
    border-left-color: var(--color-success);
}
.toast-success .toast-icon {
    color: var(--color-success);
}

.toast-error {
    border-left-color: var(--color-danger);
}
.toast-error .toast-icon {
    color: var(--color-danger);
}

.toast-warning {
    border-left-color: var(--color-warning);
}
.toast-warning .toast-icon {
    color: var(--color-warning);
}

.toast-info {
    border-left-color: var(--color-info);
}
.toast-info .toast-icon {
    color: var(--color-info);
}

/* ==========================================
   FASE 2: ALERTAS MÉDICAS, WHATSAPP & IMPRESIÓN
   ========================================== */

/* Allergy Quick Pill Buttons in Patient Modal */
.btn-pill-allergy {
    background: var(--bg-primary);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: var(--color-danger);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.btn-pill-allergy:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--color-danger);
    transform: translateY(-1px);
}

.btn-pill-allergy.active {
    background: var(--color-danger);
    color: #ffffff;
    border-color: var(--color-danger);
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

/* Card Allergy Badge */
.card-allergy-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 9999px;
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.3);
    margin-top: 0.35rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* WhatsApp Reminder Buttons */
.btn-whatsapp-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #25D366;
    color: #ffffff !important;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.4rem 0.75rem;
    border-radius: var(--border-radius-sm);
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(37, 211, 102, 0.25);
}

.btn-whatsapp-action:hover {
    background: #20ba59;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 211, 102, 0.35);
}

.btn-whatsapp-action svg {
    flex-shrink: 0;
}

.btn-whatsapp-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.76rem;
    border-radius: 4px;
}

/* WhatsApp Button Group with Dropdown Trigger */
.whatsapp-btn-group {
    display: inline-flex;
    align-items: stretch;
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(37, 211, 102, 0.25);
}

.whatsapp-btn-group .btn-whatsapp-action {
    border-radius: 0;
    box-shadow: none;
}

.whatsapp-btn-group .btn-whatsapp-options-trigger {
    padding: 0.4rem 0.55rem;
    background: #1ebe5d;
    border-left: 1px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    transition: background 0.2s ease;
}

.whatsapp-btn-group .btn-whatsapp-options-trigger:hover {
    background: #179b4b;
}

/* WhatsApp Template Selector Pills */
.btn-pill-template {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.btn-pill-template:hover {
    background: rgba(37, 211, 102, 0.12);
    border-color: #25D366;
    color: #128C7E;
}

.btn-pill-template.active {
    background: #25D366;
    color: #ffffff;
    border-color: #25D366;
    box-shadow: 0 2px 4px rgba(37, 211, 102, 0.3);
}

/* Interactive Toast Action Button */
.btn-toast-action {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.45rem;
    background: #25D366;
    color: #ffffff;
    border: none;
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.btn-toast-action:hover {
    background: #20ba59;
    transform: translateY(-1px);
}

/* ========================================================
   PRINT STYLES: Presupuestos, Recetas y Ficha Clínica
   ======================================================== */
@media print {
    @page {
        size: letter portrait;
        margin: 12mm 15mm;
    }

    html, body {
        background: #ffffff !important;
        background-color: #ffffff !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* Universal no-print utility */
    .no-print,
    .no-print * {
        display: none !important;
    }

    /* ----------------------------------------------------
       CASE 1: PRINTING DENTAL BUDGET / COTIZACIÓN
       ---------------------------------------------------- */
    body[data-print-target="budget"] > *:not(#printBudgetDialog),
    body:has(#printBudgetDialog[open]) > *:not(#printBudgetDialog) {
        display: none !important;
    }

    body[data-print-target="budget"] #printBudgetDialog,
    body:has(#printBudgetDialog[open]) #printBudgetDialog {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: #ffffff !important;
        background-color: #ffffff !important;
        box-shadow: none !important;
        inset: auto !important;
        overflow: visible !important;
    }

    body[data-print-target="budget"] #printBudgetDialog::backdrop,
    body:has(#printBudgetDialog[open]) #printBudgetDialog::backdrop {
        display: none !important;
    }

    body[data-print-target="budget"] #printBudgetDialog .modal-content,
    body:has(#printBudgetDialog[open]) #printBudgetDialog .modal-content {
        display: block !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    body[data-print-target="budget"] #printBudgetSheet,
    body:has(#printBudgetDialog[open]) #printBudgetSheet {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: #ffffff !important;
        color: #000000 !important;
    }

    /* ----------------------------------------------------
       CASE 2: PRINTING MEDICAL PRESCRIPTION / RECETA
       ---------------------------------------------------- */
    body[data-print-target="prescription"] > *:not(#printPrescriptionDialog),
    body:has(#printPrescriptionDialog[open]) > *:not(#printPrescriptionDialog) {
        display: none !important;
    }

    body[data-print-target="prescription"] #printPrescriptionDialog,
    body:has(#printPrescriptionDialog[open]) #printPrescriptionDialog {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: #ffffff !important;
        background-color: #ffffff !important;
        box-shadow: none !important;
        inset: auto !important;
        overflow: visible !important;
    }

    body[data-print-target="prescription"] #printPrescriptionDialog::backdrop,
    body:has(#printPrescriptionDialog[open]) #printPrescriptionDialog::backdrop {
        display: none !important;
    }

    body[data-print-target="prescription"] #printPrescriptionDialog .modal-content,
    body:has(#printPrescriptionDialog[open]) #printPrescriptionDialog .modal-content {
        display: block !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    body[data-print-target="prescription"] #printPrescriptionSheet,
    body:has(#printPrescriptionDialog[open]) #printPrescriptionSheet {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: #ffffff !important;
        color: #000000 !important;
    }

    /* ----------------------------------------------------
       CASE 3: PRINTING CLINICAL HISTORY / FICHA CLÍNICA
       ---------------------------------------------------- */
    body[data-print-target="clinical"] > *:not(#clinicalDialog),
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])):not(:has(#printReportDialog[open])) > *:not(#clinicalDialog) {
        display: none !important;
    }

    body[data-print-target="clinical"] #clinicalDialog,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])):not(:has(#printReportDialog[open])) #clinicalDialog {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: #ffffff !important;
        background-color: #ffffff !important;
        box-shadow: none !important;
        inset: auto !important;
        overflow: visible !important;
    }

    body[data-print-target="clinical"] #clinicalDialog::backdrop,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])):not(:has(#printReportDialog[open])) #clinicalDialog::backdrop {
        display: none !important;
    }

    /* ----------------------------------------------------
       CASE 4: PRINTING REPORT / REPORTE GERENCIAL
       ---------------------------------------------------- */
    body[data-print-target="report"] > *:not(#printReportDialog),
    body:has(#printReportDialog[open]) > *:not(#printReportDialog) {
        display: none !important;
    }

    body[data-print-target="report"] #printReportDialog,
    body:has(#printReportDialog[open]) #printReportDialog {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: #ffffff !important;
        background-color: #ffffff !important;
        box-shadow: none !important;
        inset: auto !important;
        overflow: visible !important;
    }

    body[data-print-target="report"] #printReportDialog::backdrop,
    body:has(#printReportDialog[open]) #printReportDialog::backdrop {
        display: none !important;
    }

    body[data-print-target="report"] #printReportDialog .modal-content,
    body:has(#printReportDialog[open]) #printReportDialog .modal-content {
        display: block !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    body[data-print-target="report"] #printReportSheet,
    body:has(#printReportDialog[open]) #printReportSheet {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: #ffffff !important;
        color: #000000 !important;
    }

    body[data-print-target="clinical"] .clinical-tabs-nav,
    body[data-print-target="clinical"] .add-treatment-section,
    body[data-print-target="clinical"] .modal-footer,
    body[data-print-target="clinical"] .modal-header .btn-close,
    body[data-print-target="clinical"] .btn-card-action,
    body[data-print-target="clinical"] .btn-pill-allergy,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .clinical-tabs-nav,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .add-treatment-section,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .modal-footer,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .modal-header .btn-close,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .btn-card-action,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .btn-pill-allergy {
        display: none !important;
    }

    body[data-print-target="clinical"] .modal-content,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .modal-content {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
    }

    body[data-print-target="clinical"] .modal-body-scrollable,
    body:has(#clinicalDialog[open]):not(:has(#printBudgetDialog[open])):not(:has(#printPrescriptionDialog[open])) .modal-body-scrollable {
        max-height: none !important;
        overflow: visible !important;
        padding: 0 !important;
    }

    .treatment-table {
        border: 1px solid #000000 !important;
        width: 100% !important;
    }

    .treatment-table th,
    .treatment-table td {
        border-color: #333333 !important;
        color: #000000 !important;
    }

    .print-only-header {
        display: block !important;
        margin-bottom: 1.5rem;
        border-bottom: 2px solid #000000;
        padding-bottom: 0.75rem;
    }

    .print-signature-area {
        display: flex !important;
        justify-content: space-between;
        margin-top: 3rem;
        padding-top: 1rem;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    /* ----------------------------------------------------
       DEFAULT FALLBACK HIDING
       ---------------------------------------------------- */
    .app-header,
    .stats-bar,
    .search-container,
    .tab-navigation,
    .toast-container,
    .cita-actions-block,
    .cita-contact-links,
    .modal-dialog:not([open]) {
        display: none !important;
    }

    /* Common pagination & break protections */
    tr {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .print-signatures-row {
        margin-top: 2.5rem !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }
}

/* Loading Spinners & Anti-Double-Submit UX */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

.btn:disabled,
button:disabled {
    opacity: 0.65;
    cursor: not-allowed !important;
    pointer-events: none;
}

.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.8;
}

/* ==========================================
   CLINICAL TABS NAVIGATION
   ========================================== */
.clinical-tabs-nav {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1.25rem;
    overflow-x: auto;
    padding-bottom: 2px;
}

.clinical-tab-btn {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 0.65rem 1.1rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.clinical-tab-btn:hover {
    color: var(--accent);
    background: rgba(37, 99, 235, 0.05);
}

.clinical-tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(37, 99, 235, 0.08);
}

.clinical-tab-pane {
    display: none;
}

.clinical-tab-pane.active {
    display: block;
    animation: fadeInTab 0.2s ease;
}

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

/* ==========================================
   ODONTOGRAMA STYLES
   ========================================== */
.odontogram-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.odontogram-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.palette-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 4px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.palette-btn:hover {
    border-color: var(--accent);
}

.palette-btn.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--accent);
    transform: translateY(-1px);
}

.palette-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
    display: inline-block;
}

.odontogram-board {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 1rem 0.5rem;
    overflow-x: auto;
}

.odontogram-arch {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1.25rem;
    position: relative;
}

.odontogram-quadrant {
    display: flex;
    gap: 0.35rem;
}

.tooth-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    user-select: none;
}

.tooth-number {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.tooth-svg-box {
    width: 36px;
    height: 36px;
    position: relative;
    cursor: pointer;
}

.tooth-svg-box svg {
    width: 100%;
    height: 100%;
}

.tooth-surface {
    fill: #ffffff;
    stroke: #64748b;
    stroke-width: 1.2;
    transition: fill 0.15s ease;
    cursor: pointer;
}

.tooth-surface:hover {
    opacity: 0.8;
}

/* Surface condition colors */
.surface-sano { fill: #ffffff !important; }
.surface-caries { fill: #ef4444 !important; }
.surface-obturado { fill: #3b82f6 !important; }
.surface-corona { fill: #f59e0b !important; }
.surface-endodoncia { fill: #8b5cf6 !important; }

/* Whole tooth states */
.tooth-item.state-ausente .tooth-svg-box::after {
    content: "✕";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 26px;
    color: #ef4444;
    font-weight: bold;
    pointer-events: none;
}

.tooth-item.state-implante .tooth-svg-box::after {
    content: "🔩";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    pointer-events: none;
}

.tooth-item.state-corona .tooth-surface {
    stroke: #d97706 !important;
    stroke-width: 2 !important;
}

/* ==========================================
   RECETAS MEDICAS & PRESCRIPTIONS
   ========================================== */
.prescriptions-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.prescription-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 1rem 1.25rem;
    transition: box-shadow 0.2s ease;
}

.prescription-card:hover {
    box-shadow: var(--shadow-md);
}

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

.prescription-meds-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
    margin-bottom: 0.6rem;
}

.prescription-meds-table th,
.prescription-meds-table td {
    padding: 0.45rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.prescription-meds-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
}

/* Printable Prescription, Budget & Report Sheet Modals */
#printPrescriptionSheet,
#printBudgetSheet,
#printReportSheet {
    background: #ffffff !important;
    color: #000000 !important;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding: 2.25rem;
    max-width: 840px;
    margin: 0 auto;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

/* ========================================================
   USER PERMISSIONS & MODULE ACCESS CONTROL STYLES
   ======================================================== */
.user-permissions-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.75rem 0.85rem;
}

.permissions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
}

@media (max-width: 680px) {
    .permissions-grid {
        grid-template-columns: 1fr;
    }
}

.perm-checkbox-card {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-block-size: 44px;
    padding: 0.4rem 0.65rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
    user-select: none;
}

.perm-checkbox-card:hover {
    border-color: var(--primary);
}

.perm-checkbox-card:has(.perm-checkbox:checked) {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.06);
}

.perm-checkbox-card:has(.perm-checkbox:disabled) {
    opacity: 0.65;
    cursor: not-allowed;
}

.perm-checkbox {
    accent-color: var(--primary);
    inline-size: 1.15em;
    aspect-ratio: 1;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.perm-checkbox:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.perm-checkbox:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.perm-title {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.perm-desc {
    display: block;
    font-size: 0.71rem;
    color: var(--text-muted);
    line-height: 1.2;
    margin-top: 0.1rem;
}

.btn-link-sm {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.btn-link-sm:hover {
    text-decoration: underline;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.12rem 0.5rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.role-badge-admin {
    background: rgba(139, 92, 246, 0.15);
    color: #7c3aed;
    border: 1px solid rgba(139, 92, 246, 0.35);
}

.role-badge-doctor {
    background: rgba(37, 99, 235, 0.14);
    color: #2563eb;
    border: 1px solid rgba(37, 99, 235, 0.3);
}

.role-badge-recepcion {
    background: rgba(16, 185, 129, 0.14);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.role-badge-lectura {
    background: rgba(245, 158, 11, 0.15);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.role-badge-user {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.user-perm-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.3rem;
}

.user-perm-chip {
    font-size: 0.68rem;
    font-weight: 500;
    padding: 0.1rem 0.42rem;
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.user-perm-chip.perm-chip-config {
    background: rgba(99, 102, 241, 0.12);
    color: #4f46e5;
    border: 1px solid rgba(99, 102, 241, 0.35);
    font-weight: 600;
}

.user-perm-chip.perm-chip-action {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.3);
    font-weight: 600;
}

.user-perm-chip.perm-chip-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.3);
    font-weight: 600;
}

/* Global UI enforcement classes based on user permissions */
body.perm-no-eliminar .btn-delete,
body.perm-no-eliminar [onclick*="deletePatient"],
body.perm-no-eliminar [onclick*="deleteTreatmentRow"],
body.perm-no-eliminar [onclick*="deleteAppointment"],
body.perm-no-eliminar [onclick*="deletePrescription"],
body.perm-no-eliminar [onclick*="deleteDoctor"] {
    display: none !important;
}

body.perm-no-editar #btnNewPatient,
body.perm-no-editar #btnNewAppointment,
body.perm-no-editar #btnScheduleFromClinical,
body.perm-no-editar #btnNewPrescription,
body.perm-no-editar #btnSaveOdontogram,
body.perm-no-editar #btnQuoteFromOdontogram,
body.perm-no-editar #btnManageDoctorsFromCita,
body.perm-no-editar #treatmentRowForm,
body.perm-no-editar #doctorForm,
body.perm-no-editar [onclick*="openPatientModal"],
body.perm-no-editar [onclick*="openNewAppointmentModal"],
body.perm-no-editar [onclick*="editAppointment"],
body.perm-no-editar [onclick*="updateAppointmentStatus"],
body.perm-no-editar [onclick*="editDoctor"],
body.perm-no-editar [onclick*="openBudgetModal"] {
    display: none !important;
}

body.perm-no-agenda #tabAgenda,
body.perm-no-agenda #agendaView,
body.perm-no-agenda .clinical-tab-btn[data-tab="citas"],
body.perm-no-agenda #tabPaneCitas,
body.perm-no-agenda .card-cita-btn,
body.perm-no-agenda #btnScheduleFromClinical {
    display: none !important;
}

body.perm-no-doctores #btnDoctors,
body.perm-no-doctores #btnManageDoctorsFromCita {
    display: none !important;
}

body.perm-no-reportes #tabReports,
body.perm-no-reportes #reportsView {
    display: none !important;
}

body.perm-no-whatsapp #tabWhatsapp,
body.perm-no-whatsapp #whatsappView {
    display: none !important;
}

body.perm-no-presupuestos #btnOpenBudgetModal,
body.perm-no-presupuestos #btnQuoteFromOdontogram,
body.perm-no-presupuestos [onclick*="openBudgetModal"],
body.perm-no-presupuestos #budgetDialog,
body.perm-no-presupuestos #printBudgetDialog {
    display: none !important;
}

body.perm-no-alertas-medicas #tabMedicalAlerts,
body.perm-no-alertas-medicas #medicalAlertsView,
body.perm-no-alertas-medicas #medicalAlertDialog,
body.perm-no-alertas-medicas #alertPatientsDialog {
    display: none !important;
}

body.perm-no-editar #btnNewMedicalAlert,
body.perm-no-editar .btn-edit-medical-alert {
    display: none !important;
}

body.perm-no-eliminar .btn-delete-medical-alert {
    display: none !important;
}

/* System tools permission visibility rules */
body.perm-no-usuarios #btnUsers,
body.perm-no-respaldos #btnBackups,
body.perm-no-exportar-importar #btnExport,
body.perm-no-exportar-importar #btnImport,
body.perm-no-exportar-importar #btnTemplate,
body.perm-no-empresa #btnClinicConfig {
    display: none !important;
}

/* ========================================================
   REPORTS & STATISTICS MODULE STYLES (UI/UX ARCHITECT)
   ======================================================== */
.reports-subtabs-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    background: var(--surface-overlay);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 0.5rem;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

.report-subtab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.55rem 1.1rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.report-subtab-btn:hover {
    color: var(--accent);
    background: var(--bg-hover);
    border-color: rgba(15, 118, 110, 0.18);
}

.report-subtab-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.report-subtab-btn.active {
    background: linear-gradient(135deg, var(--accent) 0%, #0d9488 100%);
    color: #ffffff;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.28);
}

.reports-toolbar-card {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-md);
    padding: 1.15rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-md);
}

.reports-filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

.report-filter-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.report-filter-label {
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
}

.report-filter-control {
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    min-height: 40px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.report-filter-control:focus,
.report-filter-control:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.reports-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--border-color);
}

.reports-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.reports-kpi-grid .stat-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    background: linear-gradient(180deg, var(--surface-raised) 0%, var(--bg-surface-elevated) 100%);
    box-shadow: var(--shadow-sm);
}

.reports-kpi-grid .stat-card::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--accent), #3b82f6);
    border-radius: 4px 0 0 4px;
}

/* Tabular Numbers for Metrics, Currency & Badges */
.stat-value,
.tab-badge,
.ficha-badge,
.reports-data-table td,
.treatment-table td {
    font-variant-numeric: tabular-nums;
}

.reports-table-card {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    margin-bottom: 2rem;
}

.reports-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface-elevated);
}

.reports-table-scroll-region {
    overflow: auto;
    max-inline-size: 100%;
    max-block-size: min(640px, 75vh);
    container-type: inline-size;
}

.reports-table-scroll-region:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.reports-data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.86rem;
    text-align: left;
}

.reports-data-table thead {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
}

.reports-data-table thead tr {
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
}

.reports-data-table th {
    padding: 0.75rem 0.95rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.45px;
    white-space: nowrap;
    background: var(--bg-surface-elevated);
    border-bottom: 2px solid var(--border-color);
}

.reports-data-table td {
    padding: 0.75rem 0.95rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

/* Zebra striping & high-contrast hover state */
.reports-data-table tbody tr:nth-child(even) {
    background-color: rgba(148, 163, 184, 0.045);
}

.reports-data-table tbody tr:hover {
    background-color: var(--bg-hover);
}

.rep-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.74rem;
    font-weight: 700;
    padding: 0.2rem 0.55rem;
    border-radius: 9999px;
    white-space: nowrap;
}

.rep-status-completada {
    background: rgba(16, 185, 129, 0.14);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.rep-status-cancelada {
    background: rgba(239, 68, 68, 0.14);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.rep-status-confirmada {
    background: rgba(37, 99, 235, 0.14);
    color: #2563eb;
    border: 1px solid rgba(37, 99, 235, 0.3);
}

.rep-status-pendiente {
    background: rgba(245, 158, 11, 0.15);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.35);
}

/* ========================================================
   SUBTLE VERSION WATERMARK FOOTER
   ======================================================== */
.login-version-watermark {
    margin-top: 1.15rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border-color);
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    opacity: 0.78;
    letter-spacing: 0.3px;
    user-select: none;
}

.login-version-watermark strong {
    color: var(--text-secondary);
    font-weight: 600;
}

.app-version-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.1rem 1rem 1.35rem;
    margin-top: 1rem;
    user-select: none;
    pointer-events: none;
}

.version-watermark-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    font-size: 0.72rem;
    color: var(--text-muted);
    opacity: 0.75;
    letter-spacing: 0.3px;
    box-shadow: var(--shadow-sm);
}

.version-watermark-pill strong {
    color: var(--text-secondary);
    font-weight: 700;
}

.version-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* ========================================================
   MODERNO CLÍNICO PREMIUM — INTEGRAL UI/UX OVERHAUL
   ======================================================== */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

/* 1. Login Page & Security Pill */
.login-page {
    background:
        radial-gradient(circle at 12% 18%, rgba(15, 118, 110, 0.18) 0%, transparent 45%),
        radial-gradient(circle at 88% 82%, rgba(2, 132, 199, 0.14) 0%, transparent 45%),
        var(--bg-primary);
}

.login-card {
    position: relative;
    overflow: hidden;
    background: var(--surface-overlay);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-xl);
}

.login-card::before {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent) 0%, #0284c7 50%, #10b981 100%);
}

.login-security-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.28rem 0.75rem;
    margin-bottom: 1rem;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.25px;
    color: var(--accent);
    background: rgba(15, 118, 110, 0.1);
    border: 1px solid rgba(15, 118, 110, 0.25);
}

[data-theme="dark"] .login-security-pill {
    color: #2dd4bf;
    background: rgba(20, 184, 166, 0.14);
    border-color: rgba(45, 212, 191, 0.3);
}

/* 2. Sticky Glassmorphic App Header & User Profile Pill */
.app-header {
    position: sticky;
    top: 0.75rem;
    z-index: 40;
    background: var(--surface-overlay);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    border-radius: var(--border-radius);
    max-width: 100%;
}

.header-main-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    width: 100%;
}

.header-primary-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.btn-icon-round {
    width: 38px;
    height: 38px;
    padding: 0 !important;
    border-radius: var(--border-radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-cta-new {
    background: linear-gradient(135deg, var(--accent) 0%, #0d9488 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.28);
    height: 38px;
    padding: 0 1.15rem;
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
}

.header-primary-actions .btn {
    height: 38px;
    white-space: nowrap;
}

/* Secondary Tools Row (Admin & Data Management Utilities) */
.header-tools-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}

.tools-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.header-tools-cluster {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.btn-tool {
    height: 32px;
    padding: 0 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-tool:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

.btn-tool svg {
    width: 14px;
    height: 14px;
    stroke-width: 2;
}

.brand-title-stack {
    display: flex;
    flex-direction: column;
}

.brand-eyebrow {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    line-height: 1.1;
    margin-bottom: 0.1rem;
}

.header-user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.3rem 0.75rem 0.3rem 0.35rem;
    border-radius: 9999px;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    margin-right: 0.25rem;
    height: 38px;
}

.header-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, #0284c7 100%);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(15, 118, 110, 0.25);
}

.header-user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.header-user-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

.header-user-role {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* 3. Primary & Secondary Buttons with Gradient Micro-Accents */
.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, #0d9488 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.24);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
    box-shadow: 0 6px 16px rgba(15, 118, 110, 0.32);
    transform: translateY(-1px);
}

.btn:focus-visible,
.tab-btn:focus-visible,
.btn-toggle-view:focus-visible,
.btn-card-action:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* 4. Contextual Navigation Bar & Main Tabs */
.views-navigation-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.main-tabs {
    background: var(--surface-overlay);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    padding: 0.38rem;
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--accent) 0%, #0284c7 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.25);
}

.nav-contextual-bar {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.9rem;
    border-radius: 9999px;
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
}

/* 5. Asymmetric KPI Stat Bars (Visual Variety Directive) */
@media (min-width: 1024px) {
    .stats-bar {
        grid-template-columns: 1.35fr 1fr 1fr 1fr;
    }
}

.stat-card {
    overflow: hidden;
    background: linear-gradient(180deg, var(--surface-raised) 0%, var(--bg-surface-elevated) 100%);
    border: 1px solid var(--border-subtle);
    padding: 1.25rem 1.35rem;
}

.stat-card::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 4px;
    background: var(--accent);
    opacity: 0.75;
}

#cardStatTotal::before,
#cardStatCitasHoy::before {
    width: 5px;
    background: linear-gradient(180deg, var(--accent) 0%, #3b82f6 100%);
    opacity: 1;
}

#cardStatTotal,
#cardStatCitasHoy {
    background: linear-gradient(135deg, var(--surface-raised) 0%, rgba(15, 118, 110, 0.07) 100%);
}

[data-theme="dark"] #cardStatTotal,
[data-theme="dark"] #cardStatCitasHoy {
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(20, 184, 166, 0.14) 100%);
}

#cardStatTotal .stat-value,
#cardStatCitasHoy .stat-value {
    font-size: 2.05rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

#cardStatFichas::before,
#cardStatCitasCompletadas::before {
    background: var(--color-success);
}

#cardStatProximo::before,
#cardStatCitasPendientes::before {
    background: var(--color-warning);
}

#cardStatVencido::before {
    background: var(--color-danger);
}

/* 6. Enhanced Patient Cards & Identity Header */
.patient-card {
    position: relative;
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

.patient-card::before {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline: 0;
    height: 3.5px;
    background: var(--accent);
}

.patient-card.status-al-dia::before {
    background: linear-gradient(90deg, #10b981, #059669);
}

.patient-card.status-proximamente::before {
    background: linear-gradient(90deg, #f59e0b, #d97706);
}

.patient-card.status-vencido::before {
    background: linear-gradient(90deg, #ef4444, #dc2626);
}

.card-patient-identity {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex: 1;
    min-width: 0;
}

.card-avatar-ring {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.14) 0%, rgba(59, 130, 246, 0.14) 100%);
    border: 2px solid rgba(15, 118, 110, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    cursor: pointer;
    transition: var(--transition);
}

.card-avatar-ring:hover {
    border-color: var(--accent);
    transform: scale(1.04);
}

.card-avatar-ring.card-avatar-sm {
    width: 36px;
    height: 36px;
}

.card-avatar-ring img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-avatar-initials {
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.03em;
}

[data-theme="dark"] .card-avatar-initials {
    color: #2dd4bf;
}

.card-badges-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.2rem;
}

.card-allergy-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.14rem 0.55rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.card-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.38rem;
    padding: 0.22rem 0.62rem;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 700;
    border: 1px solid var(--border-subtle);
    background: var(--bg-primary);
    color: var(--text-secondary);
    flex-shrink: 0;
}

.card-status-pill .card-status-dot {
    margin-top: 0;
    width: 0.5rem;
    height: 0.5rem;
}

.card-status-pill.al-dia {
    background: var(--color-success-bg);
    color: var(--color-success);
    border-color: rgba(16, 185, 129, 0.3);
}

.card-status-pill.proximamente {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border-color: rgba(245, 158, 11, 0.3);
}

.card-status-pill.vencido {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.balance-alert-row {
    background: var(--color-danger-bg);
    color: var(--color-danger) !important;
    padding: 0.42rem 0.65rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(239, 68, 68, 0.25);
    font-weight: 600;
}

.results-counter-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    background: rgba(15, 118, 110, 0.1);
    border: 1px solid rgba(15, 118, 110, 0.22);
    white-space: nowrap;
}

[data-theme="dark"] .results-counter-pill {
    color: #2dd4bf;
    background: rgba(20, 184, 166, 0.15);
    border-color: rgba(45, 212, 191, 0.3);
}

/* 7. Treatment Table Zebra Striping & Sticky Header */
.treatment-table tbody tr:nth-child(even) {
    background-color: rgba(148, 163, 184, 0.045);
}

/* 8. Modal Header & Elevation Polish */
.modal-dialog {
    border: 1px solid var(--border-subtle);
}

.modal-header {
    background: linear-gradient(180deg, var(--bg-surface-elevated) 0%, var(--bg-card) 100%);
}

/* 9. Patient Directory Table View (High Scannability) */
.patient-directory-table th {
    background: var(--bg-surface-elevated);
    padding: 0.7rem 0.65rem;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.patient-directory-table td {
    padding: 0.6rem 0.65rem;
    vertical-align: middle;
}

.patient-directory-table tbody tr:hover {
    background-color: var(--bg-hover);
}

@media (max-width: 1120px) {
    .patient-directory-table th:nth-child(4),
    .patient-directory-table td:nth-child(4) {
        display: none;
    }
}

@media (max-width: 900px) {
    .patient-directory-table th:nth-child(5),
    .patient-directory-table td:nth-child(5) {
        display: none;
    }
}

@media (max-width: 680px) {
    .patient-directory-table th:nth-child(3),
    .patient-directory-table td:nth-child(3) {
        display: none;
    }
}

/* ========================================================
   WHATSAPP TEMPLATES MANAGEMENT VIEW & REAL-TIME PREVIEW
   ======================================================== */

.whatsapp-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.whatsapp-view-header-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.whatsapp-view-icon-badge {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.28);
    flex-shrink: 0;
}

.whatsapp-view-header-title h2 {
    font-size: 1.28rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.25rem 0;
    letter-spacing: -0.2px;
}

.whatsapp-view-subtitle {
    font-size: 0.84rem;
    color: var(--text-secondary);
    margin: 0;
}

/* 3-Column Asymmetric Grid Layout */
.whatsapp-config-grid {
    display: grid;
    grid-template-columns: 280px 1fr 340px;
    gap: 1.25rem;
    align-items: start;
}

/* Column 1: Status Sidebar */
.whatsapp-status-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.whatsapp-sidebar-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.15rem;
    box-shadow: var(--shadow-sm);
}

.whatsapp-sidebar-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.whatsapp-sidebar-eyebrow {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.2rem;
}

.whatsapp-sidebar-header h3 {
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.whatsapp-status-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.whatsapp-status-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.85rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    user-select: none;
    width: 100%;
}

.whatsapp-status-item:hover {
    border-color: #25D366;
    background: var(--bg-hover);
    transform: translateX(2px);
}

.whatsapp-status-item.active {
    background: rgba(37, 211, 102, 0.08);
    border-color: #25D366;
    box-shadow: 0 0 0 1px #25D366;
}

[data-theme="dark"] .whatsapp-status-item.active {
    background: rgba(37, 211, 102, 0.14);
    border-color: #25D366;
}

.status-item-indicator {
    width: 8px;
    height: 38px;
    border-radius: 4px;
    flex-shrink: 0;
}

.status-ind-recordatorio { background: #d97706; }
.status-ind-confirmada   { background: #2563eb; }
.status-ind-atendida     { background: #059669; }
.status-ind-cancelada    { background: #dc2626; }

.status-item-content {
    flex: 1;
    min-width: 0;
}

.status-item-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.2rem;
}

.status-item-name {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.status-item-desc {
    font-size: 0.74rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.25;
}

.status-item-arrow {
    color: var(--text-muted);
    opacity: 0.6;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.whatsapp-status-item.active .status-item-arrow {
    color: #25D366;
    opacity: 1;
    transform: translateX(2px);
}

/* Guide Card */
.whatsapp-guide-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}

.whatsapp-guide-header {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.65rem;
}

.whatsapp-guide-list {
    margin: 0;
    padding-left: 1.15rem;
    font-size: 0.77rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.whatsapp-guide-list code {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.76rem;
    color: #25D366;
    font-weight: 600;
}

/* Column 2: Editor Section */
.whatsapp-editor-section {
    display: flex;
    flex-direction: column;
}

.whatsapp-editor-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.35rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.whatsapp-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.whatsapp-editor-heading-wrap {
    flex: 1;
}

.whatsapp-editor-badge-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.35rem;
}

.whatsapp-editor-heading-wrap h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.25rem 0;
}

.whatsapp-editor-subtitle {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.35;
}

.whatsapp-save-status {
    font-size: 0.73rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
}

/* Variables toolbar card */
.whatsapp-variables-card {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.9rem 1rem;
}

.whatsapp-variables-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}

.whatsapp-variables-title {
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.whatsapp-variables-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.whatsapp-variable-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.btn-variable-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 0.32rem 0.65rem;
    border-radius: 6px;
    font-size: 0.76rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.btn-variable-chip code {
    color: #059669;
    font-weight: 700;
    background: rgba(16, 185, 129, 0.1);
    padding: 0.1rem 0.25rem;
    border-radius: 4px;
}

[data-theme="dark"] .btn-variable-chip code {
    color: #34d399;
    background: rgba(16, 185, 129, 0.2);
}

.btn-variable-chip:hover {
    border-color: #25D366;
    background: rgba(37, 211, 102, 0.08);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-variable-chip:active {
    transform: scale(0.96);
}

/* Textarea wrapper */
.whatsapp-textarea-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.whatsapp-textarea-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.whatsapp-textarea-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
}

.whatsapp-char-counter {
    font-size: 0.74rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.whatsapp-textarea {
    width: 100%;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    padding: 0.85rem 1rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-primary);
    resize: vertical;
    min-height: 220px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
}

.whatsapp-textarea:focus {
    outline: none;
    border-color: #25D366;
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.25);
}

/* Editor footer actions */
.whatsapp-editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

/* Column 3: Live Mobile Mockup */
.whatsapp-preview-section {
    display: flex;
    flex-direction: column;
}

.whatsapp-preview-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem 1.15rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.whatsapp-preview-card-header {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.preview-badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(37, 211, 102, 0.12);
    color: #128C7E;
    border: 1px solid rgba(37, 211, 102, 0.3);
    padding: 0.2rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

[data-theme="dark"] .preview-badge-pill {
    color: #25D366;
    background: rgba(37, 211, 102, 0.18);
}

.preview-dot-pulse {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #25D366;
    animation: waDotPulse 1.8s infinite ease-in-out;
}

@keyframes waDotPulse {
    0% { transform: scale(0.9); opacity: 0.8; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.8; }
}

.whatsapp-preview-sub {
    font-size: 0.74rem;
    color: var(--text-muted);
}

/* Smartphone Device Mockup */
.wa-phone-mockup {
    width: 100%;
    max-width: 310px;
    background: #e5ddd5;
    border: 8px solid #1e293b;
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22), 0 10px 10px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
}

[data-theme="dark"] .wa-phone-mockup {
    background: #0b141a;
    border-color: #0f172a;
}

.wa-phone-top-bar {
    background: #075e54;
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0.85rem 0.15rem;
    font-size: 0.68rem;
    font-weight: 600;
}

[data-theme="dark"] .wa-phone-top-bar {
    background: #1f2c34;
}

.wa-phone-notch {
    width: 50px;
    height: 10px;
    background: #0f172a;
    border-radius: 0 0 8px 8px;
}

/* App Header */
.wa-app-header {
    background: #075e54;
    color: #ffffff;
    padding: 0.45rem 0.65rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

[data-theme="dark"] .wa-app-header {
    background: #1f2c34;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.wa-header-left {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.wa-back-arrow {
    cursor: pointer;
    opacity: 0.9;
}

.wa-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #128c7e;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: #ffffff;
    overflow: hidden;
    flex-shrink: 0;
}

.wa-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wa-avatar-fallback {
    font-size: 0.72rem;
}

.wa-header-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.wa-header-contact-name {
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

.wa-header-status {
    font-size: 0.64rem;
    opacity: 0.85;
}

.wa-header-actions {
    opacity: 0.9;
}

/* Chat canvas */
.wa-chat-canvas {
    padding: 0.85rem 0.65rem;
    min-height: 280px;
    max-height: 380px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    background-color: #efeae2;
    background-image: radial-gradient(rgba(0,0,0,0.04) 1px, transparent 0);
    background-size: 16px 16px;
}

[data-theme="dark"] .wa-chat-canvas {
    background-color: #0b141a;
    background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 0);
}

.wa-date-chip-wrap {
    display: flex;
    justify-content: center;
}

.wa-date-chip {
    background: rgba(255, 255, 255, 0.85);
    color: #54656f;
    font-size: 0.64rem;
    font-weight: 700;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
    text-transform: uppercase;
}

[data-theme="dark"] .wa-date-chip {
    background: #182229;
    color: #8696a0;
}

/* Chat bubble */
.wa-bubble-wrap {
    display: flex;
    justify-content: flex-end;
}

.wa-message-bubble {
    background: #dcf8c6;
    color: #111b21;
    border-radius: 8px 8px 2px 8px;
    padding: 0.55rem 0.65rem 0.4rem;
    max-width: 90%;
    box-shadow: 0 1px 1.5px rgba(0,0,0,0.13);
    position: relative;
    word-break: break-word;
    font-size: 0.82rem;
    line-height: 1.38;
}

[data-theme="dark"] .wa-message-bubble {
    background: #005c4b;
    color: #e9edef;
}

.wa-message-text {
    white-space: pre-wrap;
    margin-bottom: 0.25rem;
}

.wa-message-text strong {
    font-weight: 700;
}

.wa-message-text em {
    font-style: italic;
}

.wa-message-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    font-size: 0.64rem;
    color: #667781;
    font-variant-numeric: tabular-nums;
}

[data-theme="dark"] .wa-message-footer {
    color: #8696a0;
}

.wa-read-receipt {
    color: #53bdeb;
    display: inline-flex;
    align-items: center;
}

/* Phone bottom input */
.wa-phone-input-bar {
    background: #f0f2f5;
    padding: 0.35rem 0.55rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px solid rgba(0,0,0,0.06);
}

[data-theme="dark"] .wa-phone-input-bar {
    background: #202c33;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.wa-input-placeholder {
    flex: 1;
    background: #ffffff;
    border-radius: 18px;
    padding: 0.32rem 0.65rem;
    font-size: 0.72rem;
    color: #8696a0;
}

[data-theme="dark"] .wa-input-placeholder {
    background: #2a3942;
    color: #8696a0;
}

.wa-mic-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #00a884;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.whatsapp-preview-footnote {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    margin: 0.85rem 0 0 0;
    line-height: 1.35;
}

.whatsapp-preview-footnote code {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    padding: 0.1rem 0.25rem;
    border-radius: 4px;
    font-size: 0.7rem;
    color: #059669;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .whatsapp-config-grid {
        grid-template-columns: 240px 1fr 300px;
        gap: 1rem;
    }
}

@media (max-width: 980px) {
    .whatsapp-config-grid {
        grid-template-columns: 1fr;
    }
    .whatsapp-preview-card {
        max-width: 420px;
        margin: 0 auto;
        width: 100%;
    }
}

/* ========================================================
   MEDICAL ALERTS & CRITICAL ALLERGIES MODULE STYLES
   ======================================================== */
.medical-alerts-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
    background: var(--surface-overlay, var(--bg-secondary));
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    backdrop-filter: blur(8px);
}

.medical-alerts-header-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.medical-alerts-icon-badge {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(239, 68, 68, 0.12);
    border: 1.5px solid rgba(239, 68, 68, 0.3);
    color: var(--color-danger);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.medical-alerts-header-title h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.medical-alerts-subtitle {
    margin: 0.2rem 0 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.medical-alerts-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.alert-kpi-card {
    background: var(--bg-surface-elevated, var(--bg-secondary));
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.95rem 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.alert-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.alert-kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.alert-kpi-icon.icon-blue {
    background: rgba(37, 99, 235, 0.12);
    color: var(--color-primary);
}

.alert-kpi-icon.icon-red {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-danger);
}

.alert-kpi-icon.icon-amber {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

.alert-kpi-icon.icon-teal {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}

.alert-kpi-data {
    display: flex;
    flex-direction: column;
}

.alert-kpi-value {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.alert-kpi-label {
    font-size: 0.76rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-top: 0.15rem;
}

.medical-alerts-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    background: var(--bg-surface-elevated, var(--bg-secondary));
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.alerts-search-wrap {
    position: relative;
    flex: 1;
    min-width: 240px;
    max-width: 420px;
}

.alerts-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.alerts-search-wrap input {
    width: 100%;
    height: 38px;
    padding-left: 2.25rem;
    padding-right: 2rem;
    font-size: 0.86rem;
    border-radius: var(--border-radius-sm);
}

.alerts-filter-group {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.alerts-risk-pills {
    display: flex;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 2px;
    gap: 2px;
}

.btn-risk-pill {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-risk-pill:hover {
    color: var(--text-primary);
}

.btn-risk-pill.active {
    background: var(--color-primary);
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}

.btn-risk-pill.active.risk-pill-critico {
    background: var(--color-danger);
    box-shadow: 0 1px 3px rgba(239, 68, 68, 0.3);
}

.btn-risk-pill.active.risk-pill-alto {
    background: #d97706;
    box-shadow: 0 1px 3px rgba(217, 119, 6, 0.3);
}

.btn-risk-pill.active.risk-pill-moderado {
    background: #ca8a04;
    box-shadow: 0 1px 3px rgba(202, 138, 4, 0.3);
}

.medical-alerts-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 1.15rem;
}

.alert-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.15rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.85rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    position: relative;
    overflow: hidden;
}

.alert-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(37, 99, 235, 0.3);
}

.alert-card.risk-critico {
    border-left: 4.5px solid var(--color-danger);
}

.alert-card.risk-alto {
    border-left: 4.5px solid #d97706;
}

.alert-card.risk-moderado {
    border-left: 4.5px solid #ca8a04;
}

.alert-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.alert-card-title-group {
    flex: 1;
}

.alert-card-name {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.25;
}

.alert-card-category {
    display: inline-block;
    margin-top: 0.25rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.alert-risk-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.alert-risk-badge.badge-critico {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-risk-badge.badge-alto {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.alert-risk-badge.badge-moderado {
    background: rgba(234, 179, 8, 0.12);
    color: #ca8a04;
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.alert-card-description {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin: 0;
}

.alert-card-action-box {
    background: var(--bg-primary);
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.65rem 0.85rem;
    font-size: 0.82rem;
    line-height: 1.4;
}

.alert-card-action-box strong {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--color-danger);
    margin-bottom: 0.25rem;
}

.alert-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.65rem;
    border-top: 1px solid var(--border-color);
    margin-top: 0.25rem;
}

.alert-patient-count-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--color-primary);
    transition: background 0.15s ease;
}

.alert-patient-count-btn:hover {
    background: rgba(37, 99, 235, 0.08);
}

.alert-card-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.btn-alert-action {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.3rem 0.55rem;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.78rem;
    font-weight: 600;
    transition: all 0.15s ease;
}

.btn-alert-action:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.btn-alert-action.btn-delete-medical-alert:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--color-danger);
    border-color: rgba(239, 68, 68, 0.4);
}

.medical-alerts-empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3.5rem 1.5rem;
    background: var(--bg-secondary);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.medical-alerts-empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-danger);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
}






