:root {
  --brand: #6b4a3a;
  --brand-dark: #4a3227;
  --brand-soft: #efe3d3;
  --bg: #f7f1e8;
  --card: #fffdf9;
  --text: #2e241f;
  --muted: #8c7a6b;
  --line: #e6d9c7;
  --ok: #5b7a3a;
  --warn: #d98324;
  --danger: #b4483a;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(80, 55, 35, .08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(84px + var(--safe-b));
  max-width: 640px;
  margin: 0 auto;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
h1, h2, h3, p { margin: 0; }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + var(--safe-t)) 18px 12px;
  background: rgba(247, 241, 232, .94);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 22px; font-weight: 750; letter-spacing: -.3px; }
.topbar p { font-size: 13px; margin-top: 2px; }

main { padding: 14px 16px 24px; }

/* ---------- Nút ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px;
  background: var(--brand); color: #fff; font-weight: 650;
}
.btn:active { background: var(--brand-dark); }
.btn.block { width: 100%; }
.btn.secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn.danger { background: #f6e2dc; color: var(--danger); }
.ghost {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 8px 14px; font-weight: 600;
}
.ghost.small { font-size: 13px; padding: 6px 12px; color: var(--brand-dark); }

.fab {
  position: fixed; z-index: 6;
  right: max(18px, calc(50% - 320px + 18px));
  bottom: calc(84px + var(--safe-b));
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--brand); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgba(107, 74, 58, .4);
}
.fab:active { transform: scale(.95); }

/* ---------- Thanh tab ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(255, 253, 249, .96);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + var(--safe-b));
}
.tabbar button {
  border: 0; background: none; padding: 6px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
.tabbar .ti { font-size: 21px; filter: grayscale(1); opacity: .6; }
.tabbar button.active { color: var(--brand-dark); }
.tabbar button.active .ti { filter: none; opacity: 1; }

/* ---------- Tìm & lọc ---------- */
.search {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 11px 14px; outline: none;
}
.search:focus { border-color: var(--brand); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Nhóm theo ngày ---------- */
.day-group { margin-top: 18px; }
.day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 2px 8px; font-size: 14px;
}
.day-head b { font-size: 15px; }
.day-head.today b { color: var(--brand-dark); }
.day-head .count { color: var(--muted); font-size: 13px; }

/* ---------- Thẻ lịch ---------- */
.card {
  display: grid; grid-template-columns: 62px 1fr; gap: 12px;
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow);
  border-left: 5px solid var(--svc, var(--brand));
}
.card:active { background: #fbf6ef; }
.card .time { font-size: 18px; font-weight: 750; letter-spacing: -.3px; }
.card .time small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.card .name { font-weight: 700; font-size: 16px; }
.card .meta { font-size: 13.5px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .row2 { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
.card.cancelled { opacity: .55; }
.card.cancelled .name { text-decoration: line-through; }
.card.conflict { box-shadow: 0 0 0 2px #f6c56b; }

.tag {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--svc, var(--brand)) 14%, white); color: var(--svc, var(--brand));
}
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.st-cho { background: #fff3e0; color: #b86a12; }
.st-coc { background: #ebe1d3; color: #6b4a3a; }
.st-xong { background: #e6ecdc; color: var(--ok); }
.st-huy { background: #efeae4; color: var(--muted); }
.money-due { font-size: 12.5px; font-weight: 700; color: var(--danger); }
.warn-text { font-size: 12.5px; font-weight: 700; color: var(--warn); }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 46px; margin-bottom: 8px; }
.empty .btn { margin-top: 16px; }

/* ---------- Lịch tháng ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.month-nav h2 { font-size: 19px; text-transform: capitalize; }
.month-nav button { border: 1px solid var(--line); background: var(--card); width: 40px; height: 40px; border-radius: 12px; font-size: 18px; }
.cal {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; box-shadow: var(--shadow);
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0 6px; }
.cal-day {
  aspect-ratio: 1 / 1.05; border: 0; background: none; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 6px; gap: 3px; font-size: 15px; font-weight: 600; position: relative;
}
.cal-day.other { color: #cbbdac; }
.cal-day.today .num { background: var(--brand-soft); color: var(--brand-dark); }
.cal-day.sel { background: var(--brand); color: #fff; }
.cal-day.sel .num { background: none; color: #fff; }
.cal-day .num { width: 28px; height: 28px; line-height: 28px; text-align: center; border-radius: 50%; }
.dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--svc, var(--brand)); }
.cal-day.sel .dot { background: #fff; }
.cal-day .more { font-size: 10px; line-height: 1; color: var(--muted); }
.cal-day.sel .more { color: #fff; }
.cal-day.busy::after {
  content: ""; position: absolute; top: 5px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn);
}

/* ---------- Thống kê ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.stat .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat .val { font-size: 21px; font-weight: 780; margin-top: 4px; letter-spacing: -.4px; }
.stat.wide { grid-column: 1 / -1; }
.stat .val.ok { color: var(--ok); }
.stat .val.due { color: var(--danger); }
.section-title { font-size: 16px; font-weight: 750; margin: 22px 2px 10px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 14px; }
.bar { height: 10px; background: #efe5d8; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--svc, var(--brand)); border-radius: 99px; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.panel p { font-size: 14px; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

/* ---------- Bảng trượt ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(40, 28, 20, .45); animation: fade .2s; }
.sheet {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-b));
  animation: up .25s cubic-bezier(.2, .8, .2, 1);
  overscroll-behavior: contain;
}
.sheet-handle { width: 40px; height: 5px; border-radius: 9px; background: #d9cab6; margin: 4px auto 12px; }
@keyframes up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-title h2 { font-size: 20px; }
.x { border: 0; background: var(--brand-soft); color: var(--brand-dark); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; }

/* ---------- Form ---------- */
.field { margin-bottom: 14px; }
.field > label, .field > .lbl { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 12px 13px; outline: none; font-size: 16px;
  -webkit-appearance: none; appearance: none; min-height: 48px;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.opt-chips .chip.on { background: var(--svc, var(--brand)); border-color: var(--svc, var(--brand)); }
.req { color: var(--danger); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.alert {
  background: #fff6e6; border: 1px solid #f6d79e; color: #8a5a12;
  border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px;
}

/* ---------- Chi tiết ---------- */
.detail-top { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.detail-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.detail-list .r { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 15px; }
.detail-list .r:last-child { border-bottom: 0; }
.detail-list .k { width: 92px; flex: none; color: var(--muted); font-size: 14px; }
.detail-list .v { flex: 1; white-space: pre-wrap; word-break: break-word; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.act {
  border: 1px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 12.5px; font-weight: 650; color: var(--text); text-decoration: none;
}
.act span { font-size: 21px; }
.act[aria-disabled="true"] { opacity: .35; pointer-events: none; }
.status-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0 14px; }
.status-row button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 2px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.status-row button.on.st-cho { background: #fff3e0; border-color: #f3c98f; color: #b86a12; }
.status-row button.on.st-coc { background: #ebe1d3; border-color: #cdb79e; color: #6b4a3a; }
.status-row button.on.st-xong { background: #e6ecdc; border-color: #bccaa3; color: var(--ok); }
.status-row button.on.st-huy { background: #efeae4; border-color: #d6cbbd; color: var(--text); }

/* ---------- Thông báo nhỏ ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(150px + var(--safe-b));
  background: #2e241f; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2); animation: fade .2s;
}

/* ---------- Thương hiệu Đen Makeup ---------- */
.brand {
  font-family: "Didot", "Bodoni 72", "Playfair Display", Georgia, "Times New Roman", serif;
  font-size: 26px !important; font-weight: 700 !important; letter-spacing: .2px !important;
  color: var(--brand-dark);
}
.brand span { font-style: italic; font-weight: 400; color: #a07d62; }
.topbar { border-bottom: 1px solid var(--line); }

/* ---------- Mời cài ứng dụng ---------- */
.install-banner {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 16px 0; padding: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); cursor: pointer;
}
.install-banner[hidden] { display: none; }
.install-banner img { border-radius: 11px; flex: none; }
.ib-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.ib-text span { font-size: 12.5px; color: var(--muted); }
.ib-btn { padding: 9px 14px; font-size: 14px; flex: none; }
.ib-x { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 4px; flex: none; }
