:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #64748b;
  --line: #dbe5f1;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --accent: #f97316;
  --danger-soft: #fb923c;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 14px 40px rgba(37, 99, 235, 0.28);
  --ease: 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Noto Sans";
  color: var(--text);
  background:
    radial-gradient(1000px 420px at 100% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(860px 360px at 0% -8%, #ffedd5 0%, transparent 48%),
    var(--bg);
}

button, input {
  font: inherit;
}

button {
  transition: transform var(--ease), box-shadow var(--ease), background-color var(--ease), border-color var(--ease), opacity var(--ease);
}

button:focus-visible, input:focus-visible, .import-label:focus-within {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  outline-offset: 2px;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 16px 104px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 2.8vw, 30px);
  letter-spacing: -0.02em;
}

.top-actions, .filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.filters {
  margin: 14px 0 18px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
}

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}

.chip:hover {
  transform: translateY(-1px);
  border-color: #bfdbfe;
}

.chip:active {
  transform: translateY(0);
}

.chip.active {
  background: linear-gradient(180deg, #3b82f6 0%, var(--primary) 100%);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.28);
}

.date-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.date-label input {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

canvas {
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}

table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}

thead th {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 13px;
}

th, td {
  padding: 11px 10px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
}

tbody tr:hover {
  background: #f8fbff;
}

tbody td:last-child {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.empty {
  margin: 12px 0 0;
  color: var(--text-secondary);
  display: none;
  text-align: center;
  padding: 12px;
}

.fab {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #3b82f6 0%, var(--primary) 100%);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 26px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.fab:hover { transform: translateX(-50%) translateY(-1px); }
.fab:active { transform: translateX(-50%); }

dialog {
  border: 1px solid var(--line);
  border-radius: 20px;
  width: min(430px, 92vw);
  padding: 0;
  box-shadow: var(--shadow-md);
  background: rgba(255, 255, 255, 0.98);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(2px);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
}

dialog h3 {
  margin: 0 0 2px;
  font-size: 20px;
  letter-spacing: -0.01em;
}

dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 600;
}

.weight-field .field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  white-space: nowrap;
}

.weight-field .field-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inline-unit-btn {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: var(--primary-strong);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  flex: 0 0 auto;
}

.inline-unit-btn:hover {
  transform: translateY(-1px);
  background: #dbeafe;
}

.inline-unit-btn:active {
  transform: translateY(0);
}

dialog input[type="date"], dialog input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: #fff;
}

dialog input[type="date"]:hover, dialog input[type="number"]:hover {
  border-color: #bfdbfe;
}

small {
  color: var(--text-secondary);
  line-height: 1.45;
}

.quick-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.quick-row button {
  border: none;
  border-radius: 11px;
  padding: 10px;
  cursor: pointer;
  font-weight: 700;
  color: #fff;
}

.quick-row.minus button {
  background: linear-gradient(180deg, #fdba74 0%, var(--danger-soft) 100%);
}

.quick-row.plus button {
  background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
}

.quick-row button:hover {
  transform: translateY(-1px);
  filter: saturate(1.05);
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  margin: 10px 0 0;
}

menu button, .import-label, #downloadTemplateBtn, #exportBtn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 9px 12px;
  cursor: pointer;
}

#saveRecordBtn, #downloadTemplateBtn, #exportBtn {
  background: linear-gradient(180deg, #3b82f6 0%, var(--primary) 100%);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
}

#saveRecordBtn:hover, #downloadTemplateBtn:hover, #exportBtn:hover {
  transform: translateY(-1px);
}

.import-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-secondary);
  font-weight: 600;
}

.import-label input {
  display: block;
  margin-top: 2px;
}

@media (max-width: 640px) {
  .app { padding-top: 14px; padding-bottom: 110px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 8px; }
  .top-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .chip { padding: 8px 12px; }
  .filters { gap: 6px; padding: 10px 8px; }
  .filters .chip { flex: 1; text-align: center; }
  .date-label { width: 100%; justify-content: space-between; }
  .date-label input { width: 62%; }
  .card { border-radius: 14px; padding: 14px 12px; }
  dialog { width: 96vw; border-radius: 16px; }
  dialog form { padding: 14px; gap: 10px; }
  .weight-field .field-head { gap: 8px; }
  .inline-unit-btn { padding: 5px 9px; font-size: 12px; }
  .quick-row button { min-height: 40px; }
  .fab { width: calc(100vw - 28px); max-width: 380px; text-align: center; }
  menu { justify-content: stretch; }
  menu button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0ms !important;
    transition-duration: 0ms !important;
    scroll-behavior: auto !important;
  }
}
