/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --green:       #28a745;
    --green-light: #d4edda;
    --red:         #dc3545;
    --red-light:   #f8d7da;
    --blue:        #3498db;
    --blue-light:  #cce5ff;
    --orange:      #fd7e14;
    --gray-100:    #f8f9fa;
    --gray-200:    #e9ecef;
    --gray-600:    #6c757d;
    --bg:          #f0f4f8;
    --card:        #ffffff;
    --radius:      12px;
    --shadow:      0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg:   0 4px 24px rgba(0,0,0,0.13);
}

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', sans-serif;
    background: var(--bg);
    color: #2c3e50;
    line-height: 1.6;
    padding-bottom: 80px;
}

/* ===== NAV ===== */
#site-nav {
    background: var(--card);
    padding: 10px 20px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.nav-link {
    display: inline-block;
    padding: 7px 16px;
    border-radius: 20px;
    text-decoration: none;
    color: var(--gray-600);
    font-size: 0.85rem;
    background: var(--gray-100);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-link:hover { background: var(--gray-200); }
.nav-link.active { background: var(--green); color: #fff; }
.nav-reset { color: var(--red); }
.nav-reset:hover { background: var(--red-light); color: var(--red); }

/* ===== PAGE HEADER ===== */
.page-header {
    text-align: center;
    padding: 28px 20px 20px;
}

.page-header h1 {
    font-size: 1.75rem;
    color: #2c3e50;
    margin-bottom: 6px;
}

.version-badge {
    font-size: 0.7rem;
    background: var(--green);
    color: #fff;
    padding: 3px 10px;
    border-radius: 12px;
    vertical-align: middle;
    font-weight: normal;
}

.page-header p {
    color: var(--gray-600);
    font-size: 0.9rem;
}

/* ===== MAIN ===== */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ===== PRESET SELECTOR ===== */
.preset-selector {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--blue-light);
    border-radius: 8px;
    border-left: 4px solid var(--blue);
}

.preset-label {
    font-weight: bold;
    font-size: 0.95rem;
    color: #2c3e50;
    margin-bottom: 10px;
}

.preset-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.preset-btn {
    padding: 8px 16px;
    border: 2px solid var(--blue);
    background: #fff;
    color: var(--blue);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: var(--blue-light);
}

.preset-btn.active {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 2px 8px rgba(52,152,219,0.3);
}

.preset-note {
    font-size: 0.78rem;
    color: #666;
    margin: 0;
}

.stat-info-btn {
    padding: 5px 12px;
    border: 1px solid var(--gray-200);
    background: #fff;
    color: var(--blue);
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.stat-info-btn:hover {
    background: var(--blue-light);
    border-color: var(--blue);
}

/* ===== DATA CONTROLS ===== */
.data-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--green-light);
    border-radius: var(--radius);
    justify-content: center;
    flex-wrap: wrap;
}

.btn-icon {
    padding: 9px 18px;
    border: none;
    border-radius: 8px;
    background: var(--green);
    color: #fff;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40,167,69,0.3);
}

/* ===== PANELS ===== */
.panel {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    overflow: hidden;
}

.panel-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    color: #2c3e50;
    text-align: left;
    transition: background 0.15s;
}

.panel-toggle:hover { background: var(--gray-100); }

.toggle-arrow {
    font-size: 1.1rem;
    transition: transform 0.25s;
}

.panel-toggle.collapsed .toggle-arrow { transform: rotate(-90deg); }

.panel-content {
    padding: 20px;
    border-top: 1px solid var(--gray-200);
}

.panel-content.collapsed { display: none; }

.panel-static-header {
    padding: 15px 20px;
    font-weight: bold;
    color: #2c3e50;
    border-bottom: 1px solid var(--gray-200);
}

/* ===== SETTINGS GRID ===== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

fieldset {
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 14px 16px;
}

legend {
    font-weight: bold;
    font-size: 0.88rem;
    padding: 0 8px;
    color: var(--green);
}

fieldset label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    margin-bottom: 9px;
    flex-wrap: wrap;
    color: #444;
}

fieldset label:last-of-type { margin-bottom: 0; }

fieldset input[type="number"] {
    width: 85px;
    padding: 5px 7px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    text-align: right;
    font-size: 0.92rem;
    flex-shrink: 0;
    transition: border-color 0.15s, box-shadow 0.15s;
}

fieldset input[type="number"]:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(40,167,69,0.15);
}

.hint {
    font-size: 0.76rem;
    color: var(--gray-600);
    margin-top: 8px;
    line-height: 1.4;
}

/* ===== EVENT PRESETS ===== */
.event-presets {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.preset-label {
    font-size: 0.85rem;
    color: var(--gray-600);
    font-weight: bold;
}

.event-presets button {
    padding: 7px 15px;
    border: 2px solid var(--green);
    background: #fff;
    color: var(--green);
    border-radius: 20px;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
}

.event-presets button:hover {
    background: var(--green);
    color: #fff;
}

/* ===== EVENTS LIST ===== */
#events-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.event-empty {
    text-align: center;
    color: var(--gray-600);
    padding: 28px;
    font-size: 0.88rem;
    border: 2px dashed var(--gray-200);
    border-radius: 8px;
}

.event-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--gray-100);
    border-radius: 8px;
    border-left: 4px solid var(--red);
    flex-wrap: wrap;
}

.event-item.income-event { border-left-color: var(--green); }

.event-age {
    font-weight: bold;
    font-size: 0.82rem;
    min-width: 80px;
    color: #555;
}

.event-name {
    flex: 1;
    font-weight: 500;
    font-size: 0.92rem;
    min-width: 120px;
}

.event-amount {
    font-size: 0.9rem;
    color: var(--red);
    font-weight: bold;
    white-space: nowrap;
}

.event-item.income-event .event-amount { color: var(--green); }

.event-infl {
    font-size: 0.75rem;
    color: var(--orange);
    margin-left: 4px;
}

.event-actions { display: flex; gap: 5px; }

.btn-edit, .btn-delete {
    padding: 3px 9px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    transition: opacity 0.15s;
}

.btn-edit  { background: var(--blue-light);  color: var(--blue); }
.btn-delete{ background: var(--red-light);   color: var(--red);  }
.btn-edit:hover, .btn-delete:hover { opacity: 0.75; }

/* ===== SUMMARY CARDS ===== */
.summary-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.summary-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: box-shadow 0.2s;
}

.summary-card:hover { box-shadow: var(--shadow-lg); }

.card-icon { font-size: 1.9rem; flex-shrink: 0; }

.card-label {
    font-size: 0.78rem;
    color: var(--gray-600);
    margin-bottom: 3px;
}

.card-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #2c3e50;
    line-height: 1;
}

.card-value.green  { color: var(--green); }
.card-value.red    { color: var(--red); }
.card-value.orange { color: var(--orange); }

.card-unit {
    font-size: 0.72rem;
    color: var(--gray-600);
    margin-top: 3px;
}

/* ===== CHART ===== */
.chart-wrap {
    position: relative;
    min-height: 340px;
}

/* ===== TABLE ===== */
.table-wrap {
    overflow-x: auto;
    max-height: 520px;
    overflow-y: auto;
}

#simTable {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-size: 0.82rem;
}

#simTable th {
    background: var(--gray-100);
    padding: 9px 11px;
    text-align: right;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: 2px solid var(--gray-200);
    font-size: 0.78rem;
}

#simTable th.col-age,
#simTable td.col-age {
    text-align: center;
    position: sticky;
    left: 0;
    background: var(--gray-100);
    z-index: 3;
    min-width: 60px;
}

#simTable th.col-age { z-index: 4; }

#simTable td {
    padding: 7px 11px;
    text-align: right;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

#simTable tr:hover td { background: rgba(40,167,69,0.04); }
#simTable tr:hover td.col-age { background: var(--green-light); }

/* Row states */
.row-negative td { background: rgba(220,53,69,0.03); }
.row-negative td.col-age { background: var(--red-light) !important; color: var(--red); }
.row-current td { background: rgba(40,167,69,0.07) !important; font-weight: bold; }
.row-current td.col-age { background: var(--green-light) !important; color: var(--green); }

/* Cell colors */
.c-income  { color: var(--green); }
.c-invest  { color: #1a7abf; }
.c-expense { color: var(--red); }
.c-event-expense { color: var(--red); font-weight: 500; }
.c-event-income  { color: var(--green); font-weight: 500; }
.c-net-pos { color: var(--green); font-weight: bold; }
.c-net-neg { color: var(--red);   font-weight: bold; }
.c-bal-pos { color: var(--blue);  font-weight: bold; }
.c-bal-neg { color: var(--red);   font-weight: bold; }
.c-muted   { color: var(--gray-600); }

/* ===== MODAL ===== */
#modal-overlay,
#statistics-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#modal-overlay.hidden,
#statistics-modal-overlay.hidden {
    display: none !important;
}

.modal {
    background: var(--card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,0.22);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.modal-header h3 { font-size: 1.05rem; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.15rem;
    cursor: pointer;
    color: var(--gray-600);
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}

.modal-close:hover { background: var(--gray-200); }

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 13px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-body label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.88rem;
    font-weight: 500;
    color: #444;
}

.modal-body input[type="text"],
.modal-body input[type="number"],
.modal-body select {
    padding: 8px 11px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 0.93rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-body input:focus,
.modal-body select:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(40,167,69,0.15);
}

.checkbox-label {
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 8px !important;
    font-weight: normal !important;
    cursor: pointer;
    line-height: 1.4;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin-top: 2px;
    flex-shrink: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.btn-primary, .btn-secondary {
    padding: 9px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.93rem;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
}

.btn-primary  { background: var(--green); color: #fff; }
.btn-primary:hover { background: #218838; }
.btn-secondary { background: var(--gray-200); color: #333; }
.btn-secondary:hover { background: #ced4da; }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
    .settings-grid { grid-template-columns: 1fr; }
    .summary-row   { grid-template-columns: 1fr 1fr; }
    .card-value    { font-size: 1.2rem; }
    .page-header h1{ font-size: 1.4rem; }
    .event-item    { font-size: 0.85rem; }
}
