/* Design System - Rose Clínica & Financeira */
:root {
    --bg-primary: #FDFBFC;       /* Branco rosado */
    --bg-secondary: #F8F5F5;     /* Cinza rosado claro */
    --bg-card: #ffffff;          /* Card fundo branco */
    --bg-card-hover: #ffffff;
    --bg-input: #ffffff;
    --border-color: #EDE8E8;     /* Cinza claro para bordas */
    --border-color-hover: #DDA0A4; /* Rosa pálido */
    --text-primary: #3A3A3A;     /* Cinza escuro */
    --text-secondary: #6B6B6B;   /* Cinza médio */
    --text-muted: #9B9B9B;       /* Cinza claro */
    
    --primary: #5A7A7C;          /* Verde-azulado hospitalar/clínico */
    --primary-rgb: 90, 122, 124;
    --primary-hover: #4A6A6C;
    --primary-glow: rgba(90, 122, 124, 0.12);
    
    --accent: #DDA0A4;           /* Rosa pálido */
    --accent-soft: #F0D5D8;      /* Rosa muito suave */
    --accent-light: #FAF0F1;     /* Rosa clarinho */
    --green-soft: #A3C1C3;       /* Verde suave */
    --secondary-blue: #8B9DC3;   /* Azul suave */
    
    --success: #2d8a6b;
    --success-glow: rgba(45, 138, 107, 0.12);
    --warning: #d97706;
    --warning-glow: rgba(217, 119, 6, 0.12);
    --danger: #dc2626;
    --danger-glow: rgba(220, 38, 38, 0.12);
    --info: #0891b2;
    --info-glow: rgba(8, 145, 178, 0.12);
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --shadow-sm: 0 2px 8px rgba(90, 122, 124, 0.04);
    --shadow-md: 0 10px 30px rgba(90, 122, 124, 0.06);
    --shadow-lg: 0 20px 50px rgba(90, 122, 124, 0.1);
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 260px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--primary-rgb), 0.2) var(--bg-primary);
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: rgba(var(--primary-rgb), 0.2);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--primary-rgb), 0.4);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}
a:hover {
    color: var(--primary-hover);
}

/* Loader */
.initial-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-color: var(--bg-primary);
}
.loader-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(var(--primary-rgb), 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* App Shell Layout */
#app {
    min-height: 100vh;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: var(--transition);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(var(--primary-rgb), 0.1);
}
.logo-icon {
    width: 38px;
    height: 38px;
    background: radial-gradient(circle, var(--primary) 0%, #4A6A6C 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 0 15px var(--primary-glow);
}
.logo-text h1 {
    font-size: 1.3rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.logo-text p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.menu-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.menu-item button {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
    text-align: left;
}
.menu-item button i {
    width: 20px;
    height: 20px;
}
.menu-item button:hover {
    color: var(--primary);
    background-color: rgba(var(--primary-rgb), 0.05);
}
.menu-item.active button {
    color: var(--text-primary);
    background: linear-gradient(90deg, rgba(var(--primary-rgb), 0.12) 0%, rgba(var(--primary-rgb), 0.02) 100%);
    border-left: 3px solid var(--primary);
    padding-left: 13px; /* adjusts for border */
}

.user-profile-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}
.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--bg-primary);
    border: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--primary);
}
.user-info {
    flex-grow: 1;
    overflow: hidden;
}
.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.btn-logout {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}
.btn-logout:hover {
    color: var(--danger);
}

/* Main Content Wrapper */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Topbar Header */
.topbar {
    height: 70px;
    background-color: rgba(253, 251, 252, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 0 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 90;
}
.page-title h2 {
    font-size: 1.4rem;
    font-weight: 700;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}
.system-mode-badge {
    background-color: rgba(var(--primary-rgb), 0.08);
    color: var(--primary);
    border: 1px solid rgba(var(--primary-rgb), 0.15);
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.system-mode-badge.supabase {
    background-color: rgba(45, 138, 107, 0.08);
    color: var(--success);
    border-color: rgba(45, 138, 107, 0.15);
}
.system-mode-badge.local, .system-mode-badge.test-mode {
    background-color: rgba(217, 119, 6, 0.08);
    color: var(--warning);
    border-color: rgba(217, 119, 6, 0.15);
}
.system-mode-badge.danger {
    background-color: rgba(220, 38, 38, 0.08);
    color: var(--danger);
    border-color: rgba(220, 38, 38, 0.15);
}


/* Content Area */
.content-body {
    padding: 36px;
    flex-grow: 1;
}

/* Glass Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at top right, rgba(var(--primary-rgb), 0.03), transparent 60%);
    pointer-events: none;
}
.card:hover {
    border-color: var(--border-color-hover);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Typography Helpers */
.section-title {
    font-size: 1.15rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.section-title i {
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: none;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #4A6A6C 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.2);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #3a5355 100%);
    box-shadow: 0 6px 16px rgba(var(--primary-rgb), 0.3);
    transform: translateY(-1px);
}
.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover {
    background-color: rgba(0,0,0,0.02);
    border-color: var(--border-color-hover);
}
.btn-danger {
    background-color: var(--danger);
    color: white;
}
.btn-danger:hover {
    background-color: #dc2626;
}
.btn-success {
    background-color: var(--success);
    color: white;
}
.btn-success:hover {
    background-color: #059669;
}
.btn-warning {
    background-color: var(--warning);
    color: white;
}
.btn-warning:hover {
    background-color: #b45309;
}
.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

/* Inputs & Form Controls */
.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}
.form-control, select, textarea {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: var(--transition);
}
.form-control:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(var(--primary-rgb), 0.15);
}
textarea {
    resize: vertical;
    min-height: 100px;
}
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-active, .badge-ativo, .badge-pago, .badge-confirmada, .badge-realizada {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.badge-inactive, .badge-inativo, .badge-cancelado, .badge-cancelada, .badge-falta {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.badge-em_espera, .badge-pendente, .badge-parcial, .badge-agendada {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.badge-alta, .badge-concluido, .badge-isento {
    background-color: rgba(6, 182, 212, 0.1);
    color: var(--info);
    border: 1px solid rgba(6, 182, 212, 0.2);
}
.badge-pausado {
    background-color: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}
.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    text-align: left;
}
.table th {
    padding: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border-color);
}
.table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-primary);
}
.table tr {
    transition: var(--transition);
}
.table tr:hover td {
    background-color: rgba(var(--primary-rgb), 0.02);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(58, 58, 58, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}
.modal-container {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 650px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-container.large {
    max-width: 900px;
}
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex-grow: 1;
}
.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}
.modal-close:hover {
    color: var(--primary);
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* 1. LOGIN STYLE */
.login-view-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at 10% 20%, rgba(var(--primary-rgb), 0.04) 0%, transparent 50%),
                radial-gradient(circle at 90% 80%, rgba(var(--primary-rgb), 0.04) 0%, transparent 50%),
                var(--bg-primary);
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 440px;
    padding: 40px;
    border: 1px solid var(--border-color);
    background: #ffffff;
}
.login-header {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo {
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, var(--primary) 0%, #4A6A6C 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin: 0 auto 16px auto;
    box-shadow: 0 0 20px var(--primary-glow);
}
.login-header h2 {
    font-size: 1.8rem;
    margin-bottom: 6px;
}
.login-header p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.login-info-box {
    background-color: rgba(var(--primary-rgb), 0.05);
    border: 1px dashed rgba(var(--primary-rgb), 0.2);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 24px;
    font-size: 0.85rem;
}
.login-info-box p {
    margin-bottom: 6px;
    font-weight: 500;
}
.login-info-box ul {
    list-style-position: inside;
    color: var(--text-secondary);
}
.login-error {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-size: 0.85rem;
    margin-bottom: 20px;
    display: none;
}

/* 2. DASHBOARD STYLE */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    margin-bottom: 36px;
}
.kpi-card {
    display: flex;
    align-items: center;
    gap: 20px;
}
.kpi-icon {
    width: 54px;
    height: 54px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}
.kpi-icon.primary { background-color: var(--primary-glow); color: var(--primary); }
.kpi-icon.success { background-color: var(--success-glow); color: var(--success); }
.kpi-icon.warning { background-color: var(--warning-glow); color: var(--warning); }
.kpi-icon.info { background-color: var(--info-glow); color: var(--info); }

.kpi-data h3 {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.2;
}
.kpi-data p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.dashboard-sections {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

/* Charts & Lists in Dashboard */
.chart-container {
    height: 250px;
    position: relative;
    margin-top: 16px;
}
.cashflow-chart-bar-container {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 200px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}
.chart-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 60px;
}
.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 150px;
    width: 100%;
    justify-content: center;
}
.chart-bar {
    width: 14px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: var(--transition);
    min-height: 2px;
}
.chart-bar.receita { background-color: var(--success); }
.chart-bar.despesa { background-color: var(--danger); }
.chart-bar:hover {
    opacity: 0.8;
}
.chart-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.chart-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 16px;
    font-size: 0.8rem;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}
.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}
.legend-color.receita { background-color: var(--success); }
.legend-color.despesa { background-color: var(--danger); }

/* Quick Lists */
.quick-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.quick-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: rgba(255,255,255,0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}
.quick-list-details h4 {
    font-size: 0.9rem;
    font-weight: 600;
}
.quick-list-details p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.quick-list-value {
    font-weight: 600;
    font-size: 0.9rem;
}

/* 3. AGENDA / CALENDAR STYLE */
.agenda-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.calendar-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}
.calendar-view-select {
    display: flex;
    background-color: var(--bg-secondary);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.calendar-view-select button {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px 14px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.calendar-view-select button.active {
    background-color: var(--primary);
    color: white;
}

.weekly-calendar-grid {
    display: grid;
    grid-template-columns: 80px repeat(7, 1fr);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background-color: var(--bg-secondary);
    overflow: hidden;
}
.calendar-time-col-header {
    padding: 16px;
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-bottom: 2px solid var(--border-color);
    border-right: 1px solid var(--border-color);
}
.calendar-day-header {
    padding: 16px 8px;
    text-align: center;
    border-bottom: 2px solid var(--border-color);
    border-right: 1px solid var(--border-color);
}
.calendar-day-header:last-child {
    border-right: none;
}
.calendar-day-name {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 500;
}
.calendar-day-number {
    font-size: 1.4rem;
    font-weight: 700;
    margin-top: 4px;
}
.calendar-day-header.today {
    background-color: rgba(var(--primary-rgb), 0.08);
}
.calendar-day-header.today .calendar-day-number {
    color: var(--primary);
}

.calendar-time-slot {
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background-color: transparent;
}
.calendar-day-col {
    position: relative;
    border-right: 1px solid var(--border-color);
    background-color: rgba(var(--primary-rgb), 0.02);
}
.calendar-day-col:last-child {
    border-right: none;
}
.calendar-grid-cell {
    height: 70px;
    border-bottom: 1px solid var(--border-color);
}

/* Appointment block overlay in calendar */
.appointment-card {
    position: absolute;
    left: 4px;
    right: 4px;
    border-radius: var(--radius-sm);
    padding: 8px;
    font-size: 0.75rem;
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border-left: 3px solid transparent;
    z-index: 10;
}
.appointment-card:hover {
    transform: scale(1.02);
    z-index: 20;
    box-shadow: var(--shadow-md);
}
.appointment-card.agendada {
    background-color: rgba(245, 158, 11, 0.15);
    border-color: var(--warning);
    color: #fca5a5; /* warm lighter text */
}
.appointment-card.confirmada {
    background-color: rgba(37, 99, 235, 0.15);
    border-color: #3b82f6;
    color: #93c5fd;
}
.appointment-card.realizada {
    background-color: rgba(16, 185, 129, 0.15);
    border-color: var(--success);
    color: #a7f3d0;
}
.appointment-card.cancelada {
    background-color: rgba(148, 163, 184, 0.1);
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}
.appointment-card.falta {
    background-color: rgba(239, 68, 68, 0.15);
    border-color: var(--danger);
    color: #fca5a5;
}
.appointment-card-title {
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.appointment-card-time {
    font-size: 0.65rem;
    opacity: 0.8;
    margin-top: 2px;
}

/* 4. PATIENT PROFILE STYLE */
.patient-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}
.search-box {
    display: flex;
    align-items: center;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0 16px;
    flex-grow: 1;
    max-width: 500px;
}
.search-box i {
    color: var(--text-secondary);
}
.search-box input {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 12px;
    width: 100%;
    outline: none;
    font-family: var(--font-body);
}

.patient-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}
.patient-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.patient-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
}
.patient-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background-color: rgba(var(--primary-rgb), 0.08);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    border: 1px solid rgba(var(--primary-rgb), 0.15);
}
.patient-card-info h3 {
    font-size: 1.05rem;
    font-weight: 600;
}
.patient-card-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}
.patient-card-contact {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}
.patient-card-contact div {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.patient-card-contact div i {
    width: 14px;
    height: 14px;
    color: var(--primary);
}

/* Patient Tabs Detail View */
.patient-detail-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 30px;
}
.patient-side-card {
    height: fit-content;
}
.patient-side-avatar {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-lg);
    background-color: rgba(var(--primary-rgb), 0.08);
    border: 2px solid var(--primary);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 700;
    margin: 0 auto 20px auto;
}
.patient-side-name {
    text-align: center;
    font-size: 1.25rem;
    margin-bottom: 6px;
}
.patient-side-status {
    text-align: center;
    margin-bottom: 24px;
}
.patient-info-list {
    list-style: none;
    font-size: 0.85rem;
}
.patient-info-list li {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}
.patient-info-list li:last-child {
    border-bottom: none;
}
.patient-info-list label {
    color: var(--text-secondary);
}
.patient-info-list span {
    font-weight: 500;
}

.tabs-navigation {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
    overflow-x: auto;
    gap: 8px;
}
.tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 12px 18px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.tab-btn:hover {
    color: var(--primary);
}
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

/* 5. CLINICAL RECORDS / PRONTUÁRIOS */
.record-card {
    border-left: 4px solid var(--primary);
    margin-bottom: 20px;
}
.record-card.locked {
    border-left-color: var(--success);
}
.record-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.record-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.record-item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.record-detail-block {
    background-color: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.record-detail-block label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    font-weight: 600;
}
.record-detail-block p {
    font-size: 0.9rem;
    line-height: 1.5;
}
.record-footer-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* CRP Locked Alert Badge */
.crp-locked-badge {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 6. FINANCE VIEW STYLE */
.finance-dashboard {
    display: grid;
    grid-template-columns: 2fr 1.2fr;
    gap: 30px;
}
.transaction-form-overlay {
    /* reuse modal styles */
}
.finance-stats-summary {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.finance-list-filters {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.finance-filter-tabs {
    display: flex;
    background-color: var(--bg-secondary);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.finance-filter-tabs button {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px 16px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.finance-filter-tabs button.active {
    background-color: var(--primary);
    color: white;
}

.transaction-value.receita { color: var(--success); }
.transaction-value.despesa { color: var(--danger); }

/* Document Upload Grid styles */
.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.document-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    position: relative;
    transition: var(--transition);
}
.document-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}
.document-icon {
    font-size: 2.2rem;
    color: var(--primary);
    margin-bottom: 12px;
}
.document-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    margin-bottom: 4px;
}
.document-meta {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Custom Notification Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
}
.toast {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 16px 24px;
    color: var(--text-primary);
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 450px;
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger { border-left-color: var(--danger); }
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive adjustments & Mobile Layout support */
body, html {
    overflow-x: hidden;
    max-width: 100vw;
}
.app-container {
    max-width: 100vw;
    width: 100%;
    overflow: hidden;
}
.main-wrapper {
    max-width: 100%;
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
}
.content-body {
    max-width: 100%;
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

.btn-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    margin-right: 8px;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.btn-menu-toggle:hover {
    background-color: rgba(var(--primary-rgb), 0.05);
}
.btn-menu-toggle i {
    width: 24px;
    height: 24px;
    color: var(--text-primary);
}
.topbar-left-side {
    display: flex;
    align-items: center;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 95;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 1024px) {
    .btn-menu-toggle {
        display: flex;
    }
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .main-wrapper {
        margin-left: 0;
    }
    .dashboard-sections {
        grid-template-columns: 1fr;
    }
    .patient-detail-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    .finance-dashboard {
        grid-template-columns: 1fr;
    }
    .topbar {
        padding: 0 20px;
    }
    .modal-container {
        margin: 16px;
        max-width: calc(100% - 32px);
    }
}

@media (max-width: 768px) {
    .topbar {
        padding: 0 16px;
        height: 60px;
    }
    .topbar-actions .system-mode-badge {
        font-size: 0.7rem;
        padding: 2px 8px;
    }
    .topbar-actions .system-mode-badge i {
        width: 12px;
        height: 12px;
    }
    .page-title h2 {
        font-size: 1.15rem;
    }
    .content-body {
        padding: 20px 16px;
    }
    
    /* Weekly calendar mobile horizontal scrolling fixed */
    .weekly-calendar-grid {
        display: grid !important;
        grid-template-columns: 65px repeat(7, 130px) !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius-md);
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    .calendar-time-slot {
        height: 70px;
    }
    .calendar-day-col {
        height: 70px !important;
    }
    
    /* Finance filters layout wrap & class targets */
    .finance-list-filters {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
    }
    .finance-list-filters .search-box {
        max-width: 100% !important;
        width: 100%;
    }
    
    .finance-filter-actions {
        display: flex;
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px;
        width: 100%;
    }
    .finance-filter-actions button {
        width: 100% !important;
        justify-content: center;
    }
    .finance-filter-tabs {
        width: 100%;
        display: flex;
    }
    .finance-filter-tabs button {
        flex: 1;
        text-align: center;
    }
    
    /* Tabs navigation scrolling */
    .tabs-navigation {
        display: flex;
        overflow-x: auto !important;
        white-space: nowrap;
        padding-bottom: 6px;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        border-bottom: 1px solid var(--border-color);
    }
    .tabs-navigation::-webkit-scrollbar {
        height: 4px;
    }
    .tabs-navigation::-webkit-scrollbar-thumb {
        background-color: var(--border-color);
        border-radius: var(--radius-sm);
    }
    .tab-btn {
        flex-shrink: 0;
    }
    
    /* KPI grids gaps */
    .kpi-grid {
        gap: 16px;
        margin-bottom: 24px;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
    .kpi-card {
        padding: 16px !important;
        gap: 16px;
    }
    
    /* Settings layout and buttons */
    #form-settings-supabase div[style*="display:flex"] {
        flex-direction: column;
        gap: 12px;
    }
    #form-settings-supabase div[style*="display:flex"] div,
    #form-settings-supabase div[style*="display:flex"] button {
        width: 100%;
    }
}

@media (max-width: 576px) {
    .agenda-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 16px;
    }
    .calendar-nav {
        justify-content: center;
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }
    #calendar-range-label {
        margin-left: 0 !important;
        font-size: 0.95rem !important;
        width: 100%;
        text-align: center;
    }
    #btn-schedule-session {
        width: 100%;
        justify-content: center;
    }
    .patient-list-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
    }
    .patient-list-header .search-box {
        max-width: 100% !important;
        width: 100%;
    }
    .patient-list-header button {
        width: 100%;
        justify-content: center;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 24px 16px;
    }
    .login-header h2 {
        font-size: 1.5rem;
    }
    .card {
        padding: 16px !important;
    }
}
