:root {
  --primary: #0F6E56;
  --primary-strong: #0B5744;
  --primary-soft: #E1F5EE;
  --bg: #f2f4f3;
  --card: #ffffff;
  --text: #16231f;
  --muted: #6b7a75;
  --line: #e6ebe9;
  --danger: #C2413C;
  --danger-soft: #FCEBEB;
  --amber: #B45309;
  --amber-soft: #FEF3E2;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(22, 40, 34, .06), 0 1px 2px rgba(22, 40, 34, .04);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

#app { max-width: 520px; margin: 0 auto; min-height: 100%; padding-bottom: 84px; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; font-size: 16px; color: var(--text); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  background: rgba(242, 244, 243, .86);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-size: 19px; font-weight: 600; letter-spacing: .5px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--line); }

/* ---------- Tip bar ---------- */
.tipbar {
  margin: 0 16px 12px; padding: 10px 12px;
  background: var(--primary-soft); color: var(--primary-strong);
  border-radius: 12px; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.tipbar b { font-weight: 600; }
.tip-close { margin-left: auto; font-size: 18px; color: var(--primary-strong); opacity: .6; width: 26px; height: 26px; }

/* ---------- Views ---------- */
.view { padding: 4px 16px 24px; }

/* ---------- Hero metrics ---------- */
.hero { margin-bottom: 18px; }
.hero-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.metric {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.metric-label { font-size: 12px; color: var(--muted); }
.metric-value { font-size: 26px; font-weight: 600; letter-spacing: -.5px; margin-top: 2px; font-variant-numeric: tabular-nums; color: var(--primary); }
.metric-unit { font-size: 11px; color: var(--muted); }
.hero-sub { margin-top: 10px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- Section ---------- */
.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 4px 2px 10px;
}
.section-title > span:first-child { font-size: 16px; font-weight: 600; }
.section-count { font-size: 12.5px; color: var(--muted); }

/* ---------- Record cards ---------- */
.rec {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 10px;
}
.rec-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.rec-date { font-weight: 600; font-size: 14px; }
.rec-note { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-full {
  margin-left: auto; font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.rec-cons {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--amber-soft); color: var(--amber); font-weight: 600; white-space: nowrap;
}
.rec-cons.ref { background: var(--bg); color: var(--muted); }
.rec-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rec-cell .k { font-size: 11px; color: var(--muted); }
.rec-cell .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-cell .u { font-size: 11px; color: var(--muted); }
.rec-foot {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  padding-top: 10px; border-top: 1px dashed var(--line); font-size: 12.5px; color: var(--muted);
}
.rec-photo { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); }
.rec-del { margin-left: auto; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.rec-del:active { background: var(--danger-soft); color: var(--danger); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty svg { color: #b9c6c1; margin-bottom: 10px; }
.empty .t1 { font-size: 15px; color: var(--text); font-weight: 600; margin-bottom: 4px; }
.empty .t2 { font-size: 13px; }
.empty .empty-btn { margin-top: 16px; }

/* ---------- Tab bar & FAB ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: 100%; max-width: 520px; z-index: 30;
  display: grid; grid-template-columns: 1fr 84px 1fr;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px; color: var(--muted); font-size: 11px;
}
.tab.active { color: var(--primary); font-weight: 600; }
.fab-holder { position: relative; display: flex; align-items: center; justify-content: center; }
.fab {
  position: absolute; top: -26px;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(15, 110, 86, .35);
}
.fab:active { background: var(--primary-strong); }

/* ---------- Pages (overlay) ---------- */
.page {
  position: fixed; inset: 0; z-index: 40;
  background: var(--bg);
  max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column;
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 10px; background: rgba(242,244,243,.92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.page-title { font-size: 17px; font-weight: 600; }
.save-btn {
  background: var(--primary); color: #fff; border-radius: 12px;
  padding: 8px 18px; font-size: 14px; font-weight: 600;
}
.save-btn:active { background: var(--primary-strong); }
.page-body { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---------- Form ---------- */
.form-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label, .field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; background: #f4f6f5; border: 1px solid transparent;
  border-radius: 12px; padding: 13px 14px; outline: none;
  transition: border-color .15s, background .15s;
}
.field input:focus { border-color: var(--primary); background: #fff; }
.field-hint { font-size: 12px; color: var(--primary); margin-top: 5px; min-height: 0; }
.field-hint:empty { display: none; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line);
}
.switch-title { font-size: 14px; font-weight: 600; }
.switch-sub { font-size: 12px; color: var(--muted); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 20px; background: #d7ddda;
  transition: background .18s;
}
.slider::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .18s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ---------- Photo & OCR ---------- */
.photo-box {
  border: 1.5px dashed #c9d4d0; border-radius: 14px;
  padding: 14px; position: relative;
}
.photo-empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 22px 0; color: #9db0aa; cursor: pointer;
}
.photo-empty-text { font-size: 13px; }
.photo-preview { width: 100%; border-radius: 10px; display: block; }
.photo-actions { display: flex; gap: 10px; margin-top: 10px; }
.ghost-btn {
  flex: 1; padding: 11px 0; border-radius: 12px; font-size: 14px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.ghost-btn.primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 600; }
.ghost-btn:active { opacity: .75; }
.ocr-bar { margin-top: 12px; }
.ocr-text { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.ocr-progress { height: 6px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.ocr-progress-in { height: 100%; width: 0; background: var(--primary); border-radius: 4px; transition: width .15s; }
.ocr-result { margin-top: 12px; background: var(--bg); border-radius: 12px; padding: 12px; }
.ocr-result-title { font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }
.ocr-lines { font-size: 12px; color: var(--muted); max-height: 140px; overflow-y: auto; line-height: 1.7; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- Stats ---------- */
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.stat-card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.chart-wrap { width: 100%; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-line { background: var(--primary); }
.dot-avg { background: var(--danger); }

.trip-row {
  display: grid; grid-template-columns: 74px 1fr auto;
  gap: 6px 12px; padding: 10px 2px; border-bottom: 1px solid var(--line);
  align-items: center;
}
.trip-row:last-child { border-bottom: none; }
.trip-date { font-size: 12.5px; color: var(--muted); }
.trip-main { font-size: 13px; }
.trip-main b { font-weight: 600; }
.trip-cons { text-align: right; font-size: 15px; font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; }
.trip-cons .u { font-size: 11px; color: var(--muted); font-weight: 400; }
.trip-cons.ref { color: var(--muted); }

/* ---------- Settings ---------- */
.settings-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.settings-group-title { font-size: 12px; color: var(--muted); padding: 12px 16px 6px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-top: 1px solid var(--line); font-size: 14px; }
.settings-row:first-of-type { border-top: none; }
.row-btn { font-size: 13px; color: var(--primary); font-weight: 600; padding: 6px 10px; border-radius: 8px; }
.row-btn:active { background: var(--primary-soft); }
.row-btn.danger { color: var(--danger); }
.row-btn.danger:active { background: var(--danger-soft); }
.row-select { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 13px; background: #fff; max-width: 60%; }
.row-muted { font-size: 13px; color: var(--muted); }
.settings-hint { font-size: 12px; color: var(--muted); padding: 4px 16px 14px; line-height: 1.6; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: rgba(22, 35, 31, .92); color: #fff;
  padding: 10px 18px; border-radius: 12px; font-size: 13.5px; z-index: 99;
  max-width: 86%; text-align: center;
  animation: fadeUp .2s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff; border-radius: 14px;
  padding: 12px 22px; font-size: 14px; font-weight: 600;
}
.btn:active { background: var(--primary-strong); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.soft:active { background: #d3efe4; }
.btn.block { width: 100%; justify-content: center; }

/* ---------- CSV import ---------- */
.csv-hint { background: var(--primary-soft); color: var(--primary-strong); border-radius: 12px; padding: 12px 14px; font-size: 12.5px; line-height: 1.7; margin-bottom: 16px; }
.csv-file-name { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.csv-map-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.csv-map-row:last-child { border-bottom: none; }
.csv-map-label { font-size: 14px; flex: none; }
.csv-map-label .req { color: var(--danger); margin-left: 3px; }
.csv-map-row .row-select { max-width: 56%; }
.csv-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.csv-tbl th, .csv-tbl td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csv-tbl th { background: #f4f6f5; color: var(--muted); font-weight: 600; }
.csv-preview { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }
