:root {
  --terra: #99432c; --terra-dark: #6e2c1c; --terra-soft: #f6e7e0;
  --sage: #6f7f5f; --sage-soft: #e9eee2;
  --cream: #faf6f1; --ink: #2b2522; --muted: #776d67; --line: #ebe2da; --white: #fff;
  --ok: #3f7a43; --ok-soft: #e3f1e2; --warn: #a96b00; --warn-soft: #fbefd6; --bad: #a3321e; --bad-soft: #fbe3de;
  --radius: 12px; --shadow: 0 6px 22px rgba(60, 30, 20, .07);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Poppins', system-ui, sans-serif; background: var(--cream); color: var(--ink); font-size: 14.5px; line-height: 1.5; }
a { color: var(--terra); }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h1 { font-family: 'Playfair Display', Georgia, serif; font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
button, input, select, textarea { font: inherit; }

/* layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
aside.side { background: var(--terra-dark); color: #f3e5df; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
aside.side .logo { justify-content: center; padding: 1.4rem 1.2rem 1rem; display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; }
aside.side .logo img { height: 92px; }
aside.side .logo b { font-family: 'Josefin Sans', sans-serif; font-weight: 400; letter-spacing: .14em; font-size: 1.25rem; display: block; line-height: 1; }
aside.side .logo small { font-size: .62rem; opacity: .75; letter-spacing: .06em; }
aside.side nav { flex: 1; overflow-y: auto; padding: .4rem .7rem; }
aside.side nav a { display: flex; align-items: center; gap: .7rem; color: #f3e5df; text-decoration: none; padding: .62rem .8rem; border-radius: 9px; margin-bottom: 2px; font-size: .92rem; }
aside.side nav a:hover { background: rgba(255, 255, 255, .08); }
aside.side nav a.active { background: #fff; color: var(--terra-dark); font-weight: 600; }
aside.side nav a .ic { width: 1.3rem; text-align: center; }
aside.side nav a .badge { margin-left: auto; background: #f0b9a8; color: var(--terra-dark); font-size: .72rem; font-weight: 700; border-radius: 999px; padding: 0 .5rem; }
aside.side nav a.active .badge { background: var(--terra); color: #fff; }
aside.side .me { padding: 1rem 1.2rem; border-top: 1px solid rgba(255, 255, 255, .12); font-size: .85rem; }
aside.side .me b { display: block; color: #fff; }
aside.side .me button { background: none; border: 1px solid rgba(255, 255, 255, .3); color: #fff; border-radius: 8px; padding: .3rem .7rem; cursor: pointer; margin-top: .5rem; font-size: .8rem; }
main.content { padding: 1.8rem clamp(16px, 3vw, 2.4rem) 3rem; min-width: 0; }
.mobilebar { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  aside.side { position: fixed; inset: 0 30% 0 0; z-index: 60; transform: translateX(-105%); transition: transform .25s; max-width: 300px; }
  aside.side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .mobilebar { display: flex; align-items: center; gap: .8rem; background: var(--terra-dark); color: #fff; padding: .6rem 16px; position: sticky; top: 0; z-index: 40; }
  .mobilebar button { background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; }
  .mobilebar img { height: 30px; }
  main.content { padding-top: 1.2rem; }
}

/* page header */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head p { margin: .2rem 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumbs { font-size: .82rem; margin-bottom: .3rem; }
.crumbs a { text-decoration: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1.5px solid var(--terra); background: var(--terra); color: #fff; padding: .5rem 1rem; border-radius: 9px; cursor: pointer; font-weight: 500; text-decoration: none; font-size: .9rem; white-space: nowrap; }
.btn:hover { background: var(--terra-dark); border-color: var(--terra-dark); }
.btn.ghost { background: #fff; color: var(--terra); }
.btn.ghost:hover { background: var(--terra-soft); }
.btn.sm { padding: .28rem .65rem; font-size: .8rem; border-radius: 7px; }
.btn.danger { background: #fff; color: var(--bad); border-color: #e5b5ab; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn:disabled { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--terra); cursor: pointer; padding: 0; text-decoration: underline; }

/* cards & grids */
.card { background: #fff; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 1.2rem 1.3rem; margin-bottom: 1.2rem; }
.card > h2:first-child { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.2rem; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; text-decoration: none; color: inherit; display: block; }
.stat b { display: block; font-size: 1.6rem; font-family: 'Playfair Display', serif; color: var(--terra); }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.bad b { color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 1.6rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 0 -1.3rem; padding: 0 1.3rem; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: .55rem .6rem; border-bottom: 1.5px solid var(--line); white-space: nowrap; }
table.t td { padding: .6rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--cream); }
table.t tr.past td { color: var(--muted); }
table.t tr.cancelled td { text-decoration: line-through; color: var(--muted); }

/* tags */
.tag { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 600; background: #eee; color: #555; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.terra { background: var(--terra-soft); color: var(--terra); }
.tag.sage { background: var(--sage-soft); color: #4c5a3e; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; vertical-align: middle; margin-right: .3rem; }

/* forms */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem 1rem; }
.form .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form { grid-template-columns: 1fr; } }
label.f { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; font-weight: 500; color: var(--muted); }
label.f input, label.f select, label.f textarea, select.in, input.in { padding: .55rem .7rem; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-size: .92rem; }
label.f input:focus, label.f select:focus, label.f textarea:focus, select.in:focus, input.in:focus { outline: none; border-color: var(--terra); }
label.chk { display: flex; gap: .5rem; align-items: center; font-size: .9rem; cursor: pointer; }
label.chk input { accent-color: var(--terra); width: 16px; height: 16px; }
.days { display: flex; gap: .3rem; flex-wrap: wrap; }
.days label { cursor: pointer; }
.days input { position: absolute; opacity: 0; }
.days span { display: inline-block; padding: .35rem .65rem; border: 1.5px solid var(--line); border-radius: 7px; font-size: .85rem; }
.days input:checked + span { background: var(--terra); color: #fff; border-color: var(--terra); }

/* tabs */
.tabs { display: flex; gap: .3rem; border-bottom: 1.5px solid var(--line); margin-bottom: 1.2rem; overflow-x: auto; }
.tabs a { padding: .6rem 1rem; text-decoration: none; color: var(--muted); border-bottom: 2.5px solid transparent; margin-bottom: -1.5px; white-space: nowrap; font-weight: 500; cursor: pointer; }
.tabs a.active { color: var(--terra); border-color: var(--terra); }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(40, 20, 10, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(620px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { width: min(860px, 100%); }
.modal header { padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal header h2 { margin: 0; }
.modal header button { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
.modal .body { padding: 1.2rem 1.4rem; }
.modal footer { padding: 1rem 1.4rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; position: sticky; bottom: 0; background: #fff; }
.err { background: var(--bad-soft); color: var(--bad); padding: .6rem .8rem; border-radius: 8px; font-size: .88rem; margin-top: .8rem; }
.note { background: var(--sage-soft); color: #44513a; padding: .7rem .9rem; border-radius: 8px; font-size: .88rem; }
.note.warn { background: var(--warn-soft); color: #7a4e00; }
#toast { position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .7rem 1.2rem; border-radius: 10px; z-index: 200; font-size: .9rem; opacity: 0; transition: .25s; pointer-events: none; }
#toast.show { opacity: 1; }

/* login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login .pic { background: url(../img/img_4190.jpg) center/cover; position: relative; }
.login .pic::after { content: ''; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(110, 44, 28, .75), rgba(110, 44, 28, .2)); }
.login .pic img { position: absolute; z-index: 1; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 260px; }
.login .box { display: grid; place-items: center; padding: 2rem 16px; }
.login form { width: min(380px, 100%); }
.login .demo { margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px dashed var(--line); }
.login .demo .row button { flex: 1; }
@media (max-width: 800px) { .login { grid-template-columns: 1fr; } .login .pic { display: none; } }

/* calendar */
.cal-toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.cal-toolbar .title { font-weight: 600; font-size: 1.05rem; min-width: 14rem; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { background: #fff; border: 0; padding: .42rem .8rem; cursor: pointer; font-size: .85rem; }
.seg button.on { background: var(--terra); color: #fff; }
.legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-bottom: .8rem; }
.legend label { cursor: pointer; display: flex; align-items: center; gap: .3rem; }
.legend input { accent-color: var(--terra); }
.cal { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.cal-grid { display: grid; min-width: 760px; position: relative; }
.cal-head { position: sticky; top: 0; background: #fff; z-index: 3; border-bottom: 1.5px solid var(--line); padding: .55rem .4rem; text-align: center; font-size: .82rem; font-weight: 600; }
.cal-head.today { color: var(--terra); }
.cal-head small { display: block; font-weight: 400; color: var(--muted); }
.cal-times { border-right: 1px solid var(--line); }
.cal-times div { height: 48px; font-size: .72rem; color: var(--muted); text-align: right; padding: 0 .4rem; transform: translateY(-.5em); }
.cal-col { position: relative; border-right: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, transparent 0 47px, var(--line) 47px 48px); }
.cal-col.today { background-color: #fdf8f5; }
.ev { position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: .25rem .4rem; font-size: .74rem; line-height: 1.25; overflow: hidden; color: #fff; cursor: pointer; border-left: 4px solid rgba(0, 0, 0, .2); }
.ev b { display: block; font-size: .78rem; }
.ev.busy { background: repeating-linear-gradient(135deg, #d9d2cc 0 6px, #e6e0db 6px 12px) !important; color: #5b524d; cursor: default; border-left-color: #b8aea7; }
.ev.cancelled { opacity: .5; text-decoration: line-through; }
.ev.split { right: auto; }

/* attendance matrix */
.att { border-collapse: collapse; font-size: .82rem; }
.att th, .att td { border: 1px solid var(--line); padding: .3rem .35rem; text-align: center; white-space: nowrap; }
.att th.name, .att td.name { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; min-width: 160px; }
.att th { font-weight: 500; color: var(--muted); font-size: .72rem; }
.a-present { background: var(--ok-soft); color: var(--ok); }
.a-absent { background: var(--bad-soft); color: var(--bad); }
.a-late { background: var(--warn-soft); color: var(--warn); }
.a-excused { background: #e8eef6; color: #3d5a80; }
.attsel { display: inline-flex; gap: 3px; }
.attsel button { border: 1.5px solid var(--line); background: #fff; border-radius: 6px; padding: .2rem .5rem; cursor: pointer; font-size: .78rem; }
.attsel button.on.present { background: var(--ok); color: #fff; border-color: var(--ok); }
.attsel button.on.absent { background: var(--bad); color: #fff; border-color: var(--bad); }
.attsel button.on.late { background: var(--warn); color: #fff; border-color: var(--warn); }
.attsel button.on.excused { background: #3d5a80; color: #fff; border-color: #3d5a80; }

/* messages */
.msgs { display: grid; grid-template-columns: 340px 1fr; gap: 1.2rem; align-items: start; }
@media (max-width: 900px) { .msgs { grid-template-columns: 1fr; } }
.threads { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.thread { display: block; padding: .8rem 1rem; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.thread:hover { background: var(--cream); }
.thread.on { background: var(--terra-soft); }
.thread .top { display: flex; justify-content: space-between; gap: .5rem; font-size: .76rem; color: var(--muted); }
.thread b { display: block; font-size: .92rem; margin: .15rem 0; }
.thread.unread b::before { content: ''; display: inline-block; width: .5rem; height: .5rem; background: var(--terra); border-radius: 50%; margin-right: .4rem; vertical-align: middle; }
.thread p { margin: 0; font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubbles { display: flex; flex-direction: column; gap: .7rem; max-height: 60vh; overflow-y: auto; padding: .4rem .2rem 1rem; }
.bubble { max-width: 80%; background: var(--cream); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .85rem; white-space: pre-wrap; }
.bubble.me { align-self: flex-end; background: var(--terra-soft); border-color: #ecd0c4; }
.bubble .who { font-size: .74rem; color: var(--muted); margin-bottom: .2rem; white-space: normal; }

/* documents */
.doc { white-space: pre-wrap; background: #fffdfa; border: 1px solid var(--line); border-radius: 10px; padding: 1.4rem 1.6rem; font-family: Georgia, serif; font-size: .95rem; line-height: 1.65; max-height: 55vh; overflow-y: auto; }
.sigbox { margin-top: 1rem; padding: 1rem; border: 1.5px dashed var(--terra); border-radius: 10px; background: #fffaf7; }
.sigline { font-family: 'Caveat', 'Segoe Script', cursive; font-size: 1.6rem; color: #1b3d8f; }

/* payment gateway mock */
.gateway { text-align: center; }
.gateway .amount { font-size: 2rem; font-weight: 700; color: var(--terra); margin: .4rem 0 1rem; }
.methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: 1rem 0; }
.methods label input { position: absolute; opacity: 0; }
.methods label span { display: block; border: 1.5px solid var(--line); border-radius: 10px; padding: .8rem .4rem; cursor: pointer; font-weight: 600; }
.methods label input:checked + span { border-color: var(--terra); background: var(--terra-soft); color: var(--terra); }

@media print {
  aside.side, .mobilebar, .no-print, .page-head .actions { display: none !important; }
  .app { display: block; }
  .doc { max-height: none; border: 0; }
}
