@font-face {
  font-family: "IBM Plex Sans Thai";
  src: url("fonts/IBMPlexSansThai-Regular.8b6e11b263b5.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Thai";
  src: url("fonts/IBMPlexSansThai-Medium.c46a265cbe0d.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --border: #d9dde3;
  --brand: #1d4ed8;
  --brand-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --demo: #b54708;
  --demo-bg: #fef0c7;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Thai", "Leelawadee UI", "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

h1 { font-size: 1.4rem; font-weight: 500; margin: 0 0 0.75rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }

.demo-banner {
  background: var(--demo-bg);
  color: var(--demo);
  font-weight: 500;
  padding: 0.4rem 1rem;
  text-align: center;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
}
.topbar .brand { font-weight: 500; font-size: 1.1rem; text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: center; }
.topbar nav a { color: var(--text); text-decoration: none; padding: 0.35rem 0; }
.topbar nav a:hover { color: var(--brand); }
.bell { display: inline-flex; align-items: center; }

.page { padding: 1rem; max-width: 72rem; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.card.narrow { max-width: 28rem; margin: 1rem auto; }

.picker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.picker-list button { width: 100%; text-align: left; }

button {
  font: inherit;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }

.action-form .field { margin-bottom: 0.75rem; }
.action-form label { display: block; font-weight: 500; margin-bottom: 0.2rem; }
.action-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.action-form select,
.action-form textarea {
  width: 100%;
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

.error { color: var(--danger); margin: 0.2rem 0 0; }
.alert {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin: 0 0 0.75rem;
}
.ref { font-family: ui-monospace, Consolas, monospace; letter-spacing: 0.05em; }

@media (min-width: 768px) {
  .topbar { flex-direction: row; justify-content: space-between; align-items: center; padding: 0.5rem 1.5rem; }
  .page { padding: 1.5rem; }
  .card.narrow { margin-top: 3rem; }
}

:root {
  --amber: #b54708;
  --amber-bg: #fef0c7;
  --red: #b42318;
  --red-bg: #fee4e2;
  --info: #175cd3;
  --info-bg: #d1e9ff;
  --chip-bg: #eef0f3;
}

.topbar .inline-form { display: inline; margin: 0; }
button.linklike {
  min-height: 0; padding: 0.35rem 0; border: 0; background: none; color: var(--text);
}
button.linklike:hover { color: var(--brand); }
a.button {
  display: inline-block; padding: 0.5rem 1rem; border: 1px solid var(--border);
  border-radius: var(--radius); text-decoration: none; background: var(--surface);
}
a.button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }

h2 { font-size: 1.05rem; font-weight: 500; margin: 0 0 0.5rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; }
.notice {
  background: var(--amber-bg); color: var(--amber); border-radius: var(--radius);
  padding: 0.5rem 0.75rem; margin: 0 0 0.75rem;
}

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); }
.tabs a {
  padding: 0.5rem 0.75rem; text-decoration: none; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }
.count { background: var(--chip-bg); border-radius: 999px; padding: 0 0.5rem; font-size: 0.85rem; }
.finished-switch { margin: 0.5rem 0; font-size: 0.9rem; }

.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.task-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}
.row-main { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; }
.row-title { font-weight: 500; text-decoration: none; color: var(--text); }
.row-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; align-items: center; margin-top: 0.25rem; }
.note { display: inline-block; margin: 0.25rem 0.75rem 0 0; font-size: 0.85rem; color: var(--amber); }
.empty { padding: 1rem; }

.chip {
  display: inline-block; padding: 0 0.6rem; border-radius: 999px; font-size: 0.85rem;
  background: var(--chip-bg); color: var(--text);
}
.chip-amber, .chip-high { background: var(--amber-bg); color: var(--amber); }
.chip-red, .chip-urgent { background: var(--red-bg); color: var(--red); }
.chip-info { background: var(--info-bg); color: var(--info); }
.badge {
  display: inline-block; padding: 0 0.5rem; border-radius: var(--radius); font-size: 0.9rem;
  background: var(--chip-bg);
}
.badge.due-soon { background: var(--amber-bg); color: var(--amber); }
.badge.due-over { background: var(--red-bg); color: var(--red); }

.band { margin-bottom: 0.75rem; }
.band dl, .side dl { margin: 0; display: grid; gap: 0.5rem; }
.band dl { grid-template-columns: 1fr 1fr; }
dt { color: var(--muted); font-size: 0.85rem; }
dd { margin: 0; overflow-wrap: anywhere; }
.chips { margin: 0.75rem 0 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chips:empty { display: none; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.actions .more { flex-basis: auto; }
.actions .more[open] { flex-basis: 100%; }
.actions .more button { margin: 0.5rem 0.5rem 0 0; }
.actions .more h3 { margin: 0.75rem 0 0; font-size: 0.9rem; color: var(--muted); }
.actions button { white-space: normal; overflow-wrap: anywhere; }
.inline-form { margin: 0 0 0.75rem; }

@media (max-width: 767px) {
  /* The task's buttons are docked to the bottom of a phone screen. An opened เพิ่มเติม grows
     upward and scrolls inside the bar when taller than the screen. A modal dialog is in the
     top layer, so it stays above the bar. */
  .action-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; margin: 0; padding: 0.5rem 1rem;
    max-height: 60vh; overflow-y: auto;
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .action-bar > button.primary { flex-basis: 100%; }
  main.has-action-bar { padding-bottom: 8rem; }
}

.detail-grid { display: grid; gap: 0.75rem; }
.content { display: grid; gap: 0.75rem; align-content: start; }
.content p { margin: 0 0 0.5rem; }
.history, .file-list, .people-list { list-style: none; margin: 0; padding: 0; }
.history li { padding: 0.5rem 0; border-top: 1px solid var(--border); }
.history li:first-child { border-top: 0; }
.history p { margin: 0.25rem 0; }
.change { font-size: 0.9rem; color: var(--muted); }
.people-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.25rem 0; }

dialog { max-width: min(36rem, 94vw); width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog form[method="dialog"] { margin-top: 0.75rem; }

@media (min-width: 768px) {
  .band dl { grid-template-columns: repeat(3, 1fr); }
  .detail-grid { grid-template-columns: minmax(0, 1fr) 20rem; align-items: start; }
  .detail-grid .side { grid-column: 2; grid-row: 1; }
  .detail-grid .content { grid-column: 1; grid-row: 1; }
}

.bell-count {
  background: var(--red); color: #fff; border-radius: 999px; font-size: 0.75rem;
  line-height: 1; padding: 0.15rem 0.4rem; margin-left: 0.25rem;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-bottom: 0.75rem; }
.tile {
  display: flex; flex-direction: column; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.75rem;
  text-decoration: none;
}
a.tile:hover { border-color: var(--brand); }
.tile.active { border-color: var(--brand); }
.tile:not(.tile-big).active { background: var(--info-bg); }
.tiles-total { margin: 0 0 0.5rem; color: var(--muted); }
.tile-big .tile-count { font-size: 2rem; }
.tile-overdue { background: var(--red-bg); }
.tile-overdue .tile-count { color: var(--red); }
.tile-blocked { background: var(--amber-bg); }
.tile-blocked .tile-count { color: var(--amber); }
.tile-awaiting_approval { background: var(--info-bg); }
.tile-awaiting_approval .tile-count { color: var(--info); }
/* An active big tile keeps its own colour and size; the outline marks it. */
.tile-big.active { outline: 2px solid var(--brand); outline-offset: -1px; }
.flag-line { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; margin: 0 0 0.25rem; font-size: 0.9rem; }
.flag-link { color: var(--muted); }
.flag-link.active { color: var(--brand); font-weight: 500; text-decoration: none; }
.flag-note { font-size: 0.85rem; margin: 0 0 0.75rem; }
.tile-count { font-size: 1.5rem; font-weight: 500; line-height: 1.2; }
.tile-label { font-size: 0.9rem; color: var(--muted); }

.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: 0.5rem; align-items: end; margin-bottom: 0.75rem; }
.filter-bar label { display: flex; flex-direction: column; min-width: 0; font-size: 0.9rem; color: var(--muted); }
.filter-bar select { width: 100%; min-width: 0; font: inherit; padding: 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.chip-filter { text-decoration: none; background: var(--info-bg); color: var(--info); }
.pager { display: flex; justify-content: center; gap: 1rem; margin: 1rem 0; }

.task-row.unread { border-left: 3px solid var(--brand); }
.review-list { display: grid; gap: 0.75rem; }
.review-item header { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; }
.review-actions { display: grid; gap: 0.75rem; margin-top: 0.75rem; }
.review-actions textarea { width: 100%; font: inherit; padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }
.digest-section { margin-bottom: 0.75rem; }


.data-table { width: 100%; border-collapse: collapse; background: var(--surface); }
.data-table th, .data-table td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { font-weight: 500; color: var(--muted); font-size: 0.9rem; }
.data-table .inline-form { margin: 0; }

/* Fix wave 2B */
.hints { list-style: none; margin: -0.25rem 0 0.75rem; padding: 0; font-size: 0.9rem; color: var(--muted); }
.hints li { overflow-wrap: anywhere; }
.dialog-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.consequence { font-weight: 500; }
.approve-row { border-top: 1px solid var(--border); padding-top: 0.75rem; }
.chip-decide { background: var(--info); color: #fff; }
[data-close-dialog] { display: none; }
dialog [data-close-dialog] { display: inline-block; }
[hidden] { display: none !important; }
.messages { list-style: none; margin: 0 0 0.75rem; padding: 0; }
.message {
  background: #ecfdf3; color: #067647; border: 1px solid #abefc6; border-radius: var(--radius);
  padding: 0.5rem 0.75rem; overflow-wrap: anywhere;
}
.message-info { background: var(--info-bg); color: var(--info); border-color: var(--info-bg); }
.optional { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.help { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0; overflow-wrap: anywhere; }
.notice-text { min-width: 0; overflow-wrap: anywhere; }
.task-row.unread { background: #f5f8ff; }
.task-row { min-width: 0; }
.row-main, .row-meta { min-width: 0; }
.row-title { overflow-wrap: anywhere; }
.row-next {
  margin: 0.25rem 0 0; font-size: 0.9rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.returned { color: var(--text); }
.returned p { margin: 0.25rem 0 0; overflow-wrap: anywhere; }
.rounds { list-style: none; margin: 0; padding: 0; }
.rounds > li { padding: 0.5rem 0; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.rounds > li:first-child { border-top: 0; }
.rounds p { margin: 0.25rem 0; }
.review-context { margin: 0.5rem 0; display: grid; gap: 0.4rem; }
.review-context .badge { margin: 0 0.25rem 0.25rem 0; }
.review-item, .review-item p { overflow-wrap: anywhere; }
/* Nothing may push the page wider than a 375px phone. */
.page-head > * { min-width: 0; }
h1, h2, .notice, .alert, .file-list li, .history li { overflow-wrap: anywhere; }
dialog { overflow-wrap: anywhere; }
.action-form .field { min-width: 0; }

/* Simpler screens: the update form's choice is a row of tappable options that wrap. */
[data-field="progress_state"] > div { display: flex; flex-wrap: wrap; gap: 0.5rem; }
[data-field="progress_state"] > div > div { flex: 1 1 auto; }
[data-field="progress_state"] input[type="radio"] { flex: none; width: auto; margin: 0; }
[data-field="progress_state"] label {
  display: flex; align-items: center; gap: 0.5rem; min-height: 2.75rem; padding: 0.4rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
[data-field="progress_state"] label:has(input:checked) { border-color: var(--info); font-weight: 500; }
[data-field="progress_state"] > label { margin-bottom: 0.25rem; display: block; border: 0; padding: 0; min-height: 0; }

@media (max-width: 767px) {
  /* The dialog scrolls inside itself, and its buttons stay in reach with the keyboard open. */
  dialog { max-height: 90vh; max-height: 90dvh; overflow-y: auto; }
  .dialog-buttons {
    position: sticky; bottom: 0; background: var(--surface); padding: 0.5rem 0; margin-top: 0;
  }
}
/* My tasks: second line of tabs, headings, the one button on a row */
.subtabs { margin-top: 0.25rem; font-size: 0.9rem; }
.list-heading { font-size: 1.05rem; margin: 1rem 0 0.5rem; }
.row-go { margin-left: auto; }
