/* The Attendance board, design B of Forge #5: one screen per task. Mobile first: on a phone the tabs sit
   at the bottom and each list is cards; from 800px the tabs are a sidebar and each list is a table. */

:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e0d8;
  --in: #1f7a4d;
  --in-bg: #e3f3ea;
  --out: #9a4a12;
  --out-bg: #fbeadd;
  --bad: #b3261e;
  --bad-bg: #fde7e5;
  --accent: #2f5fa7;
  --new: #fff6c7;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --card: #1f1f1d;
    --fg: #ecece8;
    --muted: #a3a39c;
    --line: #34342f;
    --in: #6fd39e;
    --in-bg: #173527;
    --out: #f2a974;
    --out-bg: #3b2414;
    --bad: #ff8a80;
    --bad-bg: #3d1714;
    --accent: #8db4f0;
    --new: #3d3510;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', system-ui, sans-serif;
}

h1,
h2 {
  margin: 0 0 8px;
  line-height: 1.25;
}

h2 {
  margin-top: 16px;
  font-size: 22px;
}

/* ---- The shell: tabs and the screen beside them ---- */

.tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
}

.tabs .brand {
  display: none;
}

.tabs a {
  position: relative;
  padding: 10px 4px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

.tabs a[aria-current='page'] {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

/* A Terminal is unreachable. */
.tabs .dot {
  position: absolute;
  top: 8px;
  right: 22%;
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--bad);
}

.tabs .dot[hidden] {
  display: none;
}

.body {
  padding: 12px 16px 96px;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 8px;
}

header h1 {
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}

#day {
  font-weight: normal;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.status[data-state='live']::before {
  content: '● ';
  color: var(--in);
}

.status[data-state='error'] {
  color: var(--bad);
}

.empty {
  color: var(--muted);
}

/* ---- A list: cards on a phone ---- */

.rows,
.rows tbody,
.rows tr,
.rows td {
  display: block;
}

.rows {
  width: 100%;
  border-collapse: collapse;
}

.rows thead {
  display: none;
}

/* Line 1: time, name, direction. Line 2, after the zero-height break: the rest, muted. */
.rows tr {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.rows tr::before {
  content: '';
  order: 4;
  flex-basis: 100%;
  height: 0;
}

.rows td {
  order: 5;
  min-width: 0;
  padding: 0;
}

.rows td.time {
  order: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.rows td.name {
  order: 2;
  flex: 1;
  font-weight: 600;
}

.rows td.direction {
  order: 3;
  padding: 1px 10px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
}

.rows tr.check-in td.direction {
  background: var(--in-bg);
  color: var(--in);
}

.rows tr.check-out td.direction {
  background: var(--out-bg);
  color: var(--out);
}

.rows td.badgenumber,
.rows td.program,
.rows td.place,
.rows td.ip {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.rows td.program::before,
.rows td.place::before {
  content: '· ';
}

.rows td.name.unknown {
  color: var(--muted);
  font-style: italic;
  font-weight: normal;
}

/* A Terminal's status: its own line on a card, coloured by its tone. */
.rows td.state {
  order: 6;
  flex-basis: 100%;
  font-weight: 600;
}

.rows tr.ok,
.rows tr.down {
  border-left: 4px solid var(--tone);
}

.rows tr.ok {
  --tone: var(--in);
}

.rows tr.down {
  --tone: var(--bad);
  background: var(--bad-bg);
}

.rows tr.never {
  --tone: var(--muted);
}

.rows tr.ok td.state,
.rows tr.down td.state,
.rows tr.never td.state {
  color: var(--tone);
}

.rows tr.new {
  animation: arrive 4s ease-out;
}

/* ---- ค้นหา and หลักสูตร (Forge #7) ---- */

.field {
  width: 100%;
  max-width: 560px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
}

.field[hidden] {
  display: none;
}

/* A Student's day, beside their name: green once they have come in. */
.rows td.answer {
  order: 3;
  padding: 1px 10px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rows tr.yes td.answer {
  background: var(--in-bg);
  color: var(--in);
}

.rows tr.no td.answer {
  background: color-mix(in srgb, var(--line) 50%, transparent);
  color: var(--muted);
}

/* "Not yet" and "came in": stacked on a phone, side by side on a wide screen. */
.split {
  display: grid;
  gap: 16px;
}

.split[hidden] {
  display: none;
}

h3 {
  margin: 8px 0;
  font-size: 17px;
}

h3.no {
  color: var(--bad);
}

h3.yes {
  color: var(--in);
}

.names {
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  list-style: none;
}

.names li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.names li:last-child {
  border-bottom: 0;
}

.names small {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.names:empty {
  display: none;
}

@keyframes arrive {
  from {
    background: var(--new);
  }
}

/* ---- A wide screen: the tabs are a sidebar, and each list is a table ---- */

@media (min-width: 800px) {
  body {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: 100vh;
  }

  .tabs {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: 100vh;
    padding: 16px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .tabs .brand {
    display: block;
    padding: 0 8px 16px;
    font-size: 20px;
  }

  .tabs a {
    padding: 10px 12px;
    text-align: left;
  }

  .tabs .dot {
    top: 18px;
    right: 12px;
  }

  .body {
    max-width: 1200px;
    padding: 24px 32px 80px;
  }

  .rows {
    display: table;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
  }

  .rows thead {
    display: table-header-group;
  }

  .rows tbody {
    display: table-row-group;
  }

  .rows tr {
    display: table-row;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
  }

  .rows tr::before,
  .rows td.program::before,
  .rows td.place::before {
    content: none;
  }

  .rows th,
  .rows td,
  .rows td.direction,
  .rows td.answer {
    display: table-cell;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    text-align: left;
    white-space: nowrap;
  }

  .rows th {
    background: color-mix(in srgb, var(--line) 35%, var(--card));
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
  }

  .rows tr.check-in td.direction,
  .rows tr.check-out td.direction,
  .rows tr.yes td.answer,
  .rows tr.no td.answer {
    background: none;
  }

  .split {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .rows tr.ok,
  .rows tr.down {
    border-left: 0;
  }

  .rows tr.ok td:first-child,
  .rows tr.down td:first-child {
    box-shadow: inset 4px 0 var(--tone);
  }
}

/* ---- Sign-in (Forge #9): the sign-in, "not yet", refusal and failure pages, and sign-out ---- */

body.gate {
  display: grid;
  min-height: 100vh;
  padding: 16px;
  place-items: center;
  grid-template-columns: minmax(0, 1fr);
}

.gate-card {
  width: 100%;
  max-width: 420px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.gate-card .brand {
  display: block;
  margin-bottom: 16px;
  color: var(--accent);
  font-size: 20px;
}

.gate-card h1 {
  font-size: 22px;
}

.gate-card p {
  color: var(--muted);
}

.gate-card form {
  margin: 0;
}

.button {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--card);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button.quiet,
.sign-out button {
  border: 1px solid var(--line);
  background: none;
  color: var(--fg);
}

.sign-out {
  margin: 0;
}

.sign-out button {
  padding: 4px 10px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
