/* 主题变量定义 */
:root {
    --bg-primary: #f0f4f8;
    --bg-card: #ffffff;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --border: #e2e8f0;
    --shadow: rgba(0,0,0,0.06);
}

body[data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-card: #1a1a1a;
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --border: #2d2d2d;
    --shadow: rgba(0,0,0,0.3);
}

body[data-theme="gray"] {
    --bg-primary: #e0e0e0;
    --bg-card: #c8c8c8;
    --text-primary: #2d2d2d;
    --text-secondary: #5a5a5a;
    --accent: #4a4a4a;
    --accent-hover: #2d2d2d;
    --border: #9e9e9e;
    --shadow: rgba(0,0,0,0.1);
}

body[data-theme="blue"] {
    --bg-primary: #e3f2fd;
    --bg-card: #bbdefb;
    --text-primary: #0d47a1;
    --text-secondary: #1565c0;
    --accent: #1976d2;
    --accent-hover: #1565c0;
    --border: #90caf9;
    --shadow: rgba(33,150,243,0.15);
}

body[data-theme="green"] {
    --bg-primary: #e8f5e9;
    --bg-card: #c8e6c9;
    --text-primary: #1b5e20;
    --text-secondary: #388e3c;
    --accent: #4caf50;
    --accent-hover: #388e3c;
    --border: #a5d6a7;
    --shadow: rgba(76,175,80,0.15);
}

body[data-theme="red"] {
    --bg-primary: #ffebee;
    --bg-card: #ffcdd2;
    --text-primary: #b71c1c;
    --text-secondary: #c62828;
    --accent: #e53935;
    --accent-hover: #c62828;
    --border: #ef9a9a;
    --shadow: rgba(229,57,53,0.15);
}

body[data-theme="warm"] {
    --bg-primary: #fff3e0;
    --bg-card: #ffe0b2;
    --text-primary: #e65100;
    --text-secondary: #f57c00;
    --accent: #ff9800;
    --accent-hover: #f57c00;
    --border: #ffcc80;
    --shadow: rgba(255,152,0,0.15);
}

body[data-theme="rainbow"] {
    --bg-primary: linear-gradient(135deg, #f093fb 0%, #f5576c 50%, #4facfe 100%);
    --bg-card: rgba(255,255,255,0.9);
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --border: #e2e8f0;
    --shadow: rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    padding: 16px;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-card);
    border-radius: 12px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px var(--shadow);
}

.header-left h1 {
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 700;
}

.header-right {
    display: flex;
    gap: 24px;
    align-items: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.theme-selector select {
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
}

.theme-selector select:focus {
    outline: none;
    border-color: var(--accent);
}

.sync-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.sync-status strong {
    color: #4f46e5;
}

.add-section {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px var(--shadow);
}

.add-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.add-section h2 {
    font-size: 16px;
    color: var(--text-primary);
    margin: 0;
    font-weight: 600;
}

.add-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

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

.form-row-vertical .form-group {
    width: 100%;
}

.form-row-vertical .form-group input,
.form-row-vertical .form-group select {
    width: 100%;
    min-width: 280px;
}

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

.form-group label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group input,
.form-group select {
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-width: 120px;
    background: var(--bg-card);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.submit-btn {
    padding: 8px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.submit-btn:hover {
    transform: translateY(-2px);
    background: var(--accent-hover);
}

.summary-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.summary-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--shadow);
}

.summary-card h3 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.summary-card p {
    font-size: 22px;
    font-weight: 700;
}

.summary-card.total p { color: var(--accent); }
.summary-card.paid p { color: #10b981; }
.summary-card.unpaid p { color: #f59e0b; }
.summary-card.avg p { color: #f97316; }

.charts-section {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.chart-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow);
}

.chart-card h3 {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 16px;
    font-weight: 600;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 240px;
}

.table-section {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 2px 8px var(--shadow);
}

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

.table-header h2 {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 600;
}

.filters {
    display: flex;
    gap: 10px;
    align-items: center;
}

.filters input,
.filters select {
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-card);
    color: var(--text-primary);
}

.filters input:focus,
.filters select:focus {
    outline: none;
    border-color: var(--accent);
}

.filters button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.filters button:first-of-type {
    background: var(--accent);
    color: white;
}

.filters button:first-of-type:hover {
    background: var(--accent-hover);
}

.filters button:last-of-type {
    background: var(--border);
    color: var(--text-secondary);
}

.table-wrapper {
    overflow-x: auto;
}

#billsTable {
    width: 100%;
    border-collapse: collapse;
}

#billsTable th {
    background: var(--border);
    color: var(--text-secondary);
    padding: 12px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
    border-bottom: 2px solid var(--border);
}

#billsTable td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
}

#billsTable tbody tr:hover {
    background: var(--border);
}

.paid-badge {
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
}

.paid-badge.yes {
    background: #d1fae5;
    color: #059669;
}

.paid-badge.no {
    background: #fef3c7;
    color: #d97706;
}

.price-cell {
    font-weight: 700;
    color: var(--accent);
}

.actions-cell {
    display: flex;
    gap: 6px;
}

.btn-edit, .btn-delete, .btn-mark-paid {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-edit {
    background: #dbeafe;
    color: #1d4ed8;
}

.btn-edit:hover {
    background: #bfdbfe;
}

.btn-delete {
    background: #fee2e2;
    color: #dc2626;
}

.btn-delete:hover {
    background: #fecaca;
}

.btn-mark-paid {
    background: #d1fae5;
    color: #059669;
}

.btn-mark-paid:hover {
    background: #a7f3d0;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlide 0.3s ease;
    box-shadow: 0 25px 50px var(--shadow);
}

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

.modal .close {
    float: right;
    font-size: 24px;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.modal .close:hover {
    color: var(--text-primary);
}

.modal h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.btn-cancel {
    padding: 10px 24px;
    background: var(--border);
    color: var(--text-secondary);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    font-weight: 500;
}

.btn-save {
    padding: 10px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.3);
}

@media (max-width: 1200px) {
    .summary-section {
        grid-template-columns: repeat(2, 1fr);
    }
    .charts-section {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        padding: 12px;
    }
    header {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }
    .header-right {
        flex-direction: column;
        gap: 8px;
    }
    .summary-section {
        grid-template-columns: 1fr;
    }
    .form-row {
        flex-direction: column;
        align-items: stretch;
    }
    .form-group input,
    .form-group select {
        min-width: 100%;
    }
    .table-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .filters {
        flex-wrap: wrap;
    }
}

.auth-content {
    background: white;
    border-radius: 16px;
    padding: 32px 24px;
    width: 90%;
    max-width: 380px;
    text-align: center;
    animation: modalSlide 0.3s ease;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}

.auth-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: white;
}

.auth-content h2 {
    color: #1a202c;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
}

.auth-subtitle {
    color: #718096;
    font-size: 13px;
    margin-bottom: 24px;
}

.auth-form-group {
    margin-bottom: 12px;
}

.auth-form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    transition: all 0.2s;
    background: #f7fafc;
    box-sizing: border-box;
}

.auth-form-group input:focus {
    outline: none;
    border-color: #4f46e5;
    background: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.auth-error {
    color: #dc2626;
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 16px;
}

.auth-btn {
    width: 100%;
    padding: 12px 24px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.3);
}
