/* ========== Gửi Xe — phong cách Matcha ========== */
:root {
  --bg: #F4F1E8;
  --card: #FFFDF7;
  --card-2: #F9F6EC;
  --line: #E6E1D2;
  --text: #1F271B;
  --muted: #6E7766;
  --matcha: #78A04F;
  --matcha-deep: #3F5F2E;
  --leaf: #DDE7C7;
  --leaf-2: #EEF3E2;
  --danger: #B0412F;
  --danger-bg: #F6E3DE;
  --warn: #A6741B;
  --warn-bg: #F6ECD4;
  --shadow: 0 1px 2px rgba(47, 74, 36, .06), 0 6px 24px rgba(47, 74, 36, .07);
  --radius: 20px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111510;
    --card: #1A2017;
    --card-2: #20271C;
    --line: #2C3527;
    --text: #E9EEDF;
    --muted: #93A086;
    --matcha: #8FB46A;
    --matcha-deep: #B8D08A;
    --leaf: #2E3B25;
    --leaf-2: #232C1D;
    --danger: #E07A66;
    --danger-bg: #3A2420;
    --warn: #E0B25E;
    --warn-bg: #352C1A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px; line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--matcha-deep); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Khởi động ---------- */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.leaf {
  width: 44px; height: 44px; border-radius: 0 50% 0 50%;
  background: linear-gradient(135deg, var(--matcha), var(--matcha-deep));
  animation: breathe 1.4s var(--ease) infinite;
}
@keyframes breathe { 50% { transform: scale(.82) rotate(12deg); opacity: .6; } }

/* ---------- Khung ---------- */
.shell { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.shell.wide { max-width: 1040px; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 0 18px; }
.topbar .hello { flex: 1; min-width: 0; }
.topbar .hello small { display: block; color: var(--muted); font-size: 13px; }
.topbar .hello b { font-size: 19px; font-weight: 700; letter-spacing: -.01em; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none;
  background: var(--leaf); color: var(--matcha-deep); font-weight: 700;
  display: grid; place-items: center; transition: transform .2s var(--ease);
}
.avatar:active { transform: scale(.92); }

.view { animation: viewIn .38s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px; border: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 4px 10px; }
.section-title h2 { margin: 0; font-size: 16px; font-weight: 700; }

/* ---------- Hero tổng tháng ---------- */
.hero {
  position: relative; overflow: hidden; color: #F7FAEF;
  background: linear-gradient(140deg, #86AE5C 0%, #4E7535 55%, #34502A 100%);
  border: 0;
}
.hero::after {
  content: ''; position: absolute; right: -40px; top: -50px; width: 190px; height: 190px;
  border-radius: 0 50% 0 50%; background: rgba(255, 255, 255, .08); transform: rotate(18deg);
}
.hero .label { font-size: 13px; opacity: .85; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin: 2px 0 12px; }
.hero .stats { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; }
.hero .stats b { display: block; font-size: 16px; font-weight: 600; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--leaf); color: var(--matcha-deep); white-space: nowrap;
}
.hero .chip { background: rgba(255, 255, 255, .18); color: #fff; }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.ghost { background: var(--card-2); color: var(--muted); }
.hero .chips { position: absolute; right: 16px; top: 16px; display: flex; gap: 6px; z-index: 1; }

/* ---------- Thẻ hôm nay ---------- */
.today { display: flex; align-items: center; gap: 14px; }
.today .ic {
  width: 52px; height: 52px; border-radius: 16px; flex: none; display: grid; place-items: center;
  background: var(--leaf-2); color: var(--matcha-deep); font-size: 24px;
}
.today.done .ic { background: var(--matcha); color: #fff; animation: pop .45s var(--ease); }
.today .txt { flex: 1; min-width: 0; }
.today .txt b { display: block; font-weight: 600; }
.today .txt span { color: var(--muted); font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.today .thumb { width: 52px; height: 52px; border-radius: 12px; object-fit: cover; flex: none; }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 600; font-size: 15px;
  background: var(--card-2); color: var(--text);
  transition: transform .15s var(--ease), background .2s, opacity .2s, box-shadow .2s;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: linear-gradient(135deg, var(--matcha), #4E7535); color: #fff; box-shadow: 0 6px 16px rgba(78, 117, 53, .25); }
.btn.soft { background: var(--leaf); color: var(--matcha-deep); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 11px; }
.btn.icon { padding: 0; width: 40px; height: 40px; border-radius: 12px; }
.btn .spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- Lịch tháng ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav b { font-size: 16px; font-weight: 700; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 380px) { .cal { gap: 4px; } }
.cal .wd { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); padding-bottom: 2px; }
.cal .wd.sun { color: var(--danger); }
.day {
  position: relative; aspect-ratio: 1; border-radius: 14px; border: 0; padding: 0;
  background: var(--card-2); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px; transition: transform .18s var(--ease), background .25s, color .25s;
}
.day:active { transform: scale(.9); }
.day.empty { background: transparent; pointer-events: none; }
.day.future { opacity: .35; pointer-events: none; }
.day.today { box-shadow: inset 0 0 0 2px var(--matcha); }
.day.on { background: var(--matcha); color: #fff; }
.day.on.today { box-shadow: inset 0 0 0 2px var(--matcha-deep); }
.day .amt { font-size: 9.5px; font-weight: 500; opacity: .9; line-height: 1; margin-top: 2px; }
.day .dots { position: absolute; top: 5px; right: 6px; display: flex; gap: 2px; }
.day .dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .75; }
.day.just { animation: pop .45s var(--ease); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 4px; background: var(--matcha); display: inline-block; }

/* ---------- Danh sách ---------- */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%;
  transition: background .2s;
}
.item:last-child { border-bottom: 0; }
button.item:active { background: var(--card-2); }
.item .main { flex: 1; min-width: 0; }
.item .main b { display: block; font-weight: 600; }
.item .main small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .right { text-align: right; flex: none; }
.item .right b { display: block; font-weight: 700; }
.item .right small { color: var(--muted); }
.item .thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; background: var(--card-2); }
.date-badge {
  width: 44px; height: 44px; border-radius: 12px; flex: none; background: var(--leaf-2); color: var(--matcha-deep);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
}
.date-badge b { font-size: 16px; }
.date-badge small { font-size: 10px; font-weight: 600; }
.empty-state { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty-state .big { font-size: 34px; margin-bottom: 6px; }

/* ---------- Thanh điều hướng (quản lý) ---------- */
.tabbar {
  position: fixed; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 4px; padding: 6px; border-radius: 22px; z-index: 20;
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 34px rgba(47, 74, 36, .18); border: 1px solid var(--line);
  width: max-content; max-width: calc(100% - 24px);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 14px; border-radius: 16px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; transition: background .25s, color .25s;
  min-width: 64px; white-space: nowrap;
}
@media (max-width: 380px) { .tabbar a { padding: 7px 10px; min-width: 0; } }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { background: var(--leaf); color: var(--matcha-deep); }

/* ---------- Thống kê quản lý ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.stat small { color: var(--muted); font-size: 12px; display: block; }
.stat b { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.stat.accent { background: var(--leaf); }
.stat.accent b { color: var(--matcha-deep); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .btn { flex: 1 1 auto; }
.lock-banner { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--warn-bg); color: var(--warn); font-size: 13px; font-weight: 500; margin-bottom: 14px; }
.paid-toggle {
  border: 0; border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 600;
  background: var(--card-2); color: var(--muted); transition: background .2s, color .2s;
}
.paid-toggle.on { background: var(--leaf); color: var(--matcha-deep); }
.search { width: 100%; margin-bottom: 10px; }

/* ---------- Form ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--card); outline: none; transition: border-color .2s, box-shadow .2s; font-size: 16px;
}
.input:focus { border-color: var(--matcha); box-shadow: 0 0 0 4px color-mix(in srgb, var(--matcha) 18%, transparent); }
textarea.input { resize: vertical; min-height: 76px; }
.money-input { position: relative; }
.money-input .input { font-size: 22px; font-weight: 700; padding-right: 44px; }
.money-input::after { content: 'đ'; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; font-size: 18px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.quick button { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; transition: all .2s; }
.quick button.on { border-color: var(--matcha); background: var(--leaf); color: var(--matcha-deep); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 14px; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; transition: background .25s; flex: none; margin: 0; }
.switch input::after { content: ''; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .25s var(--ease); }
.switch input:checked { background: var(--matcha); }
.switch input:checked::after { transform: translateX(18px); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: -4px 0 10px; }

/* ---------- Ảnh hóa đơn ---------- */
.photo-box { border: 1.5px dashed var(--line); border-radius: 16px; padding: 12px; background: var(--card-2); }
.photo-box .preview { position: relative; }
.photo-box img { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; display: block; background: var(--card); animation: fadeIn .3s var(--ease); }
.photo-box .rm { position: absolute; top: 8px; right: 8px; background: rgba(20, 25, 18, .6); color: #fff; border: 0; width: 34px; height: 34px; border-radius: 50%; font-size: 18px; }
.photo-box .size { position: absolute; left: 8px; bottom: 8px; background: rgba(20, 25, 18, .6); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
@keyframes fadeIn { from { opacity: 0; } }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(17, 21, 16, .38); z-index: 50; opacity: 0; transition: opacity .3s var(--ease);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 26px 26px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .38s var(--ease);
}
.sheet-backdrop.show .sheet { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 19px; font-weight: 700; }
.sheet .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.sheet.wide { max-width: 760px; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 26px; transform: translateY(24px) scale(.98); opacity: 0; transition: transform .32s var(--ease), opacity .25s; padding-bottom: 20px; }
  .sheet-backdrop.show .sheet { opacity: 1; }
}

/* ---------- Ảnh phóng to ---------- */
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(10, 12, 9, .9); display: grid; place-items: center; opacity: 0; transition: opacity .25s; padding: 16px; }
.lightbox.show { opacity: 1; }
.lightbox img { max-width: 100%; max-height: 86dvh; border-radius: 12px; transform: scale(.94); transition: transform .3s var(--ease); }
.lightbox.show img { transform: none; }
.lightbox .cap { color: #e9eedf; text-align: center; margin-top: 10px; font-size: 13px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translate(-50%, calc(-100% - 40px)); opacity: 0;
  transition: transform .35s var(--ease), opacity .25s;
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-weight: 500; font-size: 14px;
  z-index: 100; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 380px; }
.login .brand { text-align: center; margin-bottom: 26px; }
.login .brand img { width: 76px; height: 76px; border-radius: 22px; box-shadow: 0 12px 30px rgba(78, 117, 53, .3); animation: float 4s ease-in-out infinite; }
.login .brand h1 { margin: 16px 0 2px; font-size: 24px; letter-spacing: -.02em; }
.login .brand p { margin: 0; color: var(--muted); }
@keyframes float { 50% { transform: translateY(-6px); } }

/* ---------- Bảng (máy tính) ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; }
.tbl .c { text-align: center; }

/* ---------- Trang in ---------- */
.print-page { background: #fff; color: #1F271B; max-width: 1000px; margin: 0 auto; padding: 24px; font-size: 13px; }
.print-page h1 { font-size: 20px; margin: 0; color: #3F5F2E; text-align: center; }
.print-page .meta { text-align: center; color: #6E7766; margin: 4px 0 18px; }
.print-page table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.print-page th, .print-page td { border: 1px solid #D5DDC4; padding: 6px 8px; vertical-align: top; }
.print-page th { background: #4E7535; color: #fff; font-weight: 600; }
.print-page .tot td { background: #EEF3E2; font-weight: 700; }
.print-page .person { break-inside: avoid-page; margin-top: 22px; }
.print-page .person h2 { font-size: 15px; margin: 0 0 6px; color: #3F5F2E; }
.print-page .pimg { width: 110px; height: 110px; object-fit: cover; border-radius: 6px; display: block; }
.print-page .sign { display: flex; justify-content: space-around; margin-top: 36px; text-align: center; }
.print-page .sign div { width: 30%; }
.print-bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; justify-content: center; padding: 12px; background: var(--bg); }
@media print {
  .print-bar, .tabbar, #toast { display: none !important; }
  body, html { background: #fff !important; }
  .print-page { padding: 0; max-width: none; }
  @page { size: A4; margin: 12mm; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
