/* =============================================== */
/* DESIGN SYSTEM V6 - MODERN & VIBRANT             */
/* =============================================== */
:root {
    /* --- Colors --- */
    /* Primary (Teacher - Vibrant Indigo/Violet) */
    --color-primary-hue: 255; /* Violet */
    --color-primary-600: hsl(var(--color-primary-hue), 85%, 68%); /* More Vibrant Violet */
    --color-primary-700: hsl(var(--color-primary-hue), 85%, 60%); /* Darker Violet */
    --color-primary-500: hsl(var(--color-primary-hue), 90%, 72%); /* Lighter Violet */
    --color-primary-100: hsl(var(--color-primary-hue), 95%, 96%); /* Lighter Violet Tint */
    --color-primary-50: hsl(var(--color-primary-hue), 98%, 98%);  /* Very Light Violet Tint */
    --color-primary-focus-ring: hsla(var(--color-primary-hue), 85%, 68%, 0.35);

    /* Primary (Admin - Vibrant Teal/Cyan) */
    --color-admin-hue: 175; /* Teal/Cyan */
    --color-admin-600: hsl(var(--color-admin-hue), 75%, 50%); /* More Vibrant Teal */
    --color-admin-700: hsl(var(--color-admin-hue), 75%, 42%); /* Darker Teal */
    --color-admin-500: hsl(var(--color-admin-hue), 80%, 55%); /* Lighter Teal */
    --color-admin-100: hsl(var(--color-admin-hue), 85%, 95%); /* Light Teal Tint */
    --color-admin-50: hsl(var(--color-admin-hue), 90%, 98%);  /* Very Light Teal Tint */
    --color-admin-focus-ring: hsla(var(--color-admin-hue), 75%, 50%, 0.35);

    /* Status & Accent (More vibrant and modern) */
    --color-success-hue: 150; /* Emerald Green */
    --color-success: hsl(var(--color-success-hue), 70%, 50%);
    --color-success-dark: hsl(var(--color-success-hue), 70%, 42%);
    --color-success-light: hsl(var(--color-success-hue), 75%, 95%);
    --color-danger-hue: 355; /* Modern Red */
    --color-danger: hsl(var(--color-danger-hue), 85%, 62%);
    --color-danger-dark: hsl(var(--color-danger-hue), 85%, 52%);
    --color-danger-light: hsl(var(--color-danger-hue), 90%, 96%);
    --color-warning-hue: 38; /* Vibrant Amber */
    --color-warning: hsl(var(--color-warning-hue), 95%, 58%);
    --color-warning-dark: hsl(var(--color-warning-hue), 95%, 50%);
    --color-warning-light: hsl(var(--color-warning-hue), 98%, 95%);
    --color-info-hue: 215; /* Bright Blue */
    --color-info: hsl(var(--color-info-hue), 90%, 62%);
    --color-info-dark: hsl(var(--color-info-hue), 90%, 52%);
    --color-info-light: hsl(var(--color-info-hue), 95%, 96%);

    /* Grays & Surfaces (Slightly warmer/neutral) */
    --color-gray-hue: 215;
    --color-gray-50: hsl(var(--color-gray-hue), 20%, 97%);
    --color-gray-100: hsl(var(--color-gray-hue), 25%, 94%);
    --color-gray-200: hsl(var(--color-gray-hue), 20%, 89%);
    --color-gray-300: hsl(var(--color-gray-hue), 18%, 80%);
    --color-gray-400: hsl(var(--color-gray-hue), 15%, 65%);
    --color-gray-500: hsl(var(--color-gray-hue), 15%, 50%);
    --color-gray-600: hsl(var(--color-gray-hue), 20%, 40%);
    --color-gray-700: hsl(var(--color-gray-hue), 22%, 30%);
    --color-gray-800: hsl(var(--color-gray-hue), 25%, 20%);
    --color-gray-900: hsl(var(--color-gray-hue), 28%, 15%);

    --color-surface: #ffffff;
    --color-background: var(--color-gray-50);
    --color-border: var(--color-gray-200);
    --color-border-hover: var(--color-gray-300);

    /* Text */
    --color-text-primary: var(--color-gray-800); /* Darker for better contrast */
    --color-text-secondary: var(--color-gray-600);
    --color-text-muted: var(--color-gray-400);
    --color-text-inverted: #ffffff;
    --color-text-link: var(--color-primary-600);
    --color-text-link-hover: var(--color-primary-700);

    /* --- Shadows (Slightly softer) --- */
    --shadow-sm: 0 1px 2px 0 hsla(var(--color-gray-hue), 20%, 50%, 0.06);
    --shadow-md: 0 3px 5px -1px hsla(var(--color-gray-hue), 20%, 50%, 0.07), 0 2px 3px -2px hsla(var(--color-gray-hue), 20%, 50%, 0.05);
    --shadow-lg: 0 8px 10px -3px hsla(var(--color-gray-hue), 20%, 50%, 0.07), 0 3px 6px -4px hsla(var(--color-gray-hue), 20%, 50%, 0.05);
    --shadow-xl: 0 15px 20px -5px hsla(var(--color-gray-hue), 20%, 50%, 0.07), 0 6px 8px -6px hsla(var(--color-gray-hue), 20%, 50%, 0.05);
    --shadow-inner: inset 0 1px 3px 0 hsla(var(--color-gray-hue), 20%, 50%, 0.06);

    /* --- Spacing & Radius --- */
    --radius-sm: 0.375rem;  /* 6px */
    --radius-md: 0.625rem;  /* 10px */
    --radius-lg: 1rem;    /* 16px */
    --radius-full: 9999px;

    /* --- Transitions --- */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    /* Tables */
    --table-row-zebra: hsl(var(--color-gray-hue), 20%, 97%);
}

/* ================================= */
/* BASE & TYPOGRAPHY                 */
/* ================================= */
html {
    font-size: 14px; /* Base font size */
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

/* Accessibility/UX preferences (applied via class on <html>) */
html.ux-font-large { font-size: 16px; }
html.ux-high-contrast {
    --color-text-primary: #111111;
    --color-text-secondary: #222222;
}
html.ux-reduce-motion, html.ux-reduce-motion * {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--color-background);
    /* Simplified background - better performance */
    background-image: linear-gradient(135deg, var(--color-primary-50) 0%, var(--color-background) 50%, var(--color-admin-50) 100%);
    color: var(--color-text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeSpeed;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text-primary);
}

h1 { font-size: 1.75rem; /* ~28px */ }
h2 { font-size: 1.5rem; /* ~24px */ }
h3 { font-size: 1.25rem; /* ~20px */ }

a {
    color: var(--color-text-link);
    text-decoration: none;
    transition: color var(--transition-fast);
}
a:hover {
    color: var(--color-text-link-hover);
    text-decoration: underline;
}

/* ================================= */
/* COMPONENTES REUTILIZÁVEIS         */
/* ================================= */

/* --- Botões --- */
.app-btn-primary, .app-btn-secondary, .app-btn-danger, .app-btn-success, .app-btn-warning {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem; /* Espaço entre ícone e texto */
    padding: 0.7rem 1.4rem; /* Padding ajustado */
    font-size: 0.875rem; /* 14px */
    font-weight: 600;
    border-radius: var(--radius-md); /* Cantos arredondados */
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    box-shadow: var(--shadow-sm); /* Sombra subtil */
    line-height: 1.4; /* Ensure text fits well */
}
.app-btn-primary:focus-visible, .app-btn-secondary:focus-visible, .app-btn-danger:focus-visible, .app-btn-success:focus-visible, .app-btn-warning:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-focus-ring), var(--shadow-md); /* Anel de foco */
}
.app-btn-primary:hover, .app-btn-secondary:hover, .app-btn-danger:hover, .app-btn-success:hover, .app-btn-warning:hover {
    transform: translateY(-1px); /* Ligeira elevação no hover */
    box-shadow: var(--shadow-md);
    filter: brightness(1.05); /* Ligeiramente mais claro */
}
.app-btn-primary:active, .app-btn-secondary:active, .app-btn-danger:active, .app-btn-success:active, .app-btn-warning:active {
    transform: scale(0.98) translateY(0); /* Efeito de pressionar */
    filter: brightness(0.95);
    box-shadow: var(--shadow-sm);
}

/* Primary Button - Modern gradient */
.app-btn-primary { 
    background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
    color: var(--color-text-inverted);
    position: relative;
    overflow: hidden;
}
.app-btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
    transition: left 0.5s;
}
.app-btn-primary:hover::before {
    left: 100%;
}
.app-btn-primary:hover { 
    background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-600));
}

/* Secondary Button - Enhanced border */
.app-btn-secondary { 
    background-color: var(--color-surface);
    color: var(--color-gray-700);
    border-color: var(--color-border);
    position: relative;
}
.app-btn-secondary:hover { 
    border-color: var(--color-primary-600);
    background: linear-gradient(135deg, var(--color-primary-50), var(--color-surface));
    color: var(--color-primary-700);
}

/* Danger Button - Vibrant gradient */
.app-btn-danger { 
    background: linear-gradient(135deg, var(--color-danger), var(--color-danger-dark));
    color: var(--color-text-inverted);
}
.app-btn-danger:hover { 
    background: linear-gradient(135deg, hsl(var(--color-danger-hue), 85%, 58%), var(--color-danger));
}

/* Success Button - Fresh gradient */
.app-btn-success { 
    background: linear-gradient(135deg, var(--color-success), var(--color-success-dark));
    color: var(--color-text-inverted);
}
.app-btn-success:hover { 
    background: linear-gradient(135deg, hsl(var(--color-success-hue), 70%, 46%), var(--color-success));
}

/* Warning Button - Warm gradient */
.app-btn-warning { 
    background: linear-gradient(135deg, var(--color-warning), var(--color-warning-dark));
    color: var(--color-gray-900);
    font-weight: 700;
}
.app-btn-warning:hover { 
    background: linear-gradient(135deg, hsl(var(--color-warning-hue), 95%, 54%), var(--color-warning));
}

/* Disabled State */
.app-btn-primary:disabled, .app-btn-secondary:disabled, .app-btn-danger:disabled, .app-btn-success:disabled, .app-btn-warning:disabled {
    opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; filter: none;
}
/* Button text size adjustments */
.app-btn-primary.text-sm, .app-btn-secondary.text-sm, .app-btn-danger.text-sm, .app-btn-success.text-sm, .app-btn-warning.text-sm {
    padding: 0.5rem 1rem; /* Smaller padding for text-sm */
    font-size: 0.8rem; /* 12.8px */
}
.app-btn-primary.text-xs, .app-btn-secondary.text-xs, .app-btn-danger.text-xs, .app-btn-success.text-xs, .app-btn-warning.text-xs {
    padding: 0.35rem 0.75rem; /* Even smaller padding for text-xs */
    font-size: 0.75rem; /* 12px */
}

/* --- Inputs e Formulários --- */
.app-input, select.app-input, textarea.app-input {
    width: 100%;
    padding: 0.75rem 1rem; /* Padding ligeiramente maior */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md); /* Raio consistente */
    background-color: var(--color-surface);
    color: var(--color-text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: var(--shadow-inner);
    font-size: 0.875rem; /* 14px */
}
.app-input:hover, select.app-input:hover, textarea.app-input:hover {
    border-color: var(--color-border-hover);
}
.app-input::placeholder, textarea.app-input::placeholder { color: var(--color-gray-400); opacity: 1; }
.app-input:focus, select.app-input:focus, textarea.app-input:focus {
    outline: none;
    border-color: var(--color-primary-600);
    box-shadow: 0 0 0 3px var(--color-primary-focus-ring), var(--shadow-inner); /* Anel de foco + sombra interior */
}
select.app-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.25em 1.25em;
    padding-right: 2.5rem;
}
.app-label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.8rem; /* 12.8px */
    font-weight: 500;
    color: var(--color-text-secondary);
}
input[type="checkbox"], input[type="radio"] {
    border-radius: var(--radius-sm);
    border-color: var(--color-border);
    color: var(--color-primary-600); /* Checkbox color */
}
input[type="checkbox"]:focus, input[type="radio"]:focus {
    ring: 2px;
    ring-offset: 1px;
    ring-color: var(--color-primary-focus-ring);
}

/* --- Cards e Títulos --- */
.app-card {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg); /* Raio maior */
    padding: 1.75rem; /* Padding aumentado */
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    position: relative;
    overflow: hidden;
}
.app-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary-600), var(--color-admin-600), var(--color-success));
    opacity: 0;
    transition: opacity var(--transition-normal);
}
.app-card:hover { 
    transform: translateY(-2px); 
    box-shadow: var(--shadow-xl);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.app-card:hover::after {
    opacity: 1;
}
.card-title {
    font-size: 1.25rem; /* 20px */
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--color-gray-100); /* Separador subtil */
    padding-bottom: 0.75rem;
}

/* --- Abas de Navegação Principal --- */
nav[aria-label="Tabs"] {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem; /* Gap aumentado */
    padding: 0.5rem;
    background: linear-gradient(135deg, var(--color-gray-100), var(--color-gray-50)); /* Gradiente sutil */
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-inner);
    margin-bottom: 2rem;
    border: 1px solid var(--color-border);
}
.tab-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem; /* Padding ajustado */
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
    border: none;
    background-color: transparent;
    cursor: pointer;
    position: relative;
}
.tab-button::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--color-primary-600), var(--color-admin-600));
    transform: translateX(-50%);
    transition: width var(--transition-normal);
    border-radius: 2px;
}
.tab-button:hover {
    color: var(--color-text-primary);
    background: linear-gradient(135deg, hsla(var(--color-primary-hue), 80%, 96%, 0.5), transparent); /* Hover com gradiente */
}
.tab-button:focus-visible { 
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-focus-ring), var(--shadow-sm);
    background-color: var(--color-surface);
}
.tab-button.active {
    color: var(--color-primary-700);
    background: linear-gradient(135deg, var(--color-surface), var(--color-primary-50));
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}
.tab-button.active::before {
    width: 70%;
}
.tab-button svg {
    width: 1.2em; /* Ícone ligeiramente maior */
    height: 1.2em;
    opacity: 0.9;
    transition: all var(--transition-fast);
}
.tab-button:hover svg {
    transform: scale(1.1);
}
.tab-button.active svg {
    color: var(--color-primary-600);
    opacity: 1;
}

/* --- Abas de Navegação Secundária (Subtabs) --- */
.subtab-nav {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1.5rem;
}
.subtab-button {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}
.subtab-button:hover {
    color: var(--color-text-primary);
}
.subtab-button.active {
    color: var(--color-primary-600);
    border-bottom-color: var(--color-primary-600);
    font-weight: 600;
}
.subtab-button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-focus-ring); border-radius: 6px; }
.subtab-content { display: none; }
.subtab-content.active { display: block; }

/* Settings subtab buttons/contents (mirror subtab styles) */
.settings-subtab-button {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}
.settings-subtab-button:hover { color: var(--color-text-primary); }
.settings-subtab-button.active {
    color: var(--color-primary-600);
    border-bottom-color: var(--color-primary-600);
    font-weight: 600;
}
.settings-subtab-button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-focus-ring); border-radius: 6px; }
.settings-subtab-content { display: none; }
.settings-subtab-content.active { display: block; }

/* Generic section container used inside settings tabs */
.settings-section {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}


/* ================================= */
/* COMPONENTES ESPECÍFICOS           */
/* ================================= */

/* --- Toast e Modais --- */
.toast {
    visibility: hidden; min-width: 280px; margin-left: -140px;
    background-color: hsla(var(--color-gray-hue), 25%, 20%, 0.95); /* Mais escuro, ligeiramente transparente */
    backdrop-filter: blur(2px);
    color: var(--color-text-inverted); text-align: center;
    border-radius: var(--radius-md); padding: 1rem 1.5rem; position: fixed;
    z-index: 9999; left: 50%; bottom: 40px; opacity: 0; box-shadow: var(--shadow-xl);
    transition: opacity var(--transition-normal), transform var(--transition-normal), visibility 0s var(--transition-normal);
    transform: translateY(20px) scale(0.98); /* Começa ligeiramente mais baixo e menor */
    font-size: 0.875rem;
}
.toast.show {
    visibility: visible; opacity: 1; transform: translateY(0) scale(1);
    transition-delay: 0s;
}
.modal-overlay {
    position: fixed; inset: 0;
    background-color: hsla(var(--color-primary-hue), 10%, 10%, 0.6); /* Overlay mais escuro */
    backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center;
    padding: 1.5rem; z-index: 5000; opacity: 0; visibility: hidden;
    transition: opacity var(--transition-normal), visibility 0s var(--transition-normal);
}
.modal-overlay.show { opacity: 1; visibility: visible; transition-delay: 0s; }
.modal-content {
    background: var(--color-surface); padding: 2rem; border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl); max-height: 90vh; overflow-y: auto;
    width: 95%; /* Adjust width */
    max-width: 600px; /* Default max width */
    transform: scale(0.95) translateY(15px); /* Começa menor e mais baixo */
    opacity: 0; transition: transform var(--transition-normal), opacity var(--transition-normal);
}
/* Specific max-widths for different modals */
.modal-content.max-w-lg { max-width: 512px; }
.modal-content.max-w-xl { max-width: 576px; }
.modal-content.max-w-2xl { max-width: 672px; }
.modal-content.max-w-3xl { max-width: 768px; }
.modal-content.max-w-4xl { max-width: 896px; }

.modal-overlay.show .modal-content { transform: scale(1) translateY(0); opacity: 1; }

/* --- Drag & Drop (Schedule Editor) - shared styles --- */
.drop-zone {
    min-height: 96px;
    border: 2px dashed transparent;
    border-radius: var(--radius-lg);
    transition: background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.drop-zone.drag-over {
    background-color: var(--color-gray-100);
    border-color: var(--color-primary-600);
    box-shadow: var(--shadow-inner);
}
.activity-slot {
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
}
.activity-slot.grabbing {
    cursor: grabbing;
    opacity: 0.9;
    box-shadow: var(--shadow-lg);
}

/* --- Tabelas Genéricas (Usando Tailwind como base) --- */
.w-full.text-left { /* Aplicado via Tailwind, mas podemos refinar */
    border-collapse: separate; border-spacing: 0; width: 100%;
    border: 1px solid var(--color-border); /* Adiciona borda à tabela */
    border-radius: var(--radius-md); /* Adiciona raio à tabela */
    overflow: hidden; /* Garante que o raio se aplica */
}
.table-sticky thead th { position: sticky; top: 0; z-index: 2; }
.table-zebra tbody tr:nth-child(odd) td { background-color: var(--table-row-zebra); }
.list-zebra > * { border-radius: var(--radius-md); }
.list-zebra > *:nth-child(odd) { background-color: var(--table-row-zebra); }
.w-full.text-left th {
    background-color: var(--color-gray-50); font-weight: 600; /* Headers mais fortes */
    padding: 0.85rem 1.1rem; border-bottom: 2px solid var(--color-border); /* Borda inferior mais espessa */
    color: var(--color-gray-700); text-transform: none; /* Sem maiúsculas */
    font-size: 0.8rem; letter-spacing: 0.02em; text-align: left;
}
.w-full.text-left td {
    padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--color-gray-100);
    font-size: 0.875rem; color: var(--color-text-secondary);
    transition: background-color var(--transition-fast);
}
.w-full.text-left tbody tr:hover td { background-color: var(--color-primary-50); } /* Usa primary tint muito leve para hover */
.w-full.text-left tbody tr:last-child td { border-bottom: none; } /* Remove borda na última linha */

/* --- Skeleton Loaders --- */
.skeleton { position: relative; overflow: hidden; background: linear-gradient(90deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0.12) 37%, rgba(0,0,0,0.06) 63%); background-size: 400% 100%; animation: skeleton-loading 1.2s ease-in-out infinite; border-radius: var(--radius-md); }
.skeleton-line { height: 0.9rem; border-radius: var(--radius-sm); background: rgba(0,0,0,0.08); }
@keyframes skeleton-loading { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* --- Grelha de Planificação (Visualização AEC) --- */
.plan-table {
    border: 1px solid var(--color-border); border-collapse: separate; border-spacing: 0;
    border-radius: var(--radius-md); overflow: hidden;
}
.plan-table td, .plan-table th {
    border-bottom: 1px solid var(--color-border); border-right: 1px solid var(--color-border);
    text-align: center; font-size: 0.8rem; /* Ligeiramente maior */
}
.plan-table th {
    background-color: var(--color-gray-50); font-weight: 600; padding: 0.6rem;
    color: var(--color-text-secondary);
}
.plan-table td:last-child, .plan-table th:last-child { border-right: none; }
.plan-table tr:last-child td { border-bottom: none; }
.plan-table .lesson-header { /* Cabeçalho Hora/Disciplina */
    text-align: left; font-weight: 600; min-width: 150px; position: sticky; left: 0;
    background-color: var(--color-gray-50); z-index: 10; padding: 0.7rem; font-size: 0.85rem;
    border-right: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border);
}
.plan-table .weekend-day { background-color: var(--color-gray-100); }
.plan-table .holiday-day { background-color: var(--color-danger-light); } /* Usa danger light */
.plan-table .editable-cell {
    position: relative; word-break: break-word; min-width: 130px; height: 110px;
    padding: 0.5rem; text-align: left; vertical-align: top; cursor: pointer;
    transition: box-shadow var(--transition-fast), background-color var(--transition-fast);
    font-size: 0.8rem; line-height: 1.4; background-clip: padding-box;
}
.plan-table .editable-cell:hover {
    box-shadow: inset 0 0 0 2px var(--color-primary-600);
    background-color: var(--color-primary-50); /* Primary tint muito leve no hover */
    z-index: 5;
}
.plan-table .editable-cell .cell-content {
    overflow: hidden; display: -webkit-box; -webkit-line-clamp: 5; /* Permite mais linhas */
    -webkit-box-orient: vertical; max-height: calc(1.4 * 0.8rem * 5);
}
.plan-table .editable-cell .edit-btn {
    position: absolute; bottom: 5px; right: 5px; padding: 3px; background-color: rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-sm); opacity: 0; transition: opacity var(--transition-fast);
    border: 1px solid var(--color-gray-200);
}
.plan-table .editable-cell:hover .edit-btn { opacity: 1; }

/* --- Indicador de estado de gravação --- */
.save-status {
    font-size: 0.75rem; /* Ligeiramente maior */ font-weight: 500; color: var(--color-text-muted);
    transition: all var(--transition-normal); opacity: 0; margin-left: 0.5rem;
    display: inline-flex; align-items: center; gap: 0.25rem;
}
.save-status.visible { opacity: 1; }
.save-status.saved::before { content: '✓'; color: var(--color-success); font-weight: bold; }
.save-status.error::before { content: '⚠'; color: var(--color-danger); font-weight: bold; }
.save-status.saved { color: var(--color-success); }
.save-status.error { color: var(--color-danger); }

/* --- Geral --- */
#pdf-container { display: none; } /* Container para gerar PDF */
#app-logo-footer { display: none; } /* Logo para PDF */
/* Reduce fixed watermark logo size slightly for better balance */
#app-watermark { width: 96px !important; }
/* Loading Overlay */
#loading-overlay { display: none; /* Controlado por JS */ }
#loading-overlay svg { width: 3rem; height: 3rem; color: var(--color-primary-600); }
#loading-overlay p { color: var(--color-text-secondary); }

/* --- Calendário (Livro Ponto e Vista Semanal AEC) --- */
.calendar-grid {
    display: grid; grid-template-columns: auto repeat(7, 1fr); gap: 1px;
    background-color: var(--color-border); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); overflow: hidden; /* Aplica raio */
}
.calendar-grid > div { background-color: var(--color-surface); padding: 0.6rem; }
.day-header {
    text-align: center; font-weight: 600; font-size: 0.85rem;
    background-color: var(--color-gray-50) !important; padding: 0.7rem 0.5rem !important; /* Ajusta padding */
}
.time-labels { grid-column: 1 / 2; grid-row: 2 / -1; display: flex; flex-direction: column; background-color: var(--color-gray-50); }
.day-columns-container { grid-column: 2 / -1; grid-row: 2 / -1; display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.day-column { position: relative; min-height: 500px; display: flex; flex-direction: column; }
.time-slot {
    height: 60px; /* Altura padrão do slot */ border-bottom: 1px dashed var(--color-gray-100);
    position: relative; font-size: 0.75rem; color: var(--color-text-muted);
}
.time-labels .time-slot span { position: absolute; top: -0.6em; right: 0.6rem; background-color: var(--color-gray-50); padding: 0 2px; }
.day-column .time-slot:last-child { border-bottom: none; }
.lesson-card {
    position: absolute; left: 3px; right: 3px; background-color: var(--color-primary-100);
    border: 1px solid var(--color-primary-600); border-left-width: 3px; /* Adiciona borda esquerda mais espessa */
    border-radius: var(--radius-sm); padding: 0.4rem 0.6rem; font-size: 0.75rem;
    overflow: hidden; cursor: pointer; transition: all var(--transition-fast); z-index: 1;
    display: flex; flex-direction: column; color: var(--color-gray-800);
}
.lesson-card:hover { filter: brightness(0.97); z-index: 2; box-shadow: var(--shadow-lg); border-color: var(--color-primary-700); }
.lesson-card strong { color: var(--color-gray-900); } /* Garante texto forte escuro */

/* --- Tabela CAF --- */
.caf-plan-table { min-width: 800px; /* Garante largura mínima */ }
.caf-plan-table textarea { height: 120px; font-size: 0.8rem; }
.caf-plan-table th, .caf-plan-table td { border-color: var(--color-border); padding: 0.6rem; }
.caf-plan-table thead th { background-color: var(--color-gray-100); }
.caf-plan-table tbody th { background-color: var(--color-gray-50); width: 150px; }

/* =============================================== */
/* ESTILOS ESPECÍFICOS PARA O PAINEL DE ADMIN      */
/* =============================================== */
body.admin-theme {
    /* Override primary colors for Admin */
    --color-primary-hue: var(--color-admin-hue);
    --color-primary-600: var(--color-admin-600);
    --color-primary-700: var(--color-admin-700);
    --color-primary-100: var(--color-admin-100);
    --color-primary-50: var(--color-admin-50);
    --color-primary-focus-ring: var(--color-admin-focus-ring);
    --color-background: var(--color-gray-100); /* Fundo ligeiramente mais escuro para Admin */
    --color-text-link: var(--color-primary-600);
    --color-text-link-hover: var(--color-primary-700);
}
.admin-theme .app-btn-primary { background-color: var(--color-primary-600); }
.admin-theme .app-btn-primary:hover { background-color: var(--color-primary-700); }
.admin-theme .app-input:focus, .admin-theme select.app-input:focus, .admin-theme textarea.app-input:focus { border-color: var(--color-primary-600); box-shadow: 0 0 0 3px var(--color-primary-focus-ring), var(--shadow-inner); }
.admin-theme .tab-button.active { color: var(--color-primary-700); }
.admin-theme .tab-button.active svg { color: var(--color-primary-600); }
.admin-theme #loading-overlay svg { color: var(--color-primary-600); }
.admin-theme nav[aria-label="Tabs"] { background-color: var(--color-surface); } /* Fundo branco para abas */

/* --- Admin Sidebar Navigation (vertical on large screens) --- */
.admin-side-nav .nav-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
@media (min-width: 1024px) {
    .admin-side-nav nav[aria-label="Tabs"] {
        display: flex;
        flex-direction: column;
        gap: 0.4rem;
        padding: 0.75rem;
        margin-bottom: 2rem;
        background-color: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
    }
    .admin-side-nav .tab-button {
        width: 100%;
        justify-content: flex-start;
    }
    .admin-side-nav .tab-button.active {
        background-color: var(--color-primary-50);
        border-left: 3px solid var(--color-primary-600);
    }
}

/* --- Grelha Visual do Horário (Admin) --- */
.schedule-grid-visual { border-collapse: separate; border-spacing: 0; width: 100%; border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; table-layout: fixed; }
.schedule-grid-visual th, .schedule-grid-visual td { border-bottom: 1px solid var(--color-border); border-right: 1px solid var(--color-border); text-align: center; vertical-align: top; padding: 0; /* Remove padding */ }
.schedule-grid-visual th:last-child, .schedule-grid-visual td:last-child { border-right: none; }
.schedule-grid-visual tr:last-child td { border-bottom: none; }
.schedule-grid-visual th { background-color: var(--color-gray-50); font-weight: 600; padding: 0.75rem 0.5rem; font-size: 0.875rem; }
.schedule-grid-visual td { height: 300px; position: relative; }
.schedule-day-content { padding: 0.5rem; height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 0.25rem; }
.schedule-slot { background-color: var(--color-primary-100); border: 1px solid var(--color-primary-600); border-left-width: 3px; border-radius: var(--radius-sm); padding: 0.3rem 0.5rem; font-size: 0.75rem; text-align: left; margin-bottom: 0.25rem; cursor: pointer; }
.schedule-slot strong { color: var(--color-gray-900); display: block; margin-bottom: 0.1rem; pointer-events: none; }
.schedule-slot span { color: var(--color-gray-600); display: block; font-size: 0.7rem; pointer-events: none; }
.schedule-slot-caf { background-color: var(--color-warning-light); border-color: var(--color-warning); } /* Amarelo para CAF */
.schedule-slot-other { background-color: var(--color-gray-100); border-color: var(--color-gray-300); } /* Cinza para Outro */
.edit-day-btn { position: absolute; top: 4px; right: 4px; padding: 2px; border-radius: 50%; background-color: rgba(255,255,255,0.7); border: 1px solid var(--color-border); opacity: 0.6; transition: opacity 0.2s; cursor: pointer; }
.schedule-grid-visual td:hover .edit-day-btn { opacity: 1; }
/* Botão apagar no modal de edição do dia */
.delete-activity-btn { font-size: 1.2rem; line-height: 1; color: var(--color-danger); opacity: 0.7; transition: opacity 0.2s; background: none; border: none; padding: 0.25rem; cursor: pointer; }
.delete-activity-btn:hover { opacity: 1; }
.edit-activity-btn { background: none; border: none; padding: 0.25rem; cursor: pointer; color: var(--color-gray-500); }
.edit-activity-btn:hover { color: var(--color-primary-600); }

/* Handsontable - Estilos gerais (aplicam-se ao Admin e Residente) */
.handsontable { font-size: 0.875rem !important; }
.handsontable th, .handsontable td { border-color: var(--color-border) !important; padding: 0.5rem 0.7rem !important; }
.handsontable th { background-color: var(--color-gray-100) !important; color: var(--color-text-secondary) !important; font-weight: 600 !important; }
.handsontable .htAutocompleteArrow { color: var(--color-text-secondary) !important; }
.handsontable .htCheckboxRendererInput input[type=checkbox]:checked + span:before { background: var(--color-primary-600) !important; border-color: var(--color-primary-600) !important; }
.handsontable .htDropdownMenu li:hover { background: var(--color-primary-100) !important; }
.handsontable td.current, .handsontable th.current { background-color: var(--color-primary-50) !important; } /* Usa primary tint 50 */
.handsontable td.htInvalid { background-color: var(--color-danger-light) !important; } /* Usa danger light */
.handsontable td.htDimmed { color: var(--color-text-muted) !important; }

/* =============================================== */
/* ESTILOS PARA EXPORTAÇÃO PDF (Mantidos)          */
/* =============================================== */
.pdf-page { width: 794px; padding: 40px; background: white; font-family: Arial, sans-serif; color: #333; box-sizing: border-box; }
.pdf-page.landscape { width: 1123px; }
.pdf-logbook .pdf-date-header { font-size: 16px; font-weight: bold; text-align: center; border-bottom: 1px solid #ccc; padding-bottom: 8px; margin-bottom: 15px; }
.pdf-logbook .pdf-lesson-card { border: 1px solid #ddd; border-radius: 6px; margin-bottom: 15px; overflow: hidden; }
.pdf-logbook .pdf-lesson-header { background-color: #f8f8f8; padding: 8px 12px; font-weight: bold; display: flex; justify-content: space-between; font-size: 12px; border-bottom: 1px solid #eee; }
.pdf-logbook .pdf-section { padding: 10px 12px; }
.pdf-logbook .pdf-section-title { font-weight: bold; margin-bottom: 4px; font-size: 11px; color: #555; }
.pdf-logbook .pdf-section p { margin: 0; font-size: 10px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.pdf-report .pdf-report-header { text-align: center; margin-bottom: 30px; border-bottom: 1px solid #eee; padding-bottom: 15px; }
.pdf-report h1 { font-size: 18px; margin-bottom: 10px; color: #222; }
.pdf-report .pdf-report-subheader { display: flex; justify-content: space-around; font-size: 10px; padding: 8px 0; color: #555; }
.pdf-report .pdf-report-section { margin-bottom: 25px; }
.pdf-report h2 { font-size: 14px; font-weight: bold; border-bottom: 1px solid #eee; padding-bottom: 6px; margin-bottom: 10px; color: #444; }
.pdf-report p { font-size: 11px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; text-align: justify; }
.pdf-caf-page { padding: 30px; font-family: Arial, sans-serif; color: #333; font-size: 8pt; width: 100%; box-sizing: border-box; }
.pdf-caf-header-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; font-size: 9pt; border: 1px solid #ccc; }
.pdf-caf-header-table td { padding: 6px 10px; vertical-align: middle; border: 1px solid #ccc; }
.pdf-caf-header-table strong { font-weight: bold; color: #444; }
.pdf-caf-theme-row td { text-align: center; padding-top: 10px; padding-bottom: 10px; font-size: 10pt; background-color: #f8f8f8; font-weight: bold; color: #333; }
.pdf-caf-main-table { width: 100%; border-collapse: collapse; margin-top: 10px; table-layout: fixed; border: 1px solid #555; }
.pdf-caf-main-table th, .pdf-caf-main-table td { border: 1px solid #999; padding: 8px 10px; vertical-align: top; text-align: left; font-size: 9pt; word-wrap: break-word; height: 120px; line-height: 1.5; }
.pdf-caf-main-table thead th { font-weight: bold; text-align: center; background-color: #e0e0e0; font-size: 10pt; color: #333; height: auto; vertical-align: middle; padding: 8px; }
.pdf-caf-main-table tbody th { font-weight: bold; background-color: #f0f0f0; width: 14%; font-size: 10pt; text-align: center; vertical-align: middle; color: #444; height: auto; }
.pdf-caf-main-table td { width: 17.2%; }
.pdf-caf-main-table td ul { list-style-position: inside; margin: 0; padding-left: 5px; list-style-type: disc; }
.pdf-caf-main-table td li { margin-bottom: 4px; line-height: 1.5; }

/* Modern Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--color-gray-100); border-radius: 10px; }
::-webkit-scrollbar-thumb { background: var(--color-gray-300); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-gray-400); }

/* ================================= */
/* DARK THEME                        */
/* ================================= */
html.theme-dark {
  --color-background: #0b1220;
  --color-surface: #0f172a;
  --color-border: #1e293b;
  --color-border-hover: #334155;
  --color-text-primary: #e5e7eb;
  --color-text-secondary: #cbd5e1;
  --color-text-muted: #94a3b8;
  --color-gray-50: #111827;
  --color-gray-100: #0f172a;
  --color-gray-200: #1f2937;
  --color-gray-300: #374151;
  --color-gray-400: #4b5563;
  --color-gray-500: #6b7280;
  --color-gray-600: #9ca3af;
  --color-gray-700: #e5e7eb;
  --color-gray-800: #f3f4f6;
  --color-gray-900: #f9fafb;
  --table-row-zebra: rgba(255,255,255,0.03);
}

/* ================================= */
/* PRO THEME (glass, gradients)      */
/* ================================= */
html.theme-pro {
  /* Slightly rounder, deeper shadows */
  --radius-md: 0.8rem;
  --radius-lg: 1.15rem;
  --shadow-sm: 0 2px 6px 0 hsla(var(--color-gray-hue), 20%, 50%, 0.10);
  --shadow-md: 0 8px 18px -6px hsla(var(--color-gray-hue), 20%, 50%, 0.18), 0 4px 8px -6px hsla(var(--color-gray-hue), 20%, 50%, 0.12);
  --shadow-lg: 0 14px 28px -10px hsla(var(--color-gray-hue), 20%, 50%, 0.22), 0 8px 16px -12px hsla(var(--color-gray-hue), 20%, 50%, 0.14);
  --shadow-xl: 0 24px 48px -18px hsla(var(--color-gray-hue), 20%, 50%, 0.28), 0 12px 22px -14px hsla(var(--color-gray-hue), 20%, 50%, 0.16);
}

html.theme-pro body {
  /* Slightly richer, professional background accents */
  background-image:
    radial-gradient(1200px 520px at -10% -10%, hsla(var(--color-primary-hue), 95%, 98%, 0.9), transparent 60%),
    radial-gradient(900px 460px at 110% -5%, hsla(var(--color-admin-hue), 85%, 97%, 0.9), transparent 55%),
    linear-gradient(180deg, var(--color-background), var(--color-background));
}

/* Glassy header */
html.theme-pro header {
  background-color: rgba(255,255,255,0.65) !important;
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid rgba(148,163,184,0.35) !important; /* slate-300 */
  box-shadow: 0 10px 25px -20px rgba(0,0,0,0.35);
}
html.theme-dark.theme-pro header {
  background-color: rgba(15,23,42,0.70) !important; /* slate-900 */
  border-bottom-color: #1e293b !important; /* slate-800 */
}

/* Pro Cards with gradient borders and subtle glass */
html.theme-pro .app-card {
  position: relative;
  border: 1px solid transparent;
  background:
    linear-gradient(0deg, rgba(255,255,255,0.96), rgba(255,255,255,0.96)) padding-box,
    linear-gradient(135deg, hsla(var(--color-primary-hue), 100%, 65%, 0.28), hsla(var(--color-admin-hue), 75%, 58%, 0.28)) border-box;
  backdrop-filter: saturate(140%) blur(2px);
}
html.theme-dark.theme-pro .app-card {
  background:
    linear-gradient(0deg, rgba(15,23,42,0.92), rgba(15,23,42,0.92)) padding-box,
    linear-gradient(135deg, hsla(var(--color-primary-hue), 90%, 65%, 0.35), hsla(var(--color-admin-hue), 80%, 50%, 0.35)) border-box;
}

/* Tabs container polish */
html.theme-pro nav[aria-label="Tabs"] {
  background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(255,255,255,0.85));
  border: 1px solid rgba(148,163,184,0.35);
  box-shadow: var(--shadow-sm);
}
html.theme-dark.theme-pro nav[aria-label="Tabs"] {
  background: linear-gradient(180deg, rgba(15,23,42,0.92), rgba(15,23,42,0.88));
  border-color: #1e293b;
}
html.theme-pro .tab-button.active {
  border: 1px solid rgba(148,163,184,0.35);
  box-shadow: var(--shadow-sm);
}

/* Buttons with premium gradient and shine */
html.theme-pro .app-btn-primary,
html.theme-pro .app-btn-success {
  position: relative;
  overflow: hidden;
}
html.theme-pro .app-btn-primary {
  background-image: linear-gradient(135deg, var(--color-primary-600), hsl(var(--color-primary-hue), 85%, 60%));
  box-shadow: 0 12px 24px -12px hsla(var(--color-primary-hue), 80%, 55%, 0.35), 0 6px 12px -8px rgba(0,0,0,0.18);
}
html.theme-pro .app-btn-primary:hover {
  transform: translateY(-2px);
  filter: none;
}
html.theme-pro .app-btn-primary:active { transform: translateY(0); }
html.theme-pro .app-btn-primary::after {
  content: "";
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(120deg, rgba(255,255,255,0.0) 0%, rgba(255,255,255,0.35) 50%, rgba(255,255,255,0.0) 100%);
  transform: translateX(-150%);
  transition: transform 600ms ease;
}
html.theme-pro .app-btn-primary:hover::after { transform: translateX(150%); }

html.theme-pro .app-btn-secondary {
  background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(255,255,255,0.82));
  border-color: rgba(148,163,184,0.5);
}
html.theme-dark.theme-pro .app-btn-secondary {
  background: linear-gradient(180deg, rgba(30,41,59,0.92), rgba(30,41,59,0.88));
  border-color: #334155;
}

/* Modals slightly glassy */
html.theme-pro .modal-content {
  border: 1px solid rgba(148,163,184,0.3);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.96));
  backdrop-filter: saturate(130%) blur(6px);
}
html.theme-dark.theme-pro .modal-content {
  border-color: #1e293b;
  background: linear-gradient(180deg, rgba(15,23,42,0.96), rgba(15,23,42,0.94));
}

/* Toast polish */
html.theme-pro .toast {
  border: 1px solid rgba(148,163,184,0.3);
  box-shadow: var(--shadow-xl);
}

/* =============================================== */
/* PERFORMANCE OPTIMIZATIONS                       */
/* =============================================== */

/* Content visibility for hidden sections - improves initial render */
[id^="tab-content-"]:not(.hidden),
.subtab-content:not(.active) {
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
}

/* Optimize hidden elements */
.hidden, [hidden] {
    display: none !important;
    content-visibility: hidden;
}

/* Reduce paint on scrollable areas */
.overflow-y-auto, .overflow-x-auto {
    will-change: scroll-position;
    contain: strict;
}

/* GPU acceleration for modals */
.modal.show .modal-content {
    transform: translateZ(0);
}