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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 20px);
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    background: white;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    padding: 32px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    border-bottom: 3px solid #667eea;
    padding-bottom: 20px;
}

header h1 {
    font-size: 2.5em;
    color: #333;
    margin-bottom: 10px;
}

header .subtitle {
    color: #666;
    font-size: 1.1em;
}

section {
    margin-bottom: 36px;
    padding: 0;
}

section h2 {
    font-size: 1.35em;
    color: #2f3659;
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 2px solid #667eea;
}

section h3 {
    font-size: 1.2em;
    color: #333;
    margin-bottom: 15px;
}

.sync-toggle {
    position: fixed;
    right: env(safe-area-inset-right, 24px);
    bottom: env(safe-area-inset-bottom, 24px);
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: #667eea;
    color: white;
    font-size: 1.6rem;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.sync-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
}

.sync-toggle.highlight {
    background: #f56565;
    animation: pulse 1.6s infinite;
}

.sync-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1001;
}

.sync-overlay.open {
    display: flex;
}

.sync-card {
    width: min(480px, 100%);
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.sync-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.sync-card-header h2 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.sync-close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    color: #4a5568;
}

.migration-hint {
    font-size: 0.92rem;
    line-height: 1.45;
    color: #2d3748;
    background: #fffaf0;
    border: 1px solid #f6ad55;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 12px;
}

.migration-hint code {
    font-size: 0.88em;
}

.backup-actions {
    margin-top: 4px;
}

.sync-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sync-status {
    color: #4a5568;
    font-size: 0.95em;
    padding: 8px 10px;
    border-radius: 6px;
    background: #edf2f7;
}

.sync-status.syncing {
    background: #ebf8ff;
    color: #2b6cb0;
}

    .hidden {
        display: none !important;
    }

    .install-hint {
        position: fixed;
        left: env(safe-area-inset-left, 16px);
        right: env(safe-area-inset-right, 16px);
        bottom: calc(96px + env(safe-area-inset-bottom, 16px));
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid rgba(102, 126, 234, 0.2);
        border-radius: 16px;
        padding: 14px 16px;
        box-shadow: 0 14px 32px rgba(15, 23, 42, 0.18);
        backdrop-filter: blur(10px);
        z-index: 1002;
    }

    .install-hint span {
        color: #1f2937;
        font-size: 0.95rem;
        line-height: 1.4;
        flex: 1 1 auto;
    }

    .btn-small {
        padding: 8px 14px;
        font-size: 0.9rem;
    }

        transform: scale(1.06);
    }
}

/* Buttons */
.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #48bb78;
    color: white;
}

.btn-secondary:hover {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(72, 187, 120, 0.4);
}

.btn-danger {
    background: #f56565;
    color: white;
}

.btn-danger:hover {
    background: #e53e3e;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(245, 101, 101, 0.4);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-card h3 {
    font-size: 0.9em;
    opacity: 0.9;
    margin-bottom: 4px;
    color: rgba(255, 255, 255, 0.9);
}

.stat-value {
    font-size: 1.7em;
    font-weight: bold;
    line-height: 1.2;
}

.stat-label,
.stat-summary {
    font-size: 0.9em;
    opacity: 0.95;
    line-height: 1.4;
}

.stat-summary {
    font-size: 0.88em;
}

.stat-mini-graph {
    display: flex;
    gap: 4px;
    align-items: flex-end;
    margin-top: 6px;
    min-height: 44px;
}

.stat-mini-graph span {
    flex: 1;
    min-height: 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.85);
}

.stat-mini-graph span.under {
    background: rgba(72, 187, 120, 0.9);
}

.stat-mini-graph span.over {
    background: rgba(245, 101, 101, 0.95);
}

.stat-card.week.good,
.stat-card.month.good {
    background: linear-gradient(135deg, #38a169 0%, #2f855a 100%);
}

.stat-card.week.bad,
.stat-card.month.bad {
    background: linear-gradient(135deg, #f56565 0%, #c53030 100%);
}

.stat-card.today {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-card.week {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
}

.stat-card.month {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
}

.stat-card.accumulated {
    background: linear-gradient(135deg, #9f7aea 0%, #6b46c1 100%);
}

/* Form */
.log-form {
    background: #f7fafc;
    padding: 20px;
    border-radius: 8px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.form-group input,
.form-group select {
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Filters */
.filters-section {
    background: #f7fafc;
    padding: 20px;
    border-radius: 8px;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

    input,
    select,
    button {
        font: inherit;
    }

.filter-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.filter-group select,
.filter-group input {
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 1em;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Charts */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 30px;
}

.chart-container {
    background: #f7fafc;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-container canvas {
    max-height: 300px;
}

/* Entries List */
.entries-list {
    background: #f7fafc;
    border-radius: 8px;
    max-height: 500px;
    overflow-y: auto;
        padding: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.3s ease;
        gap: 12px;
        flex-wrap: wrap;
    border-bottom: none;
}

.entry-date {
    font-weight: 600;
    color: #333;
}

.entry-usage {
    color: #667eea;
    font-weight: 500;
}

.entry-balance {
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 600;
}

.entry-balance.positive {
    background: #c6f6d5;
    color: #22543d;
}

.entry-balance.negative {
    background: #fed7d7;
    color: #742a2a;
}

.entry-delete {
    background: #fc8181;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.3s ease;
}

.entry-delete:hover {
    background: #f56565;
}

.no-data {
    text-align: center;
    color: #999;
    padding: 20px;
}

.data-management {
    background: #f0f4ff;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.data-management h2 {
    border-bottom: none;
    margin-bottom: 15px;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 16px 14px 24px;
    }

    .container {
        padding: 20px;
        box-shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
    }

    header h1 {
        font-size: 1.8em;
    }

    section h2,
    section h3 {
        line-height: 1.2;
    }

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

    .charts-section {
        grid-template-columns: 1fr;
    }

    .log-form {
        grid-template-columns: 1fr;
    }

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

    .entry-item {
        flex-direction: column;
        align-items: stretch;
    }

    .entry-item > div {
        width: 100%;
    }

    .button-group,
    .install-actions {
        flex-direction: column;
    }

    .chart-container canvas {
        max-height: 260px;
    }
}
