* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: #f0f4f8; color: #1e293b; font-size: 14px; padding-bottom: env(safe-area-inset-bottom, 20px); }

.login-page { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; padding-top: env(safe-area-inset-top); position: relative; overflow: hidden; background: linear-gradient(135deg, #0ea5e9 0%, #06b6d4 50%, #6366f1 100%); }
.login-bg { position: absolute; inset: 0; overflow: hidden; }
.login-bg-shape { position: absolute; border-radius: 50%; opacity: 0.15; }
.login-bg-shape.shape1 { width: 300px; height: 300px; background: #fff; top: -100px; right: -80px; }
.login-bg-shape.shape2 { width: 200px; height: 200px; background: #fff; bottom: 20%; left: -60px; }
.login-bg-shape.shape3 { width: 80px; height: 80px; background: #fff; top: 40%; right: 15%; }
.login-box { position: relative; background: #fff; padding: 36px 32px; border-radius: 20px; box-shadow: 0 25px 50px -12px rgba(0,0,0,.25); max-width: 320px; width: 100%; text-align: center; }
.login-input-wrap { position: relative; margin-bottom: 20px; }
.login-input-wrap input { width: 100%; padding: 14px 16px; border: 2px solid #e2e8f0; border-radius: 12px; font-size: 16px; transition: border-color .2s, box-shadow .2s; }
.login-input-wrap input:focus { outline: none; border-color: #0ea5e9; box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.15); }
.login-input-wrap input::placeholder { color: #94a3b8; }
.login-btn { width: 100%; padding: 14px 24px; background: linear-gradient(135deg, #0ea5e9, #0284c7); color: #fff; border: none; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; min-height: 50px; transition: transform .2s, box-shadow .2s; }
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4); }
.login-btn:active { transform: translateY(0); }
.login-error { color: #ef4444; font-size: 13px; margin-top: 12px; text-align: center; min-height: 20px; }

.header { background: #0ea5e9; color: #fff; padding: 14px 20px; padding-top: max(14px, env(safe-area-inset-top)); display: flex; justify-content: space-between; align-items: center; }
.header-tabs { display: flex; gap: 4px; }
.tab-btn { padding: 8px 14px; color: rgba(255,255,255,.8); text-decoration: none; font-size: 14px; border-radius: 8px; transition: background .2s, color .2s; }
.tab-btn:hover { color: #fff; background: rgba(255,255,255,.2); }
.tab-btn.active { color: #fff; background: rgba(255,255,255,.25); font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { background: rgba(255,255,255,.2); border: none; color: #fff; width: 36px; height: 36px; border-radius: 8px; font-size: 18px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.icon-btn:hover { background: rgba(255,255,255,.35); }
.header-sync-btn { background: rgba(255,255,255,.2); border: none; color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.header-sync-btn:hover { background: rgba(255,255,255,.35); }
.btn-sync-inline { padding: 6px 12px; background: #10b981; color: #fff; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.btn-sync-inline:hover { background: #059669; }
.header a#logout { color: #fff; text-decoration: none; font-size: 14px; opacity: .9; padding: 8px 0; min-height: 44px; display: flex; align-items: center; }

.date-row { display: flex; gap: 8px; align-items: center; }
.date-row input { flex: 1; }
.date-quick { display: flex; gap: 4px; }
.date-btn { padding: 6px 10px; font-size: 12px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f8fafc; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.date-btn:hover { background: #e2e8f0; }
.work-quick { display: flex; gap: 8px; }
.work-btn { padding: 8px 16px; font-size: 13px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f8fafc; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.work-btn:hover { background: #e2e8f0; }
.work-btn.active { background: #0ea5e9; color: #fff; border-color: #0ea5e9; }
.sync-pwd-row { margin-bottom: 12px; }
.sync-pwd-row label { display: block; font-size: 12px; color: #64748b; margin-bottom: 4px; }
.sync-pwd-row input { width: 100%; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; }

.main { padding: 12px; max-width: 900px; margin: 0 auto; }

.settlement-section { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #fff; padding: 10px 12px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 12px; }
.settlement-label { font-size: 13px; color: #64748b; }
.settlement-input { padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; }
.btn-settlement { padding: 6px 14px; background: #6366f1; color: #fff; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.btn-settlement:hover { background: #4f46e5; }
.settlement-hint { font-size: 12px; color: #94a3b8; }

.form-section { background: #fff; padding: 20px; border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 16px; }
.form-section h3 { font-size: 16px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.form-grid .span-full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; color: #64748b; margin-bottom: 4px; }
.form-grid input, .form-grid select { width: 100%; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 16px; min-height: 44px; }
.btn-save { width: 100%; padding: 16px; background: #0ea5e9; color: #fff; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; min-height: 48px; -webkit-tap-highlight-color: transparent; }

.query-section { background: #fff; padding: 12px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 12px; }
.query-row { margin-bottom: 8px; }
.query-row:last-child { margin-bottom: 0; }
.query-label { display: block; font-size: 12px; color: #64748b; margin-bottom: 6px; }
.query-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.range-btn, .limit-btn, .personal-range-btn, .personal-limit-btn { padding: 6px 12px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; cursor: pointer; color: #64748b; -webkit-tap-highlight-color: transparent; }
.range-btn:hover, .range-btn.active, .personal-range-btn:hover, .personal-range-btn.active { background: #0ea5e9; color: #fff; border-color: #0ea5e9; }
.limit-btn:hover, .limit-btn.active, .personal-limit-btn:hover, .personal-limit-btn.active { background: #10b981; color: #fff; border-color: #10b981; }

.stats-section { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.personal-stats { grid-template-columns: repeat(5, 1fr); }
.personal-stats .stat:nth-child(1) span:last-child { color: #f59e0b; }
.personal-stats .stat:nth-child(2) span:last-child { color: #8b5cf6; }
.personal-stats .stat:nth-child(3) span:last-child { color: #ef4444; }
.personal-stats .stat:nth-child(4) span:last-child { color: #10b981; }
.personal-stats .stat:nth-child(5) span:last-child { color: #6366f1; }
.stat { background: #fff; padding: 10px 12px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.stat .label { display: block; font-size: 11px; color: #64748b; margin-bottom: 2px; }
.stat span:last-child { font-size: 18px; font-weight: 600; }
.stat:nth-child(1) span:last-child { color: #0ea5e9; }
.stat:nth-child(2) span:last-child { color: #10b981; }
.stat:nth-child(3) span:last-child { color: #ef4444; }
.stat:nth-child(4) span:last-child { color: #6366f1; }

.table-section h3 { font-size: 15px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; }
.btn-add { padding: 6px 14px; background: #0ea5e9; color: #fff; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.btn-add:hover { background: #0284c7; }
.table-section { background: #fff; border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.06); overflow: hidden; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.data-table th:nth-child(3), .data-table th:nth-child(4), .data-table th:nth-child(5),
.data-table td:nth-child(3), .data-table td:nth-child(4), .data-table td:nth-child(5) { width: 5em; }
.data-table th, .data-table td { padding: 3px 4px; text-align: left; border-bottom: 1px solid #f1f5f9; line-height: 1.3; }
.data-table th { background: #f8fafc; font-weight: 600; color: #475569; white-space: nowrap; font-size: 12px; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table .num { text-align: right; }
.data-table .cell-income, .data-table .cell-expense, .data-table .cell-profit { padding-left: 2px; padding-right: 2px; white-space: nowrap; }
.data-table .cell-income { color: #10b981; }
.data-table .cell-expense { color: #ef4444; }
.data-table .cell-profit { color: #6366f1; }
.data-table .btn-sm { padding: 2px 6px; font-size: 11px; margin-right: 2px; border-radius: 4px; border: 1px solid #e2e8f0; background: #fff; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.data-table .btn-edit { color: #0ea5e9; border-color: #0ea5e9; }
.data-table .btn-del { color: #ef4444; border-color: #ef4444; }
.data-table tr.after-settlement td { background: #e2e8f0 !important; color: #64748b; }
.data-table tr.after-settlement .cell-income, .data-table tr.after-settlement .cell-expense, .data-table tr.after-settlement .cell-profit { color: #64748b !important; }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; }
.modal.show { opacity: 1; visibility: visible; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-box { position: relative; background: #fff; border-radius: 12px; padding: 20px; max-width: 360px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.15); }
.modal-title { font-size: 16px; margin-bottom: 16px; }
.modal-form .form-row { margin-bottom: 12px; }
.modal-form .form-row label { display: block; font-size: 12px; color: #64748b; margin-bottom: 4px; }
.modal-form .form-row input, .modal-form .form-row select { width: 100%; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; }
.modal-form .form-row-remark { margin-bottom: 16px; }
.modal-form .form-row-remark label { display: flex; align-items: center; gap: 6px; }
.modal-form .form-row-remark label::before { content: ''; width: 4px; height: 14px; background: linear-gradient(180deg, #0ea5e9, #6366f1); border-radius: 2px; }
.modal-form .form-row-remark textarea { width: 100%; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 10px; font-size: 14px; font-family: inherit; line-height: 1.5; resize: vertical; min-height: 80px; background: linear-gradient(180deg, #f8fafc 0%, #fff 100%); transition: border-color .2s, box-shadow .2s; }
.modal-form .form-row-remark textarea:focus { outline: none; border-color: #0ea5e9; box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }
.modal-form .form-row-remark textarea::placeholder { color: #94a3b8; }
.modal-form .form-row input.inp-income { color: #10b981; }
.modal-form .form-row input.inp-expense { color: #ef4444; }
.modal-form .form-row input.inp-profit { color: #6366f1; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal-actions .btn-cancel { flex: 1; padding: 10px; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; font-size: 14px; cursor: pointer; }
.modal-actions .btn-submit { flex: 1; padding: 10px; background: #0ea5e9; color: #fff; border: none; border-radius: 8px; font-size: 14px; cursor: pointer; }
.empty { text-align: center; color: #94a3b8; padding: 32px; }

.record-cards { display: none; padding: 6px; }
.record-card { display: flex; flex-wrap: nowrap; align-items: center; gap: 4px 6px; background: #f8fafc; border-radius: 6px; padding: 4px 6px; margin-bottom: 3px; border: 1px solid #e2e8f0; font-size: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.record-card:last-child { margin-bottom: 0; }
.record-card > span, .record-card .card-actions { flex-shrink: 0; }
.record-card .card-date { min-width: 72px; }
.record-card .card-work { min-width: 24px; }
.record-card .cell-income { color: #10b981; min-width: 48px; text-align: right; }
.record-card .cell-expense { color: #ef4444; min-width: 48px; text-align: right; }
.record-card .cell-profit { color: #6366f1; min-width: 48px; text-align: right; }
.record-card .card-remark { min-width: 40px; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-card .card-actions { display: flex; gap: 2px; margin-left: auto; }
.record-card .btn-sm { padding: 2px 5px; font-size: 11px; border-radius: 4px; border: 1px solid #e2e8f0; background: #fff; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.record-card .btn-edit { color: #0ea5e9; border-color: #0ea5e9; }
.record-card .btn-del { color: #ef4444; border-color: #ef4444; }
.record-card.after-settlement { background: #e2e8f0; color: #64748b; }
.record-card.after-settlement .cell-income, .record-card.after-settlement .cell-expense, .record-card.after-settlement .cell-profit { color: #64748b !important; }

.sync-desc { font-size: 13px; color: #64748b; margin-bottom: 16px; line-height: 1.5; }
.sync-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.btn-sync { padding: 12px 16px; border: 1px solid #0ea5e9; border-radius: 8px; background: #fff; color: #0ea5e9; font-size: 14px; cursor: pointer; text-align: center; -webkit-tap-highlight-color: transparent; }
.btn-sync:hover { background: #f0f9ff; }
.sync-close { width: 100%; margin-top: 8px; }

/* 深色模式 */
body.dark { background: #1e293b; color: #e2e8f0; }
body.dark .settlement-section, body.dark .query-section, body.dark .stat, body.dark .table-section { background: #334155; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
body.dark .settlement-label, body.dark .query-label, body.dark .stat .label { color: #94a3b8; }
body.dark .settlement-input, body.dark .settlement-hint { background: #475569; border-color: #475569; color: #e2e8f0; }
body.dark .range-btn, body.dark .limit-btn, body.dark .personal-range-btn, body.dark .personal-limit-btn { background: #475569; border-color: #475569; color: #94a3b8; }
body.dark .range-btn:hover, body.dark .range-btn.active, body.dark .personal-range-btn:hover, body.dark .personal-range-btn.active { background: #0ea5e9; color: #fff; border-color: #0ea5e9; }
body.dark .limit-btn:hover, body.dark .limit-btn.active, body.dark .personal-limit-btn:hover, body.dark .personal-limit-btn.active { background: #10b981; color: #fff; border-color: #10b981; }
body.dark .data-table th, body.dark .data-table td { border-color: #475569; }
body.dark .data-table th { background: #334155; color: #94a3b8; }
body.dark .data-table tbody tr:hover { background: #475569; }
body.dark .data-table tr.after-settlement td { background: #475569 !important; color: #94a3b8; }
body.dark .record-card { background: #334155; border-color: #475569; }
body.dark .record-card.after-settlement { background: #475569; }
body.dark .modal-box { background: #334155; }
body.dark .modal-form label { color: #94a3b8; }
body.dark .modal-form input, body.dark .modal-form select, body.dark .modal-form textarea { background: #475569; border-color: #475569; color: #e2e8f0; }
body.dark .data-table .btn-sm { background: #475569; border-color: #64748b; color: #e2e8f0; }
body.dark .modal-form .form-row-remark textarea { background: linear-gradient(180deg, #475569 0%, #334155 100%); }
body.dark .date-btn { background: #475569; border-color: #475569; color: #e2e8f0; }
body.dark .date-btn:hover { background: #64748b; }
body.dark .work-btn { background: #475569; border-color: #475569; color: #e2e8f0; }
body.dark .work-btn:hover { background: #64748b; }
body.dark .work-btn.active { background: #0ea5e9; color: #fff; border-color: #0ea5e9; }
body.dark .sync-pwd-row input { background: #475569; border-color: #475569; color: #e2e8f0; }
body.dark .btn-sync-inline { background: #059669; }
body.dark .btn-sync-inline:hover { background: #047857; }
body.dark .modal-actions .btn-cancel { background: #475569; border-color: #475569; color: #e2e8f0; }
body.dark .empty { color: #64748b; }
body.dark .sync-desc { color: #94a3b8; }
body.dark .btn-sync { background: #475569; border-color: #64748b; color: #e2e8f0; }
body.dark .btn-sync:hover { background: #64748b; }

@media (max-width: 768px) {
  .main { padding: 12px; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid input, .form-grid select { font-size: 16px; }
  .stats-section { grid-template-columns: repeat(2, 1fr); }
  .personal-stats { grid-template-columns: repeat(2, 1fr); }
  .stat { padding: 14px; }
}

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-full { grid-column: 1; }
  .record-card { font-size: 11px; padding: 3px 4px; gap: 2px 4px; }
  .record-card .card-date { min-width: 64px; }
  .record-card .cell-income, .record-card .cell-expense, .record-card .cell-profit { min-width: 42px; }
  .record-card .card-remark { min-width: 32px; max-width: 60px; }
}
