:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #14201d;
  --muted: #6b7c78;
  --line: #e2e8e6;
  --brand: #0f766e;
  --brand-dark: #0b544e;
  --brand-soft: #d7efec;
  --accent: #f59e0b;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 32, 29, 0.08), 0 6px 20px rgba(20, 32, 29, 0.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand);
  color: #fff;
  padding: 0.7rem 1rem 0;
  box-shadow: 0 2px 10px rgba(11, 84, 78, 0.25);
}
.brand { display: flex; align-items: center; gap: 0.65rem; }
.brand-logo {
  font-size: 1.6rem; line-height: 1;
  background: rgba(255,255,255,0.15);
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
}
.brand-title { margin: 0; font-size: 1.15rem; font-weight: 700; }
.brand-sub { font-size: 0.78rem; opacity: 0.85; }

.tabs { display: flex; gap: 0.25rem; margin-top: 0.7rem; overflow-x: auto; }
.tab {
  flex: 0 0 auto;
  background: transparent; border: none; color: #d7efec;
  padding: 0.6rem 0.95rem; font-size: 0.92rem; font-weight: 600;
  border-bottom: 3px solid transparent; cursor: pointer;
  border-radius: 8px 8px 0 0;
}
.tab.is-active { color: #fff; border-bottom-color: var(--accent); }

/* ---------- Layout ---------- */
.app-main { max-width: 900px; margin: 0 auto; padding: 1rem; }
.tab-panel { display: none; animation: fade 0.2s ease; }
.tab-panel.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem; margin-bottom: 1rem;
}
.card-title { margin: 0 0 0.9rem; font-size: 1rem; font-weight: 700; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Form ---------- */
.field { margin-bottom: 1rem; }
.field > label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin-bottom: 0.4rem; }
input, select {
  width: 100%; padding: 0.7rem 0.8rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.segmented { display: flex; gap: 0.4rem; }
.segmented.wrap { flex-wrap: wrap; }
.seg {
  flex: 1 1 auto; min-width: 90px;
  padding: 0.6rem 0.5rem; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; font-size: 0.9rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg.is-active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }

.weight-row { display: flex; align-items: center; gap: 0.4rem; }
.weight-row input { text-align: center; font-size: 1.3rem; font-weight: 700; }
.step {
  flex: 0 0 auto; width: 52px; height: 48px; border: 1px solid var(--line);
  background: #fff; border-radius: 10px; font-size: 0.95rem; font-weight: 700; color: var(--brand-dark); cursor: pointer;
}
.step:active { background: var(--brand-soft); }

.photo-preview { margin-top: 0.6rem; max-height: 160px; border-radius: 10px; display: block; }

.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 0.5rem; }
.est-cost { font-size: 0.9rem; color: var(--muted); font-weight: 600; }

.btn {
  padding: 0.7rem 1.1rem; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; font-size: 0.92rem; font-weight: 700; color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 0.7rem 1.2rem; border-radius: 999px;
  font-weight: 600; box-shadow: var(--shadow); z-index: 40;
}

/* ---------- Dashboard ---------- */
.range-bar, .records-toolbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.range {
  padding: 0.5rem 1rem; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.range.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.7rem; margin-bottom: 1rem; }
@media (max-width: 640px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.9rem; }
.kpi-label { display: block; font-size: 0.76rem; color: var(--muted); font-weight: 600; }
.kpi-value { display: block; font-size: 1.5rem; font-weight: 800; margin-top: 0.3rem; }

.chart { display: flex; align-items: flex-end; gap: 0.35rem; height: 160px; padding-top: 0.5rem; }
.chart .col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; height: 100%; justify-content: flex-end; }
.chart .col .bar { width: 70%; min-height: 2px; background: var(--brand); border-radius: 6px 6px 0 0; transition: height 0.3s; }
.chart .col .lbl { font-size: 0.68rem; color: var(--muted); }

.bars { display: flex; flex-direction: column; gap: 0.6rem; }
.bar-row { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.bar-row .track { background: var(--bg); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--brand); border-radius: 999px; }
.bar-row .val { font-weight: 700; font-size: 0.82rem; }

.top-list { margin: 0; padding-left: 1.3rem; }
.top-list li { padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
.top-list li:last-child { border-bottom: none; }
.top-list .amt { float: right; font-weight: 700; color: var(--brand-dark); }

/* ---------- Records table ---------- */
.records-toolbar input { flex: 1; }
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.records-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.records-table th, .records-table td { padding: 0.6rem 0.7rem; text-align: left; white-space: nowrap; }
.records-table thead th { background: #f0f4f3; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
.records-table tbody tr { border-top: 1px solid var(--line); }
.row-del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1.1rem; }
.tag { font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }

/* ---------- Settings ---------- */
.chip-editor { display: flex; flex-direction: column; gap: 0.7rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { display: inline-flex; align-items: center; gap: 0.4rem; background: var(--brand-soft); color: var(--brand-dark); padding: 0.35rem 0.7rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600; }
.chip button { background: none; border: none; color: var(--brand-dark); cursor: pointer; font-size: 1rem; line-height: 1; }
.chip-add { display: flex; gap: 0.5rem; }
.settings-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.danger-card { border: 1px solid var(--danger-soft); }
.muted { color: var(--muted); font-size: 0.82rem; margin: 0.6rem 0 0; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }

.api-status { font-size: 0.85rem; font-weight: 700; align-self: center; }
.api-status.on { color: var(--brand); }
.api-status.off { color: var(--danger); }
.api-status.local { color: var(--accent); }
