/* Minimal theme: one font (Sarabun), grey surfaces, colour only where it means something
   (labels, a full lane, a danger button). Dark mode follows the device. */

:root {
  --bg: #f6f6f4;
  --lane: #ecebe7;
  --card: #ffffff;
  --text: #1f1f1d;
  --muted: #6b6a66;
  --line: #dddcd7;
  --accent: #2f5fd0;
  --warn-bg: #fbefd5;
  --warn: #8a5a00;
  --danger-bg: #fbe3e1;
  --danger: #a3261f;
  --radius: 10px;
  --label-l-bg: 92%;
  --label-l-text: 28%;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --lane: #222220;
    --card: #2b2b29;
    --text: #ecebe7;
    --muted: #a3a29c;
    --line: #3a3a37;
    --accent: #8db0ff;
    --warn-bg: #4a3a12;
    --warn: #f5d38a;
    --danger-bg: #4d1f1c;
    --danger: #ffb4ad;
    --label-l-bg: 26%;
    --label-l-text: 86%;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must win over every display rule below (.filters, .user, .custom-range
   all set display, which would otherwise show them while "hidden"). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 'Sarabun', system-ui, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; margin: 0; }

/* --- top bar --------------------------------------------------------------------------- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 20px; margin-right: auto; }
.top a.back { color: var(--muted); font-size: 14px; text-decoration: none; }
.top a.back::before { content: "← "; }
.top a.back:hover { color: var(--text); text-decoration: underline; }
.top a.nav { color: var(--muted); font-size: 14px; text-decoration: none; }
.top a.nav:hover { color: var(--text); text-decoration: underline; }

/* --- people and levels (owner only) ------------------------------------------------------ */

.people { padding: 16px; max-width: 1100px; }
.people h2 { font-size: 18px; margin-bottom: 4px; }
.people-section { margin-top: 18px; max-width: 760px; }
.people-section h3 { font-size: 15px; margin-bottom: 8px; }
.people-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; max-width: 720px; }
.people-list li { display: flex; align-items: baseline; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.person-email { font-weight: 500; overflow-wrap: anywhere; }
.person-name { color: var(--muted); margin-right: auto; }
.people button.link.danger-link { color: var(--danger); }
.person-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; max-width: 720px; }
.person-form input { flex: 1 1 200px; }
.person-form .form-error { flex-basis: 100%; margin: 0; }
.perm-wrap { overflow-x: auto; }
.perm-table { border-collapse: collapse; font-size: 13px; }
.perm-table th, .perm-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: middle; }
.perm-table { width: 100%; }
.perm-table tr:first-child th { font-weight: 600; background: var(--lane); }
.perm-table td.person { white-space: nowrap; font-weight: 500; }
.perm-table select { min-width: 120px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.section-head h3 { margin: 0; margin-right: auto; }
.level-note { font-size: 13px; color: var(--warn); background: var(--warn-bg); padding: 2px 10px; border-radius: 999px; }

/* --- the list of boards ---------------------------------------------------------------- */

.boards { padding: 16px; max-width: 720px; }
.boards h2 { font-size: 18px; margin-bottom: 8px; }
.board-group h3 { font-size: 14px; color: var(--muted); margin: 16px 0 6px; }
.board-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.board-list li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.board-link { color: var(--text); font-weight: 500; text-decoration: none; margin-right: auto; overflow-wrap: anywhere; }
.board-link:hover { text-decoration: underline; }
.board-count { font-size: 13px; color: var(--muted); white-space: nowrap; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filters input[type="search"] { width: 180px; }
.custom-range, .thai-date { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }

input, select, textarea {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  min-height: 36px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 14px;
  min-height: 36px;
  cursor: pointer;
}
button:hover { background: var(--lane); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: transparent; }
button.danger:hover { background: var(--danger-bg); }
button.link { border: none; color: var(--muted); padding: 6px 4px; }
button.link:hover { background: none; color: var(--text); text-decoration: underline; }

.user { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

/* --- board ----------------------------------------------------------------------------- */

.board {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  overflow-x: auto;
  min-height: calc(100vh - 70px);
}

.lane {
  flex: 0 0 280px;
  background: var(--lane);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 110px);
}

.lane-head { display: flex; align-items: center; gap: 8px; padding: 2px 2px 8px; }
.lane-name {
  border: none;
  padding: 2px 4px;
  min-height: 0;
  font-weight: 600;
  text-align: left;
  margin-right: auto;
}
.lane-count { font-size: 13px; color: var(--muted); padding: 1px 8px; border-radius: 999px; }
.lane-count.full { background: var(--warn-bg); color: var(--warn); }
.lane-count.over { background: var(--danger-bg); color: var(--danger); }
.lane-shown { font-size: 12px; color: var(--muted); }

.cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 48px;
  overflow-y: auto;
  padding: 2px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
.card:hover { border-color: var(--muted); }
.card.dragging { opacity: 0.4; }
.card-title { font-size: 15px; font-weight: 500; overflow-wrap: anywhere; }
.card-desc-mark { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.due { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.due.late { color: var(--danger); }
.due.done { color: var(--muted); text-decoration: line-through; }

/* what came with the Trello import, inside the card dialog */
.extras { display: flex; flex-direction: column; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.extras h4 { font-size: 13px; font-weight: 600; margin: 0 0 4px; }
.extras ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.extras .extra-line { margin: 0; }
.checklist li { display: flex; align-items: baseline; gap: 8px; }
.checklist input[type="checkbox"] { width: auto; min-height: 0; margin: 0; padding: 0; flex: none; }
.checklist li.done span { color: var(--muted); text-decoration: line-through; }
.attachments a, .extra-line a { color: var(--accent); overflow-wrap: anywhere; }
.comment { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
.comment .meta { margin: 0; }
.comment-text { margin: 2px 0 0; overflow-wrap: anywhere; }

/* the description field: formatted when read, plain markdown when edited */
.desc-field { display: flex; flex-direction: column; gap: 4px; }
.desc-head { display: flex; align-items: baseline; gap: 8px; }
.desc-head .field-name { font-weight: 500; margin-right: auto; }
.desc-view { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; max-height: 50vh; overflow-y: auto; }

/* formatted markdown (descriptions and comments) */
.md { font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 8px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 12px 0 6px; line-height: 1.35; }
.md h1 { font-size: 18px; } .md h2 { font-size: 16px; } .md h3, .md h4, .md h5, .md h6 { font-size: 15px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 2px 0; }
.md a { color: var(--accent); }
.md a:not([href]) { color: inherit; } /* a link whose address was removed as unsafe is plain text */
.md code { font-family: Consolas, "Courier New", monospace; font-size: 13px; background: var(--lane); border-radius: 4px; padding: 1px 4px; }
.md pre { background: var(--lane); border-radius: 6px; padding: 8px 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md img { max-width: 100%; }
span.lane-name { cursor: default; }
.labels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.label {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  background: hsl(var(--h) 60% var(--label-l-bg));
  color: hsl(var(--h) 55% var(--label-l-text));
}
.meta { margin: 6px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.meta span { display: block; }

.drop-marker { height: 3px; border-radius: 3px; background: var(--accent); }

.add-card { border: none; color: var(--muted); text-align: left; margin-top: 6px; }
.add-lane { flex: 0 0 200px; border-style: dashed; color: var(--muted); }

/* --- loading (until Firebase says who is signed in; about 3 s on a first visit) -------- */

.loading { text-align: center; color: var(--muted); margin-top: 18vh; }

/* --- sign-in --------------------------------------------------------------------------- */

.signin { max-width: 360px; margin: 18vh auto; text-align: center; padding: 0 16px; }
.signin p { color: var(--muted); }

/* --- dialogs --------------------------------------------------------------------------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  padding: 20px;
  width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
dialog label small { font-weight: 400; color: var(--muted); }
dialog textarea { resize: vertical; }
.label-picks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -6px; }
.label-picks .label { border: none; min-height: 0; cursor: pointer; }
.label-picks .label.on { outline: 2px solid currentColor; }
.form-error { color: var(--danger); margin: 0; min-height: 1em; font-size: 14px; }
.actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  max-width: calc(100vw - 32px);
  z-index: 10;
}

@media (max-width: 600px) {
  .top h1 { width: 100%; }
  .filters input[type="search"] { width: 100%; }
  .lane { flex-basis: 85vw; }
}
