:root {
  --bg: #f3ede4;
  --card: #fbf8f3;
  --ink: #2b2118;
  --muted: #6b5d50;
  --line: #d8cbb9;
  --brand: #4a3426;
  --brand-ink: #fbf8f3;
  --ok: #2f6b3f;
  --warn: #9a5b00;
  --bad: #a3321f;
  --chip: #ebe2d5;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1712;
    --card: #271f18;
    --ink: #efe6da;
    --muted: #a99a8a;
    --line: #4a3d31;
    --brand: #d9c3a5;
    --brand-ink: #1d1712;
    --ok: #7fc08f;
    --warn: #e0a85a;
    --bad: #e58a78;
    --chip: #382d23;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  font-size: 16px;
}
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
a { color: inherit; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* Thanh điều hướng */
#nav {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card);
  position: sticky; top: 0; z-index: 5;
}
#nav .brand { font-family: Georgia, serif; font-weight: 700; font-size: 1.2rem; text-decoration: none; margin-right: 8px; }
#nav a.link { text-decoration: none; padding: 6px 2px; color: var(--muted); border-bottom: 2px solid transparent; }
#nav a.link.on { color: var(--ink); border-bottom-color: var(--ink); }
#nav .spacer { flex: 1; }

.page { max-width: 980px; margin: 0 auto; padding: 18px 14px 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }

/* Nút */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 9px 14px; min-height: 42px;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small, .btn.small { min-height: 34px; padding: 4px 10px; font-size: 0.875rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* Ô nhập */
label { display: block; font-weight: 600; margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 9px 10px; min-height: 42px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.form { max-width: 380px; }

/* Thông báo */
.banner { border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px; border: 1px solid var(--line); background: var(--chip); }
.banner.ok { border-color: var(--ok); }
.banner.warn { border-color: var(--warn); }
.banner.bad { border-color: var(--bad); }
#toasts { position: fixed; left: 0; right: 0; bottom: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--brand); color: var(--brand-ink); padding: 10px 14px; border-radius: 8px; max-width: 92vw; pointer-events: auto; }
.toast.bad { background: var(--bad); color: #fff; }

/* Lưới ngày */
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.day.past { opacity: 0.55; }
.day.weekend { border-left: 4px solid var(--brand); }
.day h3 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.period { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
.period .ptitle { font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--chip); border-radius: 999px;
  padding: 6px 12px; min-height: 38px; font-size: 0.95rem;
}
button.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.tag { font-size: 0.75rem; border-radius: 6px; padding: 1px 6px; border: 1px solid var(--line); color: var(--muted); }
.tag.late { color: var(--warn); border-color: var(--warn); }
.tag.ok { color: var(--ok); border-color: var(--ok); }
.tag.bad { color: var(--bad); border-color: var(--bad); }
.asg { border-radius: 8px; border: 1px solid var(--line); background: var(--chip); padding: 6px 10px; font-size: 0.95rem; text-align: left; min-height: 0; display: block; width: 100%; margin-bottom: 4px; }
.asg.me { border-color: var(--brand); font-weight: 600; }
.asg .sub { color: var(--muted); font-weight: 400; font-size: 0.82rem; }
.reg { border: 1px dashed var(--line); border-radius: 8px; padding: 4px 10px; font-size: 0.9rem; background: transparent; text-align: left; min-height: 0; }
.reg.done { opacity: 0.5; text-decoration: line-through; }
.label-small { font-size: 0.8rem; color: var(--muted); margin: 6px 0 3px; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); padding: 16px; width: min(440px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: fade 0.2s ease-out; }
  @keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* ---- Nhập từ Zalo ---- */
.tablewrap { overflow-x: auto; margin: 8px 0; }
.imp-table { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 13px; }
.imp-table th, .imp-table td { border: 1px solid #d9cfc2; padding: 3px; text-align: center; }
.imp-table th { background: #efe6d9; font-weight: 600; }
.imp-table .offcell { color: #a33; font-size: 12px; }
.cellbtn { width: 100%; min-height: 34px; border: 0; background: transparent; cursor: pointer; font-size: 13px; }
.cellbtn.on { background: #cfe8cf; color: #1d5a1d; font-weight: 600; }
.cellbtn.on.had { background: #e3e3e3; color: #555; }
.imp-warn { margin: 6px 0; padding-left: 18px; color: #8a5a00; font-size: 13px; }
.imp-lines { font-size: 13px; padding-left: 18px; }
.imp-lines .unknown { color: #a33; }
.imp-lines .ignored { color: #888; }
.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid #d9cfc2; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin-top: 10px; }
label.check input { width: auto; margin-top: 4px; }
