:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #4f9cf9;
  --accent-dim: #3a7bd5;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(79, 156, 249, 0.15), transparent),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.header h1 {
  margin: 0 0 6px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.sync-status {
  margin: 8px 0 0;
  font-size: 0.82rem;
  font-weight: 500;
}

.sync-loading { color: var(--warning); }
.sync-ok { color: var(--success); }
.sync-error { color: var(--danger); }

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.history-panel,
.charts-panel {
  grid-column: 1 / -1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 18px;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card h3 {
  margin: 0 0 12px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
}

.badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--muted);
}

.sliders {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.slider-row {
  display: grid;
  grid-template-columns: 88px 1fr 64px;
  align-items: center;
  gap: 12px;
}

.slider-row label {
  font-size: 0.95rem;
  font-weight: 500;
}

.slider-row input[type="range"] {
  width: 100%;
  height: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}

.slider-row input[type="number"] {
  width: 64px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
}

.slider-row input[type="number"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.sum-bar {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.sum-info {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.sum-info strong {
  font-size: 1.5rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.sum-track {
  height: 8px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}

.sum-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.2s ease, background 0.2s ease;
}

.sum-fill.over {
  background: linear-gradient(90deg, #dc2626, var(--danger));
}

.sum-fill.exact {
  background: linear-gradient(90deg, #059669, var(--success));
}

.hint {
  margin: 10px 0 0;
  font-size: 0.82rem;
}

.hint.ok { color: var(--muted); }
.hint.warn { color: var(--warning); }
.hint.err { color: var(--danger); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:not(:disabled):hover {
  background: var(--accent-dim);
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--border);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

.btn-icon {
  padding: 4px 10px;
  font-size: 0.8rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
}

.btn-icon:hover {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.1);
}

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.stats-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

@media (max-width: 700px) {
  .stat-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card {
  background: var(--surface2);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-card .name {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-card .total {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-card .avg {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.chart-box {
  position: relative;
  height: 260px;
}

.chart-box.tall {
  height: 300px;
  margin-bottom: 24px;
}

.chart-box.tall:last-child {
  margin-bottom: 0;
}

.table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.history-table th,
.history-table td {
  padding: 10px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
}

.history-table td:first-child,
.history-table th:first-child {
  text-align: left;
}

.history-table tbody tr:hover {
  background: rgba(79, 156, 249, 0.06);
}

.history-table .time {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  z-index: 1000;
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.5);
  color: var(--danger);
}

.toast.success {
  border-color: rgba(52, 211, 153, 0.5);
}
