:root {
    /* Light Theme (Default) */
    --bg-core: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-hover: #f1f3f5;

    --border-light: #e9ecef;
    --border-focus: #dee2e6;

    --text-primary: #212529;
    --text-secondary: #495057;
    --text-tertiary: #868e96;

    --accent: #000000;
    --accent-fg: #ffffff;
    --accent-blue: #228be6;
    --danger: #fa5252;
    --success: #40c057;

    --font-sans: 'Inter', sans-serif;
    --font-mono: 'Space Mono', monospace;

    --radius: 8px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
    --bg-core: #030303;
    --bg-surface: #0e0e0e;
    --bg-hover: #1a1a1a;

    --border-light: #222222;
    --border-focus: #444444;

    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-tertiary: #52525b;

    --accent: #ffffff;
    --accent-fg: #000000;
    --accent-blue: #3b82f6;
    --danger: #ef4444;
    --success: #10b981;

    --shadow-sm: none;
    --shadow-md: none;
}

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

body {
    background-color: var(--bg-core);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

.hidden {
    display: none !important;
}

/* --- Layout --- */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.sidebar {
    width: 260px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    padding: 24px;
    z-index: 20;
    transition: background-color 0.3s, border-color 0.3s;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
}

.logo-shape {
    width: 24px;
    height: 24px;
    background: var(--accent);
    border-radius: 4px;
}

.brand-name {
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: -0.5px;
    font-size: 18px;
    color: var(--text-primary);
}

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

.nav-section-label {
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    font-size: 11px;
    margin: 24px 0 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    border-radius: var(--radius);
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-left-color: var(--accent);
}

.nav-item.active {
    background: var(--bg-hover);
    color: var(--text-primary);
    font-weight: 600;
    border-left-color: var(--accent);
}

.nav-item i {
    width: 20px;
    text-align: center;
}

/* Topbar */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-core);
    transition: background-color 0.3s;
}

.topbar {
    height: 70px;
    padding: 0 40px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface);
    transition: background-color 0.3s, border-color 0.3s;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.status-indicator {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    display: block;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-profile-top {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 20px;
    border-left: 1px solid var(--border-light);
}

.user-info-text {
    text-align: right;
}

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

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

.btn-icon-only {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon-only:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.content-scroll {
    padding: 40px;
    overflow-y: auto;
    flex: 1;
}

/* Grid Layout for Cards */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.info-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
    position: relative;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.card-icon {
    width: 40px;
    height: 40px;
    background: var(--bg-hover);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 18px;
}

.card-actions {
    display: flex;
    gap: 8px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 13px;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.tag-pill {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-right: 4px;
    margin-bottom: 4px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.2s;
    border: 1px solid transparent;
    gap: 8px;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-fg);
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: var(--bg-surface);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.btn-secondary:hover {
    border-color: var(--text-secondary);
}

.btn-danger {
    color: var(--danger);
    background: transparent;
    border-color: transparent;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* Modal */
#modal-backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.plaid-modal {
    background: var(--bg-surface);
    width: 100%;
    max-width: 480px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    position: relative;
}

.modal-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 20px;
    cursor: pointer;
}

.close-modal:hover {
    color: var(--text-primary);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.plaid-input {
    width: 100%;
    background: var(--bg-core);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 14px;
    border-radius: var(--radius);
    transition: border-color 0.2s;
}

.plaid-input:focus {
    outline: none;
    border-color: var(--text-primary);
    background: var(--bg-surface);
}

/* Login */
.login-fullscreen {
    position: fixed;
    inset: 0;
    background: var(--bg-core);
    z-index: 100;
    display: grid;
    place-items: center;
}

.login-container {
    width: 100%;
    max-width: 360px;
    padding: 20px;
}

.login-brand {
    text-align: center;
    margin-bottom: 40px;
}

.login-brand h2 {
    font-weight: 600;
    font-size: 24px;
    color: var(--text-primary);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    padding: 24px;
    border-radius: var(--radius);
}

.stat-label {
    font-size: 12px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 12px;
}

.stat-value {
    font-size: 32px;
    font-weight: 300;
    color: var(--text-primary);
    letter-spacing: -1px;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 16px 20px 20px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    transform: translateX(400px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    min-width: 300px;
    max-width: 400px;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast i {
    font-size: 18px;
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-success i {
    color: var(--success);
}

.toast-error {
    border-left: 4px solid var(--danger);
}

.toast-error i {
    color: var(--danger);
}

.toast-info {
    border-left: 4px solid var(--accent-blue);
}

.toast-info i {
    color: var(--accent-blue);
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 100%;
    background: var(--accent);
    border-radius: 0 0 var(--radius) var(--radius);
    transform-origin: left;
}

@keyframes progress {
    from {
        transform: scaleX(1);
    }

    to {
        transform: scaleX(0);
    }
}