/* CSS Design Tokens & Reset */
:root {
    --font-bengali: 'Hind Siliguri', 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-latin: 'Outfit', sans-serif;
    
    /* Dark Theme Palette (Default) */
    --bg-color: #0b0f19;
    --panel-bg: rgba(20, 28, 45, 0.65);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --color-income: #10b981;
    --color-income-rgb: 16, 185, 129;
    --color-income-glow: rgba(16, 185, 129, 0.15);
    --color-expense: #f43f5e;
    --color-expense-rgb: 244, 63, 94;
    --color-expense-glow: rgba(244, 63, 94, 0.15);
    --color-accent: #6366f1;
    --color-accent-hover: #4f46e5;
    
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --border-color: rgba(255, 255, 255, 0.05);
    --border-radius: 16px;
    --transition-speed: 0.3s;
}

/* Light Theme overrides */
.light-theme {
    --bg-color: #f3f4f6;
    --panel-bg: rgba(255, 255, 255, 0.75);
    --panel-border: rgba(0, 0, 0, 0.06);
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    
    --color-income: #059669;
    --color-income-glow: rgba(5, 150, 105, 0.1);
    --color-expense: #e11d48;
    --color-expense-glow: rgba(225, 29, 72, 0.1);
    --color-accent: #4f46e5;
    --color-accent-hover: #4338ca;
    
    --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --border-color: rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-bengali);
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
    position: relative;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

/* Background Ambient Glows */
.glow-bg {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(0, 0, 0, 0) 70%);
    top: -100px;
    left: -100px;
    z-index: -1;
    pointer-events: none;
    animation: pulseGlow 10s infinite alternate;
}

.light-theme .glow-bg {
    background: radial-gradient(circle, rgba(99, 102, 241, 0.05) 0%, rgba(0, 0, 0, 0) 70%);
}

@keyframes pulseGlow {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.2); opacity: 1; }
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--color-accent) 0%, #a855f7 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.logo-text h1 {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
}

.logo-text p {
    font-size: 12px;
    color: var(--text-secondary);
}

.btn-icon {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
}

.light-theme .btn-icon {
    background: rgba(0, 0, 0, 0.03);
}

.btn-icon:hover {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
    transform: translateY(-2px);
}

/* Dashboard Summary Cards */
.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--card-shadow);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.balance-card::before { background: var(--color-accent); }
.income-card::before { background: var(--color-income); }
.expense-card::before { background: var(--color-expense); }

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.balance-card .card-icon { background: rgba(99, 102, 241, 0.12); color: var(--color-accent); }
.income-card .card-icon { background: rgba(16, 185, 129, 0.12); color: var(--color-income); }
.expense-card .card-icon { background: rgba(244, 63, 94, 0.12); color: var(--color-expense); }

.card-details h3 {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 2px;
}

.amount-container {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.currency {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-muted);
}

.amount {
    font-family: var(--font-latin);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* Workspace Grid Layout */
.app-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

/* Glass Panel Styles */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--card-shadow);
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.panel-header h2 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-header h2 i {
    color: var(--color-accent);
}

/* Forms & Inputs */
.app-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.form-row {
    display: flex;
    gap: 14px;
}

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

.required {
    color: var(--color-expense);
}

.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.light-theme input[type="text"],
.light-theme input[type="number"],
.light-theme input[type="date"],
.light-theme select {
    background: rgba(255, 255, 255, 0.8);
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
    background: rgba(0, 0, 0, 0.3);
}

.light-theme input[type="text"]:focus,
.light-theme input[type="number"]:focus,
.light-theme input[type="date"]:focus,
.light-theme select:focus {
    background: #fff;
}

/* Radio Toggle Buttons for Income/Expense */
.toggle-group {
    flex-direction: row;
    background: rgba(0, 0, 0, 0.15);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.light-theme .toggle-group {
    background: rgba(0, 0, 0, 0.03);
}

.toggle-label {
    flex: 1;
    cursor: pointer;
}

.toggle-label input {
    display: none;
}

.toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    text-align: center;
}

.toggle-label input:checked + .income-btn {
    background: var(--color-income);
    color: #fff;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
}

.toggle-label input:checked + .expense-btn {
    background: var(--color-expense);
    color: #fff;
    box-shadow: 0 4px 10px rgba(244, 63, 94, 0.2);
}

/* Button Custom Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}

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

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.light-theme .btn-secondary {
    background: rgba(0, 0, 0, 0.03);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
    background: var(--color-expense);
    color: #fff;
}

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

.btn-block {
    width: 100%;
}

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

.btn-text {
    background: transparent;
    border: none;
    color: var(--color-accent);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-text:hover {
    text-decoration: underline;
}

/* Category Budgets List */
.budget-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 4px;
}

.budget-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
}

.budget-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.budget-cat-name {
    font-weight: 600;
    font-size: 13px;
}

.budget-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.budget-numeric {
    font-family: var(--font-latin);
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dynamically color progress-bar status */
.progress-safe { background: var(--color-income); }
.progress-warning { background: #eab308; }
.progress-danger { background: var(--color-expense); animation: pulseDanger 1.5s infinite alternate; }

@keyframes pulseDanger {
    0% { opacity: 0.8; }
    100% { opacity: 1; box-shadow: 0 0 6px rgba(244, 63, 94, 0.6); }
}

/* Empty State Styling */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 28px;
}

.empty-state p {
    font-size: 13px;
}

/* Chart Container & SVG */
.chart-container {
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 16px;
}

#chart-wrapper {
    position: relative;
    width: 130px;
    height: 130px;
    flex-shrink: 0;
}

#expense-pie-chart {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.chart-center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
}

#chart-center-title {
    font-size: 11px;
    color: var(--text-secondary);
}

#chart-center-val {
    font-family: var(--font-latin);
    font-size: 16px;
    font-weight: 700;
}

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 130px;
    overflow-y: auto;
    padding-right: 4px;
    flex: 1;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    gap: 8px;
}

.legend-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-name {
    font-weight: 500;
}

.legend-right {
    font-family: var(--font-latin);
    color: var(--text-secondary);
}

/* History List Panel Actions */
.history-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

#history-search {
    padding: 6px 10px;
    font-size: 12px;
    width: 130px;
}

#history-filter-type {
    padding: 6px 10px;
    font-size: 12px;
    width: 110px;
}

.history-list-wrapper {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 4px;
}

.transaction-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.transaction-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.transaction-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tx-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tx-cat-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.tx-item-income .tx-cat-icon {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-income);
}

.tx-item-expense .tx-cat-icon {
    background: rgba(244, 63, 94, 0.1);
    color: var(--color-expense);
}

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

.tx-title {
    font-weight: 600;
    font-size: 13px;
    /* Prevent overflow text */
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    gap: 6px;
}

.tx-date-txt {
    font-family: var(--font-latin);
}

.tx-amount-side {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tx-amount-val {
    font-family: var(--font-latin);
    font-weight: 700;
    font-size: 14px;
}

.tx-item-income .tx-amount-val { color: var(--color-income); }
.tx-item-expense .tx-amount-val { color: var(--color-expense); }

.btn-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 13px;
    transition: all 0.2s ease;
}

.btn-delete:hover {
    color: var(--color-expense);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 90%;
    max-width: 380px;
    margin: auto;
    border-radius: var(--border-radius);
    padding: 20px;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 14px;
}

.modal-header h2 {
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

/* Toast Notification Styling */
.toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    left: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}

.toast {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    padding: 12px 16px;
    border-radius: 8px;
    background: rgba(20, 28, 45, 0.95);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateY(50px);
    opacity: 0;
    animation: slideIn 0.3s forwards, fadeOut 0.3s 3s forwards;
    font-size: 13px;
}

.toast-success { border-left: 4px solid var(--color-income); }
.toast-success i { color: var(--color-income); }
.toast-error { border-left: 4px solid var(--color-expense); }
.toast-error i { color: var(--color-expense); }

@keyframes slideIn {
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
    to { transform: translateY(-20px); opacity: 0; }
}

/* Footer Section */
.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius);
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
}

.footer-info p {
    font-size: 12px;
    color: var(--text-secondary);
}

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

/* ==========================================================================
   MOBILE & TABLET RESPONSIVENESS OVERRIDES (MEDIA QUERIES)
   ========================================================================== */

/* Tablet & Mobile Screens (Up to 900px) */
@media (max-width: 900px) {
    .app-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* Mobile Screens (Up to 600px) */
@media (max-width: 600px) {
    .app-container {
        padding: 0 12px;
        margin: 10px auto;
        gap: 16px;
    }
    
    .app-header {
        padding: 12px 16px;
    }
    
    .logo-icon {
        width: 38px;
        height: 38px;
        font-size: 18px;
    }
    
    .logo-text h1 {
        font-size: 18px;
    }
    
    .logo-text p {
        font-size: 11px;
    }

    .dashboard-summary {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .card {
        padding: 16px;
    }
    
    .amount {
        font-size: 24px;
    }
    
    .glass-panel {
        padding: 16px;
        margin-bottom: 16px;
    }
    
    .form-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .panel-header {
        flex-direction: row; /* Keep alignment on header */
        align-items: center;
        justify-content: space-between;
    }
    
    .chart-container {
        flex-direction: column;
        gap: 20px;
    }
    
    #chart-wrapper {
        width: 140px;
        height: 140px;
    }
    
    .chart-legend {
        width: 100%;
        max-height: 150px;
    }

    .history-actions {
        width: 100%;
        gap: 8px;
    }
    
    #history-search, #history-filter-type {
        flex: 1;
        width: 50%;
        font-size: 12px;
        padding: 8px 10px;
    }
    
    .app-footer {
        flex-direction: column;
        text-align: center;
        padding: 16px;
    }
    
    .footer-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .footer-actions .btn {
        flex: 1;
        min-width: 90px;
    }
}

/* Extra Small Mobile Screens (Up to 360px) */
@media (max-width: 360px) {
    .app-container {
        padding: 0 8px;
    }
    
    .logo-text p {
        display: none; /* Hide subtitle for extra small screens */
    }
    
    .card {
        padding: 12px;
        gap: 12px;
    }
    
    .card-icon {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .amount {
        font-size: 22px;
    }
    
    .tx-title {
        max-width: 100px; /* Force even shorter width */
    }
}

.hidden {
    display: none !important;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.light-theme ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}
