:root {
    --primary-color: #5d4037; /* Dark coffee for better contrast with beige */
    --primary-hover: #4e342e;
    --bg-color: #fdfcf0; /* Very light ivory */
    --card-bg: #ffffff;
    --sidebar-bg: #f5f5dc; /* Beige */
    --sidebar-text: #3e2723; /* Dark brown */
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --error-color: #ef4444;
    --success-color: #10b981;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
}

/* Login Page Styling */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
}

.login-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-container h1 {
    margin-bottom: 2rem;
    font-size: 1.5rem;
    color: #1e3a8a;
    font-weight: 700;
}

.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.2s;
}

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

.error {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.btn-login {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

/* Main Dashboard Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 2rem 1rem;
    border-right: 1px solid rgba(0,0,0,0.05);
}

.sidebar h2 {
    color: var(--primary-color);
    margin-bottom: 2rem;
    padding-left: 0.5rem;
}

.sidebar nav ul {
    list-style: none;
}

.sidebar nav ul li a {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar nav ul li a:hover {
    background: rgba(0,0,0,0.03);
}

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

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-x: auto;
}

/* Dashboard Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

.card h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.card .value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Transaction Table */
.table-container {
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 2rem;
}

html {
    overflow-y: scroll;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

th, td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th {
    position: relative;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-muted);
    user-select: none;
    transition: background-color 0.2s;
}

th:hover {
    background-color: rgba(0,0,0,0.02);
}

.sort-icon {
    font-size: 0.7rem;
    opacity: 0.3;
    margin-left: 4px;
    cursor: pointer;
}

/* 列のリサイズ用ハンドル */
.resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 1;
}

.resizer:hover, .resizer.resizing {
    background-color: var(--primary-color);
    opacity: 0.5;
}

/* 金額列の右寄せ */
#transaction-table td.amount, .amount {
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
}

/* Modals & Action Buttons */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: var(--card-bg); padding: 2rem; border-radius: 1rem;
    width: 90%; max-width: 600px; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    position: relative; max-height: 90vh; overflow-y: auto;
}
.modal-close {
    position: absolute; top: 1rem; right: 1.5rem;
    background: none; border: none; font-size: 1.5rem;
    cursor: pointer; color: var(--text-muted);
}
.btn-action {
    padding: 0.25rem 0.5rem; border: none; border-radius: 0.25rem;
    cursor: pointer; font-size: 0.75rem; font-weight: bold; margin-right: 0.25rem;
}
.btn-edit { background: #e0f2fe; color: #0284c7; }
.btn-edit:hover { background: #bae6fd; }
.btn-delete { background: #fee2e2; color: #dc2626; }
.btn-delete:hover { background: #fecaca; }

/* スマホ用レスポンシブデザイン (Mobile Optimization) */
.mobile-navbar {
    display: none;
}
.sidebar-overlay {
    display: none;
}

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

    /* スマホ版上部ヘッダー（ハンバーガー付き） */
    .mobile-navbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: var(--sidebar-bg);
        color: var(--primary-color);
        padding: 1rem 1.5rem;
        border-bottom: 1px solid rgba(0,0,0,0.05);
        z-index: 50;
    }
    .mobile-logo {
        font-weight: bold;
        font-size: 1.25rem;
    }
    .hamburger-btn {
        background: none;
        border: none;
        color: var(--primary-color);
        width: 28px;
        height: 28px;
        cursor: pointer;
        padding: 0;
    }
    .close-sidebar-btn {
        background: none;
        border: none;
        color: inherit;
        font-size: 1.5rem;
        cursor: pointer;
    }

    /* サイドバーを画面外（左側）へ隠す */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    }
    .sidebar h2 {
        margin-bottom: 1.5rem;
    }
    .sidebar.open, .sidebar-is-open .sidebar {
        transform: translateX(0);
    }

    /* サイドバー背面の暗いオーバーレイ */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 90;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    .sidebar-is-open .sidebar-overlay {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    /* メインコンテンツのスマホ補正 */
    .main-content {
        padding: 1rem;
    }
    .card-grid {
        grid-template-columns: 1fr;
    }
    .table-container {
        margin-left: -1rem;
        margin-right: -1rem;
        padding: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    table {
        font-size: 0.8rem;
        min-width: 600px; /* 入出金明細などは最低600px */
        border-collapse: collapse;
    }
    .report-table table {
        min-width: 1200px; /* 14列あるPLやCF画面は強制スクロール */
    }
    th, td {
        padding: 0.5rem;
    }
    th:first-child, td:first-child {
        padding-left: 1rem;
    }
}

