:root {
  --teal: #14B8A6; --green: #10B981; --coral: #FB7185; --amber: #F59E0B; --violet: #8B5CF6;
  --ink: #134E4A; --muted: #64748B; --line: #CCFBF1; --bg: #F0FDFA; --nav: 76px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: Nunito, system-ui, sans-serif; background: var(--bg); color: #0F172A; padding-bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 16px); -webkit-text-size-adjust: 100%; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 14px; }
.ribbon { background: #FEF3C7; color: #92400E; font-size: 12px; font-weight: 800; text-align: center; padding: 5px 10px; }

header { background: linear-gradient(135deg, #14B8A6, #38BDF8); color: #fff; padding: 16px 0 46px; border-radius: 0 0 26px 26px; }
h1 { margin: 0 0 10px; font-size: 22px; font-weight: 800; }
h3 { margin: 0 0 10px; font-size: 15px; color: var(--ink); }
main { margin-top: -32px; }

select, input, textarea { font: inherit; font-size: 16px; width: 100%; min-width: 0; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: inherit; }
select:focus, input:focus, button:focus-visible { outline: 3px solid rgba(20, 184, 166, .35); outline-offset: 1px; }
header select { border: 0; font-weight: 800; color: var(--ink); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 12px; }
label input, label select { margin-top: 4px; }
button { font: inherit; cursor: pointer; }

.card { background: #fff; border-radius: 18px; padding: 16px; margin-bottom: 14px; box-shadow: 0 6px 18px rgba(20, 184, 166, .12); }
.seg { display: flex; background: #F1F5F9; border-radius: 14px; padding: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px 4px; border-radius: 11px; font-weight: 800; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0, 0, 0, .08); }
.amt { display: flex; align-items: center; gap: 8px; margin: 14px 0; }
.amt input { font-size: 32px; font-weight: 800; text-align: right; border: 0; border-bottom: 3px solid var(--teal); border-radius: 0; color: var(--coral); padding: 4px; }
.amt span { font-size: 22px; font-weight: 800; color: var(--muted); }
.mini { border: 0; background: var(--line); color: var(--ink); font-weight: 800; padding: 9px 12px; border-radius: 12px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--teal); border-color: var(--teal); color: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.btn { display: block; width: 100%; text-align: center; border: 0; border-radius: 14px; padding: 13px; font-size: 16px; font-weight: 800; margin-top: 14px; }
.primary { background: linear-gradient(135deg, #FB7185, #F59E0B); color: #fff; }
.ghost { background: #EDE9FE; color: #6D28D9; }
.acts { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi { border-radius: 16px; padding: 14px; font-weight: 800; min-width: 0; }
.kpi small { display: block; font-size: 13px; font-weight: 600; opacity: .85; }
.kpi b { font-size: 20px; overflow-wrap: anywhere; }
.in { background: #D1FAE5; color: #047857; } .out { background: #FFE4E6; color: #BE123C; }
.sav { background: #EDE9FE; color: #6D28D9; } .left { background: #FEF3C7; color: #B45309; }
.tri { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; text-align: center; }
.tri div { background: #F8FAFC; border-radius: 12px; padding: 10px 4px; min-width: 0; }
.tri small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.tri b { font-size: 16px; overflow-wrap: anywhere; }
.tri .hl { background: #CCFBF1; color: var(--ink); } .tri .hl.neg { background: #FFE4E6; color: #BE123C; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }
.row > span:last-child, .row > b:last-child { text-align: right; white-space: nowrap; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.neg { color: #BE123C; } .pos { color: #047857; }
.big { font-size: 22px; font-weight: 800; color: #6D28D9; }
.bar { height: 9px; background: #E2E8F0; border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.bar i { display: block; height: 100%; background: var(--teal); border-radius: 99px; }
.bar i.warn { background: var(--amber); } .bar i.over { background: var(--coral); }
.catrow { margin-bottom: 12px; } .catrow small { font-size: 12px; color: var(--muted); }

.tx { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #F1F5F9; font-size: 14px; }
.tx:last-child { border: 0; }
.tx div { flex: 1; min-width: 0; }
.tx small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx b { white-space: nowrap; }
.x { border: 0; background: none; color: #94A3B8; font-size: 20px; line-height: 1; padding: 6px 8px; border-radius: 8px; }
.x:hover { color: #BE123C; background: #FFE4E6; }
.cv { position: relative; height: 250px; margin-bottom: 14px; } .cv.tall { height: 320px; } .cv.low { height: 190px; }

.brow { display: grid; grid-template-columns: 1fr 150px; gap: 10px; align-items: center; padding: 6px 0; }
.brow input { text-align: right; font-weight: 800; padding: 9px 10px; }
.brow span { font-size: 14px; font-weight: 600; }
.brow em { font-style: normal; font-size: 11px; color: var(--violet); font-weight: 800; margin-left: 6px; }
.total { background: var(--bg); border-radius: 12px; padding: 12px; margin-top: 10px; font-weight: 800; }
.crow { display: grid; grid-template-columns: 1fr 1fr 1fr 36px; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px solid #F1F5F9; }
.crow b { grid-column: 1 / -1; font-size: 13px; color: var(--ink); }
.crow label { margin: 0; font-size: 11px; min-width: 0; } .crow input { padding: 8px; font-size: 14px; }

nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; background: #fff; box-shadow: 0 -4px 16px rgba(0, 0, 0, .08); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
nav button { flex: 1; max-width: 120px; min-width: 0; border: 0; background: none; font-weight: 800; font-size: 11px; color: var(--muted); padding: 8px 2px; border-radius: 12px; white-space: nowrap; }
nav button span { display: block; font-size: 19px; }
nav button.on { background: var(--line); color: var(--ink); }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav) + 24px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 90%; z-index: 30; }
#toast.show { opacity: 1; }
#busy, #modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
#busy { background: rgba(240, 253, 250, .6); z-index: 20; }
#modal { background: rgba(15, 23, 42, .45); z-index: 10; overflow: auto; }
#modal .card { width: 100%; max-width: 420px; margin: auto; }
.spin { width: 42px; height: 42px; border: 5px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Điện thoại hẹp */
@media (max-width: 380px) {
  .amt input { font-size: 26px; }
  .brow { grid-template-columns: 1fr 120px; }
}
/* Điện thoại: 2 ô ngày trên 1 hàng, tiền nhà xuống hàng dưới */
@media (max-width: 639px) {
  .crow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .crow .rentcol { grid-column: 1 / 2; }
  .crow .x { justify-self: end; }
}

/* Máy tính bảng: 4 ô chỉ số trên 1 hàng */
@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
}

/* Máy tính: thanh điều hướng dọc bên trái, nội dung 2 cột */
@media (min-width: 960px) {
  body { padding: 0 0 24px 210px; }
  .wrap { max-width: 1120px; padding: 0 24px; }
  nav { top: 0; right: auto; width: 210px; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 20px 12px; box-shadow: 4px 0 16px rgba(0, 0, 0, .06); }
  nav button { flex: none; max-width: none; display: flex; align-items: center; gap: 12px; font-size: 15px; padding: 12px 14px; text-align: left; }
  nav button span { font-size: 20px; }
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  #toast { bottom: 28px; }
}
