/* ===== Jadhai To Do ===== */
:root {
  --ink: #1d2420;
  --ink-2: #5b655f;
  --ink-3: #8b948e;
  --paper: #f6f3ec;
  --card: #ffffff;
  --line: #e4dfd3;
  --brand: #1f4d3a;
  --brand-2: #2f6b52;
  --brand-tint: #e3eee8;
  --red: #c2412d;
  --red-tint: #fbe9e5;
  --amber: #b7791f;
  --amber-tint: #fdf3e1;
  --blue: #2c5d8f;
  --blue-tint: #e6eef7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 36, 32, .06), 0 4px 14px rgba(29, 36, 32, .06);
  --nav-h: 64px;
  font-family: "IBM Plex Sans Thai", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { font-size: 16px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }

.splash { display: grid; place-items: center; min-height: 100vh; color: var(--ink-2); }

/* ---------- layout ---------- */
.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(246, 243, 236, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { border: 0; background: none; font-size: 22px; padding: 4px 8px 4px 0; cursor: pointer; }
.brand-dot { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-3); font-size: 12px;
}
.bottomnav a .ico { font-size: 20px; line-height: 1; }
.bottomnav a.on { color: var(--brand); font-weight: 600; }

.fab {
  position: fixed; right: 18px; z-index: 31;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  height: 52px; padding: 0 20px; border-radius: 26px; border: 0;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 16px;
  box-shadow: 0 6px 18px rgba(31, 77, 58, .35); cursor: pointer;
}

@media (min-width: 900px) {
  .shell { padding-bottom: 32px; padding-left: 220px; }
  .bottomnav {
    top: 0; bottom: 0; right: auto; width: 220px; height: auto;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 84px 12px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .bottomnav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
  .bottomnav a.on { background: var(--brand-tint); }
  .fab { bottom: 28px; right: 28px; }
}

/* ---------- common ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--ink-2); margin: 22px 4px 8px; display: flex; align-items: center; gap: 8px; }
.section-title .count { background: var(--line); color: var(--ink-2); border-radius: 10px; padding: 0 8px; font-size: 12px; }
.section-title.red { color: var(--red); }
.section-title.red .count { background: var(--red-tint); color: var(--red); }
.empty { text-align: center; color: var(--ink-3); padding: 28px 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 500;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--red); border-color: #efc9c1; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

label.field { display: block; }
label.field > span { display: block; font-size: 14px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }

.seg { display: flex; background: #ece8de; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; min-height: 38px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 5px 12px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge.todo { background: #eeebe3; color: var(--ink-2); }
.badge.in_progress { background: var(--blue-tint); color: var(--blue); }
.badge.done { background: var(--brand-tint); color: var(--brand); }
.badge.late { background: var(--red-tint); color: var(--red); }
.badge.high { background: var(--amber-tint); color: var(--amber); }
.badge.dept { background: #efe9f7; color: #5a3f86; }

/* ---------- task list ---------- */
.tasklist { list-style: none; margin: 0; padding: 0; }
.tasklist li + li { border-top: 1px solid var(--line); }
.task { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; cursor: pointer; }
.task:hover { background: #fbfaf7; }
.tick {
  flex: none; width: 24px; height: 24px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--ink-3); background: #fff; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.tick.done { background: var(--brand); border-color: var(--brand); color: #fff; font-size: 13px; }
.tick.late { border-color: var(--red); }
.task .title { font-weight: 500; word-break: break-word; }
.task.is-done .title { color: var(--ink-3); text-decoration: line-through; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 3px; font-size: 13px; color: var(--ink-2); align-items: center; }
.due.over { color: var(--red); font-weight: 600; }
.due.today { color: var(--amber); font-weight: 600; }

/* ---------- detail ---------- */
.detail h2 { font-size: 21px; margin: 0 0 6px; line-height: 1.35; word-break: break-word; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 15px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }
.comment { padding: 10px 0; }
.comment + .comment { border-top: 1px solid var(--line); }
.comment .who { font-weight: 600; font-size: 14px; }
.comment .body { white-space: pre-wrap; word-break: break-word; }
.history { font-size: 14px; color: var(--ink-2); }
.history li { margin: 4px 0; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 24px; }
.login h1 { margin: 12px 0 4px; font-size: 26px; }
.google-btn { background: #fff; border: 1px solid #d6d2c7; font-weight: 600; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- settings / admin ---------- */
.code-box { font-size: 36px; font-weight: 700; letter-spacing: 8px; text-align: center; padding: 14px; border-radius: 12px; background: var(--brand-tint); color: var(--brand); }
table.staff { width: 100%; border-collapse: collapse; font-size: 14px; }
table.staff th, table.staff td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.staff th { color: var(--ink-2); font-weight: 500; font-size: 13px; }
table.staff tr.inactive td { color: var(--ink-3); }
.meter { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter > div { height: 100%; background: var(--brand-2); }

/* ---------- dialog & toast ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(29, 36, 32, .45); }
dialog form { padding: 20px; }
dialog h3 { margin: 0 0 14px; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 100;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red); }
