:root {
    /* Financial Professional Palette (Inspired by realtax.askpapa.net) */
    --brand-hue: 220;
    --primary: oklch(63.7% 0.237 25.331);
    /* Target Red-500 */
    --primary-hover: oklch(57.7% 0.245 27.325);
    /* Target Red-600 */
    --secondary: #f8fafc;
    --bg-main: #ffffff;
    --bg-panel: #ffffff;
    --text-main: oklch(25% 0.02 var(--brand-hue));
    --text-muted: oklch(55% 0.02 var(--brand-hue));
    --income: oklch(70% 0.15 145);
    --expense: var(--primary);
    --border: #e2e8f0;

    /* Crisp Layout & Effects */
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --glass-blur: 0px;
    /* Simplified from glassmorphism */
    --transition-fast: 0.15s ease-out;
    --transition-base: 0.3s ease-out;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 24px;
}

/* Header */
header {
    margin-bottom: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 a {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    text-decoration: none;
    letter-spacing: -0.03em;
}

.subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin-top: 6px;
}

/* Financial Panel Style */
.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 32px;
    transition: box-shadow var(--transition-fast);
}

.panel:hover {
    box-shadow: var(--shadow-md);
}

/* Dashboard Layout - High Stability Architecture */
.dashboard-layout {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 32px;
    align-items: flex-start;
}

.sidebar {
    position: sticky;
    top: 24px;
    height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
}

.settings-panel {
    height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
    padding-right: 8px;
}

.settings-panel::-webkit-scrollbar {
    width: 6px;
}

.settings-panel::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 3px;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 32px;
    min-width: 0; /* Important for grid item stability */
}

/* Typography & Icons */
h2,
h3 {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    font-weight: 700;
}

.icon {
    font-size: 20px;
    opacity: 0.8;
}

/* Form Elements */
.input-group {
    margin-bottom: 24px;
}

.date-range-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    margin-left: 4px;
}

input,
select {
    width: 100%;
    padding: 12px 16px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    transition: all var(--transition-fast);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

/* Flow Table & Rows */
.flow-group {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #f1f5f9;
}

.flow-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    min-width: 600px; /* Ensure enough width for horizontal scroll if needed */
    overflow-x: auto;
}

.flow-header,
.flow-row {
    display: grid;
    gap: 12px;
    align-items: center;
    padding: 10px 16px;
    border-radius: var(--radius-md);
}

.flow-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f8fafc;
    border: 1px solid transparent;
}

.flow-row {
    background: #ffffff;
    border: 1px solid var(--border);
    transition: all var(--transition-fast);
}

.flow-row:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Grid Column Definitions */
#recurring-flows-container .flow-header,
#recurring-flows-container .flow-row {
    grid-template-columns: 100px 70px 90px 45px 105px 105px 32px;
}

#variable-flows-container .flow-header,
#variable-flows-container .flow-row {
    grid-template-columns: 140px 80px 120px 110px 32px;
}

.flow-row div[data-label] {
    display: contents;
}

.flow-row input,
.flow-row select {
    padding: 8px 10px;
    font-size: 13px;
    border-color: #e2e8f0;
}

/* Actions */
.actions {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    margin-top: 32px;
}

button {
    padding: 14px 24px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

button.primary {
    background: var(--primary);
    color: white;
}

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

button.secondary {
    background: #f1f5f9;
    color: #475569;
}

button.secondary:hover {
    background: #e2e8f0;
}

/* Charts */
.chart-container {
    min-height: 400px;
    position: relative;
}

.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

/* Report Summary Cards */
.report-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.summary-card {
    background: #f8fafc;
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.summary-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.summary-card h4 {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.summary-card p {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-top: 4px;
}

.income-text { color: var(--income); }
.expense-text { color: var(--expense); }

/* Mobile Responsiveness & Dual Interface Implementation */
@media (max-width: 1200px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .settings-panel {
        height: auto;
        overflow-y: visible;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 20px 16px;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .chart-grid {
        grid-template-columns: 1fr;
    }

    .panel {
        padding: 24px 16px;
        border-radius: var(--radius-md);
    }

    /* Mobile-specific adjustments for PWA feel */
    body {
        background-attachment: fixed;
    }
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Custom Scrollbar for non-Firefox */
::-webkit-scrollbar {
    width: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}