:root {
    color-scheme: light dark;
    --bg: #f8f9fc;
    --panel: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --accent: #667eea;
    --accent-hover: #5568d3;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --info: #3b82f6;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #f8f9fc 0%, #e9ecf5 100%);
    color: var(--text);
    min-height: 100vh;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.topbar-logo {
    height: 50px;
    object-fit: contain;
}

.topbar-logo-link {
    text-decoration: none;
    display: flex;
    align-items: center;
}

.topbar h1 {
    margin: 0;
    font-size: 1.5rem;
}

.subtitle {
    margin: 0.2rem 0 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.95rem;
}

/* User Profile Dropdown */
.user-profile {
    position: relative;
}

.profile-button {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.profile-button:hover {
    background: rgba(37, 99, 235, 0.05);
    border-color: var(--accent);
}

.profile-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.profile-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.profile-name {
    font-weight: 600;
    color: var(--text);
    font-size: 0.95rem;
}

.profile-role {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.dropdown-arrow {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.profile-button.active .dropdown-arrow {
    transform: rotate(180deg);
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    overflow: hidden;
}

.profile-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text);
    text-decoration: none;
    transition: background 0.2s ease;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-size: 0.95rem;
    font-family: inherit;
}

.dropdown-item:hover {
    background: rgba(37, 99, 235, 0.05);
}

.dropdown-item svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 0.25rem 0;
}

.dropdown-item.logout {
    color: var(--danger);
}

.dropdown-item.logout svg {
    color: var(--danger);
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 1.5rem;
    padding: 1.5rem 2rem 3rem;
    max-width: 1600px;
    margin: 0 auto;
}

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

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
    transition: all 0.3s ease;
}

.panel:hover {
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
}

.panel-large {
    grid-column: span 2;
}

@media (max-width: 1200px) {
    .panel-large {
        grid-column: span 1;
    }
}

.panel-form {
    position: sticky;
    top: 100px;
    height: fit-content;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.panel-header h2 {
    margin: 0 0 0.25rem 0;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.panel-subtitle {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Buttons */
button {
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 0.7rem 1.3rem;
    font-size: 0.95rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.25);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.35);
}

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

.btn-secondary {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-secondary:hover {
    border-color: var(--accent);
    background: rgba(102, 126, 234, 0.05);
    color: var(--accent);
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(102, 126, 234, 0.05);
}

.btn-icon.edit:hover {
    border-color: var(--info);
    color: var(--info);
    background: rgba(59, 130, 246, 0.05);
}

.btn-icon.reset:hover {
    border-color: var(--warning);
    color: var(--warning);
    background: rgba(245, 158, 11, 0.05);
}

.btn-icon.delete:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(239, 68, 68, 0.05);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

/* Legacy ghost button support */
.ghost {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 8px;
    padding: 0.4rem 0.9rem;
    font-size: 0.9rem;
}

.ghost:hover {
    border-color: var(--accent);
    background: rgba(102, 126, 234, 0.08);
}

.ghost.danger {
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.ghost.danger:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.4);
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
}

table, .modern-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

thead {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(102, 126, 234, 0.03) 100%);
}

thead th {
    text-align: left;
    font-weight: 700;
    padding: 1rem 1rem;
    color: var(--text);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

thead th.text-center {
    text-align: center;
}

tbody td {
    padding: 1rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.93rem;
    color: var(--text);
}

tbody td.text-center {
    text-align: center;
}

tbody tr {
    transition: background 0.2s ease;
}

tbody tr:hover {
    background: rgba(102, 126, 234, 0.03);
}

tbody tr:last-child td {
    border-bottom: none;
}

.user-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.status {
    border-radius: 12px;
    padding: 0.85rem 1.1rem;
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid;
}

.status.success {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border-color: rgba(16, 185, 129, 0.3);
}

.status.error {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border-color: rgba(239, 68, 68, 0.3);
}

.status.info {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
    border-color: rgba(59, 130, 246, 0.3);
}

.loading {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

.form {
    display: grid;
    gap: 1.25rem;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.93rem;
}

.field-group label {
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}

.field-group input,
.field-group select,
.field-group textarea {
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    font-size: 0.95rem;
    background: white;
    transition: all 0.2s ease;
    font-family: inherit;
}

.field-group textarea {
    resize: vertical;
    min-height: 80px;
}

.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.field-group small {
    color: var(--text-muted);
    font-size: 0.83rem;
    font-style: italic;
}

.field-group.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0;
}

.field-group.checkbox input {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

.field-group.checkbox label {
    margin: 0;
    cursor: pointer;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

#groups {
    min-height: 7.5rem;
}

#currentUser {
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

/* Admin Home Styles */
.admin-home {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.welcome-section {
    text-align: center;
    padding: 3rem 2rem;
    margin-bottom: 3rem;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-radius: 20px;
}

.welcome-section h2 {
    margin: 0 0 0.75rem 0;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
}

.welcome-section p {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-muted);
}

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.module-card {
    background: var(--panel);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.module-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--module-color-start), var(--module-color-end));
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
}

.module-card:hover::before {
    transform: scaleX(1);
}

.module-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    border-color: var(--module-color-start);
}

.module-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--module-color-start), var(--module-color-end));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.module-card:hover .module-icon {
    transform: scale(1.1) rotate(5deg);
}

.module-icon svg {
    width: 28px;
    height: 28px;
    color: white;
}

.module-content {
    flex: 1;
}

.module-content h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}

.module-content p {
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.module-stats {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-inactive {
    background: rgba(107, 114, 128, 0.1);
    color: var(--text-muted);
}

/* Info Box */
.info-box {
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    margin: 0.5rem 0;
}

.info-box svg {
    flex-shrink: 0;
    color: var(--info);
    margin-top: 0.2rem;
}

.info-box strong {
    color: var(--text);
    display: block;
    margin-bottom: 0.5rem;
}

.info-box ul {
    margin: 0.5rem 0 0 1.5rem;
    padding: 0;
}

.info-box li {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.info-box code {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: 'Courier New', monospace;
}

.stat-number {
    font-size: 1rem;
    font-weight: 700;
}

.module-arrow {
    width: 24px;
    height: 24px;
    color: var(--text-muted);
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.module-card:hover .module-arrow {
    opacity: 1;
    transform: translateX(0);
    color: var(--module-color-start);
}

/* Module Color Schemes */
.module-users {
    --module-color-start: #667eea;
    --module-color-end: #764ba2;
}

.module-groups {
    --module-color-start: #f093fb;
    --module-color-end: #f5576c;
}

.module-dashboards {
    --module-color-start: #4facfe;
    --module-color-end: #00f2fe;
}

.module-permissions {
    --module-color-start: #43e97b;
    --module-color-end: #38f9d7;
}

.module-logs {
    --module-color-start: #fa709a;
    --module-color-end: #fee140;
}

.module-settings {
    --module-color-start: #a8edea;
    --module-color-end: #fed6e3;
}

/* Quick Stats Section */
.quick-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

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

.stat-icon svg {
    width: 24px;
    height: 24px;
    color: white;
}

.stat-icon-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
}

.stat-icon-success {
    background: linear-gradient(135deg, var(--success), #059669);
}

.stat-icon-warning {
    background: linear-gradient(135deg, var(--warning), #d97706);
}

.stat-icon-info {
    background: linear-gradient(135deg, var(--info), #2563eb);
}

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

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

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

/* Responsive */
/* Modal de Confirmação */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

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

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

.modal-container {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 480px;
    width: 90%;
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

.modal-header {
    padding: 2rem 2rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.modal-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-icon-warning {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text);
    font-weight: 600;
}

.modal-body {
    padding: 0 2rem 1.5rem;
    text-align: center;
}

.modal-body p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.6;
    font-size: 1rem;
}

.modal-footer {
    padding: 1.5rem 2rem;
    background: var(--bg);
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.3);
}

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

/* Filters Container */
.filters-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    background: rgba(102, 126, 234, 0.02);
    border-radius: 10px;
    border: 1px dashed var(--border);
    min-height: 50px;
}

.filters-container:empty::before {
    content: 'Nenhum filtro configurado. Clique em "Adicionar Filtro" para começar.';
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.filter-item {
    display: grid;
    grid-template-columns: 1fr 2fr auto;
    gap: 0.75rem;
    align-items: start;
    padding: 0.75rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.filter-item:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.filter-field select,
.filter-field input {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 0.9rem;
    background: white;
    transition: all 0.2s ease;
}

.filter-field select:focus,
.filter-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.filter-remove {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1.4rem;
}

.filter-remove:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(239, 68, 68, 0.05);
}

.btn-sm {
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
}

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

    .quick-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .welcome-section h2 {
        font-size: 1.5rem;
    }

    .welcome-section p {
        font-size: 1rem;
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .modal-footer button {
        width: 100%;
    }

    .filter-item {
        grid-template-columns: 1fr;
    }

    .filter-remove {
        margin-top: 0;
    }
}
