/* ============================================================
   FinControl - Premium SaaS UI Design System
   Matching input_file_0.png exact layout and styling
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

:root {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #f5f3ff;
    
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    
    --sidebar-width: 250px;
    --header-height: 70px;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* App Wrapper */
.app-container {
    display: flex;
    width: 100vw;
    min-height: 100vh;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    padding-left: 8px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.brand-name {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.5px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.8px;
    text-transform: uppercase;
    margin: 20px 0 8px 12px;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-link:hover {
    background-color: var(--border-light);
    color: var(--text-primary);
}

.nav-link.active {
    background-color: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-link svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

.sidebar-user {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 4px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #334155;
    overflow: hidden;
}

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

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

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    font-size: 11px;
    color: var(--text-secondary);
}

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

.top-bar {
    height: var(--header-height);
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
}

.page-title-group h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.page-title-group p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.year-select {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #ffffff;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-danger {
    background: #ef4444;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Page Content Body */
.content-body {
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* Top Stat Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.stat-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

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

.stat-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.stat-card:hover .stat-icon-wrapper {
    transform: scale(1.08);
}

.stat-icon-purple { background: #f3e8ff; color: #9333ea; }
.stat-icon-blue   { background: #e0f2fe; color: #0284c7; }
.stat-icon-green  { background: #dcfce7; color: #16a34a; }
.stat-icon-amber  { background: #fef3c7; color: #d97706; }

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

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

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 2px 0;
}

.stat-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* Table Card Section */
.card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

.matrix-table th {
    background: #f8fafc;
    padding: 12px 14px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.matrix-table th.num, .matrix-table td.num {
    text-align: right;
}

.matrix-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-light);
    color: #334155;
    white-space: nowrap;
}

.matrix-table tr:hover td {
    background-color: #f8fafc;
}

.matrix-table td.category-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

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

.text-danger {
    color: #ef4444 !important;
    font-weight: 600;
}

.total-row th, .total-row td {
    background-color: #f1f5f9;
    font-weight: 700 !important;
    color: var(--text-primary);
    border-top: 2px solid var(--border-color);
}

.editable-cell {
    cursor: pointer;
    transition: background 0.15s;
}

.editable-cell:hover {
    background-color: #e0f2fe !important;
    color: var(--primary) !weight: 600;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.chart-card-body {
    padding: 20px;
    height: 280px;
    position: relative;
}

/* Footer */
.app-footer {
    margin-top: auto;
    padding: 20px 32px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-dialog {
    background: white;
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 440px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
}

.form-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-control {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    width: 100%;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Auth Pages (Login / Register / Checkout) */
.auth-body {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    color: white;
}

.auth-card {
    background: #ffffff;
    color: var(--text-primary);
    width: 100%;
    max-width: 420px;
    border-radius: var(--radius-lg);
    padding: 36px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
}

.badge-trial {
    background: #dcfce7;
    color: #15803d;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 16px;
}

/* ============================================================
   Mobile and Responsive Design Updates
   ============================================================ */

/* Desktop Brand styling helper */
.desktop-only {
    display: flex;
}

/* Mobile Header */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 99;
}

.mobile-menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 105;
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
}

.sidebar-header-mobile {
    display: none;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    z-index: 10;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Media Queries */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-header {
        display: flex;
    }
    
    .sidebar-header-mobile {
        display: flex;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: calc(-1 * var(--sidebar-width));
        height: 100vh;
        z-index: 1001;
        transition: left 0.3s ease-in-out;
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .main-wrapper {
        margin-left: 0;
        width: 100%;
    }
    
    .top-bar {
        padding: 16px 20px;
        height: auto;
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    
    .top-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .content-body {
        padding: 20px 16px;
        gap: 20px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .stat-card {
        padding: 16px;
        gap: 12px;
    }
    
    .stat-value {
        font-size: 18px;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .card-header {
        padding: 16px;
    }
    
    .modal-dialog {
        max-width: 90%;
        margin: 0 auto;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .top-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .top-actions form, .top-actions select {
        width: 100%;
    }
    
    .top-actions .btn-primary {
        justify-content: center;
    }
}

/* ============================================================
   Tree-view and Subcategory UI Styling
   ============================================================ */

.row-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-right: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    vertical-align: middle;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    transition: background 0.15s;
}

.row-toggle-btn:hover {
    background-color: var(--border-light);
}

.toggle-icon {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
    transform: rotate(90deg); /* Default state: Expanded */
}

.row-toggle-btn.collapsed .toggle-icon {
    transform: rotate(0deg); /* Collapsed */
}

/* Subcategory row display in tables */
.subcategory-row {
    display: none; /* Controlled by JS / CSS transition */
    background-color: #fafbfc;
}

.subcategory-row.show {
    display: table-row;
}

.subcategory-row td {
    border-bottom: 1px solid var(--border-light);
}

/* Guide lines for nested categories */
.subcategory-line-connector {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-left: 2px solid #cbd5e1;
    border-bottom: 2px solid #cbd5e1;
    margin-right: 6px;
    transform: translateY(-3px);
}

/* Readonly Cell Style for parent categories */
.readonly-cell {
    background-color: transparent !important;
    color: var(--text-secondary) !important;
    font-weight: 600;
    cursor: not-allowed !important;
}

.readonly-cell:hover {
    background-color: transparent !important;
    color: var(--text-secondary) !important;
}

/* Category Manager listing styles */
.subcategory-row-list td {
    background-color: #fafbfc;
}

/* Mobile wrap and scrolling fixes */
.main-wrapper {
    max-width: 100vw;
    overflow-x: hidden;
}

.content-body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Clickable Category Link buttons */
.category-name-btn {
    cursor: pointer;
    transition: color 0.15s ease, text-decoration 0.15s ease;
}

.category-name-btn:hover {
    color: var(--primary) !important;
    text-decoration: underline;
}

/* Small add subcategory inline button */
.row-add-sub-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--border-light);
    color: var(--text-secondary);
    border: none;
    border-radius: 4px;
    width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
    cursor: pointer;
    transition: all 0.15s;
    vertical-align: middle;
}

.row-add-sub-btn:hover {
    background-color: var(--primary);
    color: #ffffff;
    transform: scale(1.1);
}

/* Inline row add category bottom table */
.table-add-cat-row td {
    background-color: #fafbfc;
    border-bottom: 1px dashed var(--border-color) !important;
}

.btn-add-inline {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.15s;
}

.btn-add-inline:hover {
    background-color: var(--border-light);
}

/* Alerts Banner at the top of content */
.alerts-banner {
    background-color: #fff5f5;
    border-left: 4px solid #ef4444;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
    animation: fadeInAlert 0.3s ease-out;
}

.alerts-banner-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #dc2626;
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 8px;
}

.alerts-list {
    margin: 0;
    padding-left: 20px;
    color: #7f1d1d;
    font-size: 13px;
    line-height: 1.6;
}

.alerts-list li {
    margin-bottom: 4px;
}

@keyframes fadeInAlert {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Exceeded limit cell styling */
.exceeded-limit {
    background-color: #fef2f2 !important;
    color: #ef4444 !important;
    font-weight: 700 !important;
    border: 1px solid #fca5a5 !important;
    position: relative;
}

.exceeded-limit::after {
    content: '⚠️';
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 8px;
}

/* Daily tip card styles */
.daily-tip-card {
    background: linear-gradient(135deg, var(--primary-light) 0%, #e0e7ff 100%);
    border: 1px solid #c7d2fe;
    border-radius: var(--radius-md);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
}

.daily-tip-card::before {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 100px;
    height: 100px;
    background: rgba(79, 70, 229, 0.05);
    border-radius: 50%;
}

.tip-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
}

.tip-icon svg {
    width: 24px;
    height: 24px;
}

.tip-content h4 {
    font-family: 'Outfit', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.tip-content p {
    font-size: 13.5px;
    color: #312e81;
    line-height: 1.5;
}

/* Highlights for Total column and table body layout */
.matrix-table th:last-child,
.matrix-table td:last-child {
    border-left: 2px solid var(--border-color) !important;
    background-color: #f8fafc !important;
    font-weight: 700;
}

.matrix-table tr:hover td:last-child {
    background-color: #f1f5f9 !important;
}





