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

body {
    font-family: -apple-system, "Helvetica Neue", Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px 96px;
}

h1 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 1.6rem;
}

h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
}

section {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* Form */
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: .9rem; color: #555; }
.form-row input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: .95rem;
}
.four-col {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

button {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: .9rem;
}

#submit-btn {
    background: #4f7df9;
    color: #fff;
}
#submit-btn:hover { background: #3b66d9; }

#cancel-edit-btn {
    background: #e0e0e0;
    color: #333;
    margin-left: 8px;
}

.hidden { display: none !important; }

/* Backup */
.backup-fab {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 20;
}
.backup-fab-button {
    list-style: none;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #4f7df9;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(79, 125, 249, .35);
    transition: transform .2s ease, box-shadow .2s ease;
}
.backup-fab[open] .backup-fab-button,
.backup-fab-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(79, 125, 249, .45);
}
.backup-fab-button::-webkit-details-marker { display: none; }
.backup-fab-button::marker { content: ""; }
.backup-panel {
    position: absolute;
    right: 0;
    bottom: 64px;
    width: min(300px, 86vw);
    background: #fff;
    border-radius: 12px;
    padding: 12px 14px 14px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, .12);
    border: 1px solid #edf0f5;
}
.backup-title {
    font-size: .9rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}
.backup-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.backup-actions button,
.backup-actions .file-label {
    padding: 6px 10px;
    border-radius: 8px;
    font-size: .85rem;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #d0d5dd;
    cursor: pointer;
    background: #f1f3f7;
    color: #4a5568;
}
#export-btn {
    background: #4f7df9;
    border-color: #4f7df9;
    color: #fff;
}
.file-label input { display: none; }
#import-mode {
    width: 100%;
    margin-top: 8px;
    padding: 6px 10px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    background: #fff;
    font-size: .85rem;
}
.hint {
    margin-top: 6px;
    font-size: .8rem;
    color: #777;
}
@media (max-width: 520px) {
    .backup-actions {
        grid-template-columns: 1fr;
    }
}

/* Table */
.table-wrap { overflow-x: auto; }
.table-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: .9rem;
    color: #555;
}
.unit-toggle {
    display: inline-flex;
    background: #f1f3f7;
    border-radius: 999px;
    padding: 2px;
}
.unit-btn {
    background: transparent;
    color: #555;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: .85rem;
}
.unit-btn.active {
    background: #4f7df9;
    color: #fff;
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td {
    padding: 8px 10px;
    text-align: center;
    border-bottom: 1px solid #eee;
}
th { background: #f8f9fb; font-weight: 600; }
tfoot td { font-weight: 600; background: #f8f9fb; }
th[data-sort] {
    cursor: pointer;
    user-select: none;
}
th[data-sort]::after {
    content: " ^v";
    margin-left: 4px;
    font-size: .75rem;
    color: #b0b7c3;
}
th[data-sort][data-sort-direction="asc"]::after {
    content: " ^";
    color: #4f7df9;
}
th[data-sort][data-sort-direction="desc"]::after {
    content: " v";
    color: #4f7df9;
}

.btn-edit, .btn-delete {
    font-size: .8rem;
    padding: 3px 8px;
    border-radius: 4px;
    margin: 0 2px;
}
.btn-edit { background: #e8f0fe; color: #4f7df9; }
.btn-delete { background: #fde8e8; color: #d9534f; }

/* Chart */
.chart-section canvas {
    width: 100% !important;
    max-height: 400px;
}
