/* ============================================
   Categories Page Styles
   ============================================ */

.categories-page {
    max-width: 800px;
    padding-bottom: 100px;
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    flex: 1;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.btn-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--card-bg);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.btn-back:hover {
    background: var(--hover-bg);
    transform: scale(1.05);
}

.btn-header-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-header-action:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.btn-header-action i {
    width: 20px;
    height: 20px;
}

/* Stats Row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    flex-shrink: 0;
}

.stat-icon i {
    width: 20px;
    height: 20px;
    color: white;
}

.stat-icon.despesa {
    background: linear-gradient(135deg, var(--danger), var(--danger-light));
}

.stat-icon.receita {
    background: linear-gradient(135deg, var(--success), var(--success-light));
}

.stat-icon.total {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Tabs Container */
.tabs-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Tabs */
.tabs {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    padding: 4px;
    background: var(--bg-secondary);
    border-radius: 12px;
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1rem;
    background: transparent;
    border: none;
    border-radius: 10px;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab i {
    width: 18px;
    height: 18px;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}

/* Hierarchical Categories List */
.categories-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.category-group {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.category-group:hover {
    box-shadow: var(--shadow-md);
}

.category-parent {
    display: flex;
    align-items: center;
    padding: 1rem;
    gap: 1rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.category-parent:hover {
    background: var(--hover-bg);
}

.category-parent.inactive {
    opacity: 0.5;
}

.expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.expand-btn i {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

.expand-btn.expanded i {
    transform: rotate(90deg);
}

.expand-btn:hover {
    background: var(--primary);
    color: white;
}

.expand-btn.no-children {
    visibility: hidden;
}

.category-icon-sm {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
}

.category-icon-sm i,
.category-icon-sm svg {
    width: 22px;
    height: 22px;
    color: white;
    stroke: white;
}

.category-details {
    flex: 1;
    min-width: 0;
}

.category-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
}

.category-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.category-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
}

.category-badge.sub {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.parent-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.category-parent:hover .parent-actions {
    opacity: 1;
}

.parent-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.parent-action-btn i {
    width: 16px;
    height: 16px;
}

.parent-action-btn:hover {
    background: var(--hover-bg);
}

.parent-action-btn.add:hover {
    color: var(--success);
}

.parent-action-btn.edit:hover {
    color: var(--primary);
}

.parent-action-btn.delete:hover {
    color: var(--danger);
}

/* Sub-categories */
.subcategories {
    max-height: 0;
    overflow: hidden;
    padding: 0 1rem 0 1rem;
    margin-left: 2.25rem;
    border-left: 2px solid var(--primary-light);
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
}

.subcategories.expanded {
    max-height: 1000px;
    opacity: 1;
    padding: 0.5rem 1rem 0.75rem 1rem;
}

.subcategory-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    gap: 0.75rem;
    border-radius: 10px;
    transition: background 0.15s ease;
    position: relative;
}

/* Connection line for subcategory items */
.subcategory-item::before {
    content: '';
    position: absolute;
    left: -1rem;
    top: 50%;
    width: 0.75rem;
    height: 2px;
    background: var(--primary-light);
}

.subcategory-item:hover {
    background: var(--bg-secondary);
}

.subcategory-item.inactive {
    opacity: 0.5;
}

.subcategory-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    flex-shrink: 0;
}

.subcategory-icon i,
.subcategory-icon svg {
    width: 18px;
    height: 18px;
    color: white;
    stroke: white;
}

.subcategory-details {
    flex: 1;
    min-width: 0;
}

.subcategory-name {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}

.subcategory-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.subcategory-item:hover .subcategory-actions {
    opacity: 1;
}

/* View Toggle */
.view-toggle {
    display: flex;
    gap: 0.25rem;
    padding: 4px;
    background: var(--bg-secondary);
    border-radius: 10px;
    margin-bottom: 1rem;
}

.view-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.view-toggle-btn i {
    width: 18px;
    height: 18px;
}

.view-toggle-btn:hover {
    color: var(--text-primary);
}

.view-toggle-btn.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Category Card */
.category-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem 1rem;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.category-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.category-card.inactive {
    opacity: 0.5;
}

.category-card .card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.category-card:hover .card-actions {
    opacity: 1;
}

.card-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.card-action-btn i {
    width: 14px;
    height: 14px;
}

.card-action-btn:hover {
    background: var(--hover-bg);
}

.card-action-btn.edit:hover {
    color: var(--primary);
}

.card-action-btn.delete:hover {
    color: var(--danger);
}

.category-icon-wrapper {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    margin-bottom: 0.75rem;
    transition: transform 0.2s ease;
}

.category-card:hover .category-icon-wrapper {
    transform: scale(1.05);
}

.category-icon-wrapper i {
    width: 28px;
    height: 28px;
    color: white;
}

.category-icon-wrapper svg {
    width: 28px;
    height: 28px;
    stroke: white;
}

.category-card-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 0.25rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-card-count {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.category-card-status {
    position: absolute;
    bottom: 8px;
    left: 8px;
    font-size: 0.625rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--bg-secondary);
    color: var(--text-tertiary);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-state i {
    width: 64px;
    height: 64px;
    color: var(--text-tertiary);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Show Inactive Toggle */
.show-inactive-toggle {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

/* FAB */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 16px;
    box-shadow: var(--shadow-lg), 0 4px 12px rgba(59, 130, 246, 0.4);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 90;
}

.fab i {
    width: 24px;
    height: 24px;
}

.fab:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg), 0 6px 16px rgba(59, 130, 246, 0.5);
}

.fab:active {
    transform: scale(0.95);
}

@supports (bottom: env(safe-area-inset-bottom)) {
    .fab {
        bottom: calc(24px + env(safe-area-inset-bottom));
        right: calc(24px + env(safe-area-inset-right));
    }
}

/* Modal Styles */
.modal-small {
    max-width: 400px;
}

.modal-body {
    padding: 0 1.5rem 1.5rem;
}

.delete-warning {
    text-align: center;
}

.delete-warning i {
    width: 48px;
    height: 48px;
    color: var(--warning);
    margin-bottom: 1rem;
}

.delete-warning p {
    margin: 0 0 0.5rem;
    color: var(--text-primary);
}

.delete-warning .text-muted {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Type Selector */
.type-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.type-option {
    cursor: pointer;
}

.type-option input {
    display: none;
}

.type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    transition: all 0.2s ease;
}

.type-card i {
    width: 24px;
    height: 24px;
}

.type-card span {
    font-size: 0.875rem;
    font-weight: 600;
}

.type-option input:checked + .type-card {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

.type-card.despesa i {
    color: var(--danger);
}

.type-card.receita i {
    color: var(--success);
}

/* Icon Selector */
.icon-selector {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    max-height: 240px;
    overflow-y: auto;
}

.icon-option svg {
    width: 20px;
    height: 20px;
}

.icon-option {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--card-bg);
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.icon-option i,
.icon-option svg {
    width: 22px;
    height: 22px;
    color: var(--text-secondary);
}

.icon-option:hover {
    border-color: var(--border-color);
}

.icon-option.active {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

.icon-option.active i,
.icon-option.active svg {
    color: var(--primary);
}

/* Color Selector */
.color-selector {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.color-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.color-option {
    width: 32px;
    height: 32px;
    border: 3px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--card-bg);
}

input[type="color"]#categoryColor {
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: transparent;
}

/* Checkbox Group */
.checkbox-group {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 10px;
}

/* Form Hint */
.form-hint {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* Parent Category Select */
#parentCategory {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 0.9375rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.15s ease;
}

#parentCategory:focus {
    outline: none;
    border-color: var(--primary);
}

#parentCategory option {
    padding: 0.5rem;
}

#parentCategory optgroup {
    font-weight: 600;
    color: var(--text-primary);
}

/* Type Group Hidden State */
#typeGroup.hidden {
    display: none;
}

/* Inherited Type Badge */
.inherited-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.inherited-type-badge i {
    width: 16px;
    height: 16px;
}

.inherited-type-badge.despesa {
    color: var(--danger);
}

.inherited-type-badge.receita {
    color: var(--success);
}

/* Responsive Design */
@media (max-width: 640px) {
    .stats-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .stat-card {
        padding: 0.875rem;
    }

    .tabs-container {
        flex-direction: column;
        gap: 0.75rem;
    }

    .tabs {
        width: 100%;
    }

    .view-toggle {
        align-self: flex-end;
    }

    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .category-card {
        padding: 1rem 0.75rem;
    }

    .category-icon-wrapper {
        width: 48px;
        height: 48px;
    }

    .category-icon-wrapper i,
    .category-icon-wrapper svg {
        width: 24px;
        height: 24px;
    }

    .category-parent {
        flex-wrap: wrap;
    }

    .parent-actions {
        opacity: 1;
        width: 100%;
        justify-content: flex-end;
        margin-top: 0.5rem;
    }

    .subcategory-actions {
        opacity: 1;
    }

    .icon-selector {
        grid-template-columns: repeat(5, 1fr);
    }

    .icon-option {
        width: 40px;
        height: 40px;
    }

    .fab {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
}

@media (max-width: 400px) {
    .categories-grid {
        grid-template-columns: 1fr 1fr;
    }

    .type-selector {
        grid-template-columns: 1fr;
    }
}
