:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --ink: #172235;
  --muted: #65738a;
  --line: #dee6f0;
  --primary: #176b67;
  --primary-dark: #115450;
  --accent-soft: #e3f5f2;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --success: #087443;
  --success-soft: #dcfae6;
  --shadow: 0 14px 35px rgba(23, 34, 53, 0.06);
  font-family: "Noto Sans Thai", "Segoe UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  margin: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.65rem, 3vw, 2.2rem);
  line-height: 1.25;
  margin-bottom: 0.45rem;
}

h2 {
  font-size: 1.2rem;
  margin-bottom: 1.2rem;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 2rem;
  min-height: 68px;
  padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
}

.brand {
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 750;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 0.4rem 1.35rem;
}

.nav-links a {
  color: var(--muted);
  font-weight: 550;
}

.nav-links a:hover {
  color: var(--primary);
}

.user-actions {
  align-items: center;
  display: flex;
  gap: 1rem;
  white-space: nowrap;
}

.page {
  margin: 0 auto;
  max-width: 1440px;
  padding: clamp(1.25rem, 4vw, 2.5rem);
}

.auth-page {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.auth-card,
.form-card,
.table-card,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.auth-card {
  max-width: 430px;
  padding: clamp(1.5rem, 4vw, 2.4rem);
  width: 100%;
}

.eyebrow {
  color: var(--primary);
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 0.55rem;
  text-transform: uppercase;
}

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

.hint {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.7;
  margin: 1.5rem 0 0;
  padding-top: 1.1rem;
}

code {
  background: #edf2f8;
  border-radius: 5px;
  font-family: Consolas, monospace;
  padding: 0.12rem 0.35rem;
}

.stack-form {
  display: grid;
  gap: 1rem;
}

label {
  color: #344054;
  display: grid;
  font-size: 0.92rem;
  font-weight: 550;
  gap: 0.42rem;
}

input,
select,
textarea {
  background: var(--surface);
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
  font-weight: 400;
  padding: 0.68rem 0.78rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 103, 0.13);
  outline: none;
}

.button {
  align-items: center;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 9px;
  color: white;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  justify-content: center;
  padding: 0.67rem 1.05rem;
}

.button:hover {
  background: var(--primary-dark);
}

.button.secondary {
  background: white;
  border-color: #cbd5e1;
  color: var(--ink);
}

.button.secondary:hover {
  background: #f8fafc;
}

.button.compact {
  font-size: 0.86rem;
  padding: 0.45rem 0.8rem;
}

.alert {
  border-radius: 10px;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
}

.alert.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.alert.success {
  background: var(--success-soft);
  color: var(--success);
}

.page-header {
  align-items: end;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1.55rem;
}

.page-header p:last-child {
  margin-bottom: 0;
}

.filter-bar {
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
}

.filter-bar label {
  min-width: 175px;
}

.text-link {
  margin: 0 0.25rem 0.7rem;
}

.selected-record-date {
  color: var(--primary);
  margin: 0 0.35rem 0.7rem auto;
}

.two-column {
  align-items: start;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(285px, 360px) minmax(400px, 1fr);
}

.form-card {
  padding: 1.35rem;
}

.table-card {
  overflow: auto;
  padding: 1.25rem;
}

.matrix-card {
  max-height: calc(100vh - 285px);
  padding: 0;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 0.88rem;
  font-weight: 650;
  text-align: left;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.82rem 0.9rem;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td small {
  color: var(--muted);
  display: block;
  line-height: 1.45;
  margin-top: 0.25rem;
}

.matrix-table th {
  position: sticky;
  top: 0;
  z-index: 3;
}

.sticky-date {
  left: 0;
  min-width: 125px;
  position: sticky;
  z-index: 2;
}

.sticky-work {
  left: 125px;
  min-width: 270px;
  position: sticky;
  z-index: 2;
}

.matrix-table tbody .sticky-date,
.matrix-table tbody .sticky-work {
  background: white;
}

.matrix-table thead .sticky-date,
.matrix-table thead .sticky-work {
  z-index: 4;
}

.employee-head {
  min-width: 122px;
  text-align: center;
}

.check-cell {
  text-align: center;
}

.summary-row th,
.summary-row td {
  background: #f8fafc;
  border-top: 2px solid var(--line);
  bottom: 0;
  position: sticky;
  z-index: 3;
}

.sticky-summary {
  left: 0;
  min-width: 395px;
  text-align: right;
  z-index: 5 !important;
}

.summary-cell {
  text-align: center;
}

.checkbox-wrap {
  cursor: pointer;
  display: inline-block;
  height: 28px;
  position: relative;
  width: 28px;
}

.checkbox-wrap input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.checkbox-wrap span {
  background: white;
  border: 2px solid #9aa9ba;
  border-radius: 7px;
  display: block;
  height: 28px;
  transition: background 0.14s, border-color 0.14s;
  width: 28px;
}

.checkbox-wrap input:checked + span {
  background: var(--primary);
  border-color: var(--primary);
}

.checkbox-wrap input:checked + span::after {
  border: solid white;
  border-width: 0 2px 2px 0;
  content: "";
  display: block;
  height: 12px;
  margin: 4px 0 0 9px;
  transform: rotate(45deg);
  width: 6px;
}

.checkbox-wrap input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(23, 107, 103, 0.2);
}

.checkbox-wrap input:disabled + span {
  opacity: 0.6;
}

.data-table th,
.data-table td {
  padding-left: 0.72rem;
  padding-right: 0.72rem;
}

.pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.85rem;
  font-weight: 650;
  padding: 0.26rem 0.7rem;
}

.pill.complete {
  background: var(--success-soft);
  color: var(--success);
}

.pill.incomplete {
  background: var(--danger-soft);
  color: var(--danger);
}

.empty-state {
  padding: clamp(1.4rem, 4vw, 2.4rem);
  text-align: center;
}

.empty-state h2 {
  margin-bottom: 0.55rem;
}

.error-state {
  margin: 10vh auto 0;
  max-width: 520px;
}

.error-state .button {
  margin-top: 0.65rem;
}

.narrow {
  max-width: 470px;
}

@media (max-width: 900px) {
  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 0.8rem;
  }

  .user-actions {
    justify-content: space-between;
    width: 100%;
  }

  .two-column {
    grid-template-columns: 1fr;
  }

  .matrix-card {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .page-header {
    align-items: start;
    flex-direction: column;
  }

  .sticky-work {
    left: 102px;
    min-width: 200px;
  }

  .sticky-date {
    min-width: 102px;
  }

  .sticky-summary {
    min-width: 302px;
  }

  .selected-record-date {
    margin-left: 0;
  }
}
