:root {
  --gold: #b8860b;
  --gold-soft: #f6ecd4;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2024;
  --muted: #6b7280;
  --line: #e3e6ea;
  --green: #17803d;
  --red: #c0322b;
  --blue: #1d4ed8;
  --orange: #c2610c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --nav-h: 62px;
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- Khung ứng dụng ---------- */
.app-header {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(135deg, #c9971a, #a3730a);
  color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.app-header h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; }
.app-header .sub { font-size: 12px; opacity: .85; font-weight: 400; display: block; }
.header-btn {
  background: rgba(255,255,255,.18); border: 0; color: #fff;
  width: 36px; height: 36px; border-radius: 10px; font-size: 17px; cursor: pointer;
}

main { padding: 14px 14px calc(var(--nav-h) + 24px); max-width: 900px; margin: 0 auto; }
main.full { padding: 0; max-width: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; text-align: center; padding: 8px 2px 10px; text-decoration: none;
  color: var(--muted); font-size: 11px; line-height: 1.3;
}
.bottom-nav a .ic { display: block; font-size: 19px; margin-bottom: 2px; }
.bottom-nav a.active { color: var(--gold); font-weight: 600; }

/* ---------- Thành phần ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card.tight { padding: 0; overflow: hidden; }
.card h2 { margin: 0 0 10px; font-size: 15px; }

.section-title { margin: 18px 4px 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.stat { background: #fff; border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 19px; font-weight: 700; margin-top: 3px; }
.stat .value.sm { font-size: 16px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fff;
  cursor: pointer;
}
.list li:last-child { border-bottom: 0; }
.list li:active { background: #fafafa; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .right { text-align: right; white-space: nowrap; }

.empty { padding: 30px 14px; text-align: center; color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: #eef1f5; color: var(--muted);
}
.badge.green { background: #e6f5ec; color: var(--green); }
.badge.red   { background: #fdecea; color: var(--red); }
.badge.blue  { background: #e8eefc; color: var(--blue); }
.badge.orange{ background: #fdf0e2; color: var(--orange); }
.badge.gold  { background: var(--gold-soft); color: #8a6508; }

.money { font-weight: 700; }
.money.red { color: var(--red); }
.money.green { color: var(--green); }

/* ---------- Form ---------- */
label.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
label.field > span { display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
textarea { min-height: 68px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px; border-radius: 11px; border: 1px solid transparent;
  background: var(--gold); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.blue { background: var(--blue); }
.btn.sm { padding: 8px 12px; font-size: 13.5px; border-radius: 9px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

.search { display: flex; gap: 8px; margin-bottom: 12px; }
.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 13px; cursor: pointer; color: var(--muted);
}
.chip.active { background: var(--gold); border-color: var(--gold); color: #fff; font-weight: 600; }

/* ---------- Bản đồ ---------- */
#map { position: absolute; inset: 0; bottom: var(--nav-h); }
.map-wrap { position: fixed; inset: 0; top: 56px; }
.map-tools {
  position: absolute; z-index: 500; right: 12px; bottom: calc(var(--nav-h) + 14px);
  display: flex; flex-direction: column; gap: 8px;
}
.map-tools button {
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: #fff;
  box-shadow: var(--shadow); font-size: 19px; cursor: pointer;
}
.map-tools button.primary { background: var(--gold); color: #fff; }
.map-legend {
  position: absolute; z-index: 500; left: 12px; bottom: calc(var(--nav-h) + 14px);
  background: rgba(255,255,255,.94); border-radius: 10px; padding: 8px 10px;
  font-size: 11.5px; box-shadow: var(--shadow); line-height: 1.7;
}
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,.35);
}

/* ---------- Modal / sheet ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,20,26,.45); z-index: 1000;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp .18s ease-out;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6 } to { transform: none; opacity: 1 } }
.sheet h3 { margin: 2px 0 14px; font-size: 17px; }
.sheet .close { position: absolute; }

.toast-host { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 16px); z-index: 2000; pointer-events: none; }
.toast {
  background: #22262b; color: #fff; padding: 11px 14px; border-radius: 11px;
  margin-top: 8px; font-size: 14px; box-shadow: var(--shadow); animation: slideUp .15s;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.warn-box { background: #fff8e6; border: 1px solid #f0dca8; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.err-box { background: #fdecea; border: 1px solid #f5c6c2; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; color: #8a231e; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); }
table.data th { color: var(--muted); font-size: 12px; font-weight: 600; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
table.data td:first-child, table.data th:first-child { white-space: nowrap; }
.scroll-x { overflow-x: auto; }

/* ---------- Đăng nhập ---------- */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(160deg, #c9971a, #8a6508);
}
.login-card { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 380px; box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.login-card .logo { text-align: center; font-size: 40px; }
.login-card h1 { text-align: center; font-size: 19px; margin: 6px 0 4px; }
.login-card p.sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 18px; }

@media (min-width: 720px) {
  .grid3 { grid-template-columns: repeat(4, 1fr); }
}
