:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efeae2;
  --text: #221c16;
  --muted: #6f655b;
  --border: #e5ddd2;
  --accent: #7a4b2a;
  --accent-soft: #f2e6da;
  --green: #1e7e4d;
  --green-soft: #e5f5ec;
  --red: #c23b2b;
  --red-soft: #fceae7;
  --amber: #b36b00;
  --amber-soft: #fff4df;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(34, 28, 22, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171411;
    --surface: #221e1a;
    --surface-2: #2d2722;
    --text: #f3ede5;
    --muted: #a99e92;
    --border: #36302a;
    --accent: #d39664;
    --accent-soft: #382a1e;
    --green: #52c987;
    --green-soft: #1b3426;
    --red: #f17466;
    --red-soft: #3b201d;
    --amber: #f3b552;
    --amber-soft: #382c18;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
  }
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  padding-bottom: 76px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}

.content {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 19px;
  font-weight: 700;
}

.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-accent { color: var(--accent); }
.text-muted { color: var(--muted); }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 2px 6px;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 8px;
}

.card-clickable {
  cursor: pointer;
  transition: transform 0.08s ease;
}

.card-clickable:active {
  transform: scale(0.99);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
}

.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }

.alert-item {
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.alert-item.warn { background: var(--amber-soft); border: 1px solid rgba(179, 107, 0, 0.25); }
.alert-item.danger { background: var(--red-soft); border: 1px solid rgba(194, 59, 43, 0.25); }
.alert-title { font-weight: 700; font-size: 13px; }
.alert-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.btn {
  border: none;
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-green { background: var(--green); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 9px; }
.btn-block { width: 100%; }

.form-group {
  margin-bottom: 10px;
}
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--muted);
  font-size: 13px;
}

/* Tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px;
  cursor: pointer;
}
.tab-btn .tab-ico { font-size: 18px; }
.tab-btn.active { color: var(--accent); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.hidden { display: none; }

.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 14px 16px 24px;
  overflow-y: auto;
}

.toast {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.toast.hidden { display: none; }
