:root {
    --color-bg: #f5f7fb;
    --color-card: #ffffff;
    --color-card-soft: #f9fafb;
    --color-text: #111827;
    --color-heading: #1f2937;
    --color-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-primary: #2563eb;
    --color-primary-soft: #dbeafe;
    --color-primary-dark: #2563eb; /* 라이트모드 사이드바 배경 */
    --color-income: #16a34a;
    --color-income-soft: #dcfce7;
    --color-expense: #dc2626;
    --color-expense-soft: #fee2e2;
    --color-warning: #f59e0b;
    --color-warning-soft: #fef3c7;
    --color-danger: #ef4444;
    --color-danger-soft: #fee2e2;
    --color-success: #22c55e;
    --color-success-soft: #dcfce7;
    --shadow-card: 0 10px 25px rgba(15, 23, 42, 0.08);
    --radius-card: 18px;
    --radius-btn: 8px;

    --header-height: 60px;
    --sidebar-width: 250px;
    --bottom-nav-height: 65px;
}

html[data-theme="dark"] {
    --color-bg: #0f172a;
    --color-card: #111827;
    --color-card-soft: #1f2937;
    --color-text: #e2e8f0;
    --color-heading: #f8fafc;
    --color-muted: #94a3b8;
    --color-border: #334155;
    --color-primary: #60a5fa;
    --color-primary-soft: rgba(96, 165, 250, 0.16);
    --color-primary-dark: #1e293b; /* 다크모드 사이드바 배경을 어둡게 처리 */
    --color-income: #4ade80;
    --color-income-soft: rgba(74, 222, 128, 0.16);
    --color-expense: #f87171;
    --color-expense-soft: rgba(248, 113, 113, 0.16);
    --color-warning: #fbbf24;
    --color-warning-soft: rgba(251, 191, 36, 0.16);
    --color-danger: #f87171;
    --color-danger-soft: rgba(248, 113, 113, 0.16);
    --color-success: #4ade80;
    --color-success-soft: rgba(74, 222, 128, 0.16);
    --shadow-card: 0 14px 32px rgba(0, 0, 0, 0.35);
}

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

body {
    font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

.card {
    background: var(--color-card);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--header-height);
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
    padding: 0 1.5rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.app-title {
    font-size: 1.25rem;
    color: var(--color-primary);
    font-weight: bold;
}

.current-month {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--color-heading);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    margin-left: 10px;
    color: var(--color-text);
    transition: transform 0.2s, opacity 0.2s;
}

.icon-btn:hover {
    transform: scale(1.1);
    opacity: 0.85;
}

.lock-status-badge {
    display: inline-flex;
    align-items: center;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--color-text);
    margin-right: 0.5rem;
}

.header-logout-btn {
    color: var(--color-danger, #e74a3b) !important;
}

/* 로그인 페이지 레이아웃 마진 상쇄 */
.main-content.login-main-layout {
    margin-left: 0 !important;
    margin-top: 0 !important;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--color-bg);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--color-primary-dark);
    color: white;
    padding-top: 1rem;
    z-index: 900;
    transition: width 0.3s, background-color 0.3s;
}

.sidebar-nav ul li a {
    display: block;
    padding: 1rem 1.5rem;
    color: rgba(255,255,255,0.8);
    font-weight: bold;
    transition: background 0.2s;
}

.sidebar-nav ul li a:hover,
.sidebar-nav ul li.active a {
    background: rgba(255,255,255,0.1);
    color: white;
}

/* Main Content */
.main-content {
    margin-top: var(--header-height);
    margin-left: var(--sidebar-width);
    padding: 1.5rem;
    min-height: calc(100vh - var(--header-height));
    transition: margin-left 0.3s;
}

/* Bottom Nav (Mobile) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--color-card);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav ul {
    display: flex;
    height: 100%;
}

.bottom-nav ul li {
    flex: 1;
}

.bottom-nav ul li a {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: var(--color-muted);
    font-size: 0.8rem;
}

.bottom-nav ul li.active a {
    color: var(--color-primary);
}

.bottom-nav .icon {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

/* Forms and Buttons */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: var(--color-heading);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-btn);
    background-color: var(--color-card);
    color: var(--color-text);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s, color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
    outline: none;
}

.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled {
    background-color: var(--color-bg);
    color: var(--color-muted);
    cursor: not-allowed;
}

.form-group textarea {
    resize: vertical;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: bold;
    text-align: center;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

.btn-primary:hover {
    background-color: #2e59d9;
}

.btn-secondary {
    background-color: var(--color-muted);
    color: white;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* Button Group & Export */
.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-download {
    background-color: #36b9cc;
    color: white;
}

.btn-download:hover {
    background-color: #2c9faf;
}

/* Flash Message */
.flash-message {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    right: 1.5rem;
    background: #1cc88a;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-card);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 1050;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideIn 0.3s ease-out;
}

.flash-message .close-msg {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Month Nav */
.month-nav-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.btn-nav {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    color: var(--color-heading);
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-nav:hover {
    background: #e2e6ea;
}

.current-month-display {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--color-heading);
}

.btn-today {
    background: var(--color-primary);
    color: white;
    border: none;
}

.btn-today:hover {
    background: #2e59d9;
}

/* Responsive */
@media (max-width: 1023px) {
    :root {
        --sidebar-width: 80px;
    }
    .app-title {
        font-size: 1.1rem;
    }
    .sidebar-nav ul li a {
        padding: 1rem 0;
        text-align: center;
        font-size: 0; /* Hide text */
    }
    .sidebar-nav ul li a::first-letter {
        font-size: 1.5rem; /* Show only icon if text starts with emoji */
    }
}

@media (max-width: 767px) {
    .sidebar {
        display: none;
    }
    .main-content {
        margin-left: 0;
        padding-bottom: calc(var(--bottom-nav-height) + 2.5rem + env(safe-area-inset-bottom)) !important;
    }
    .bottom-nav {
        display: block;
    }
    .btn-primary { width: 100%; }
    
    .btn-group {
        flex-direction: column;
    }
    .btn-group .btn {
        width: 100%;
    }
}

/* 자산 연동 도움말 텍스트 스타일 */
.help-text {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    font-weight: normal;
}
.help-text.info {
    color: #4e73df;
}
.help-text.muted {
    color: var(--color-muted);
}

/* PWA 앱 설치 유도 배너 스타일 */
.pwa-install-banner {
    display: none;
    justify-content: space-between;
    align-items: center;
    background-color: var(--color-card);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-card, 18px);
    box-shadow: var(--shadow-card);
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    animation: slideDown 0.4s ease-out;
    gap: 1rem;
}

.pwa-install-banner.show {
    display: flex;
}

.pwa-banner-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.pwa-banner-icon {
    font-size: 1.8rem;
}

.pwa-banner-text {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.pwa-banner-text strong {
    font-size: 0.95rem;
    color: var(--color-heading);
}

.pwa-banner-text span {
    font-size: 0.82rem;
    color: var(--color-muted);
}

.pwa-banner-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.pwa-dismiss-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0.2rem;
    transition: color 0.2s;
}

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

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

@media (max-width: 580px) {
    .pwa-install-banner {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
    }
    .pwa-banner-actions {
        justify-content: flex-end;
        margin-top: 0.5rem;
    }
}
