:root {
  color-scheme: light;
  --ink: #171715;
  --paper: #f4f2e9;
  --surface: #fffdf7;
  --red: #990c19;
  --muted: #68665f;
  --line: #d8d2c7;
  --soft: #ebe7dc;
  --brand-font: "Barlow Condensed", "IBM Plex Sans Thai", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 "IBM Plex Sans Thai", system-ui, sans-serif;
}
h1, h2, p { margin: 0; }
h1 { font-family: var(--brand-font); font-size: clamp(2.3rem, 6vw, 4.2rem); line-height: 1.08; }
h2 { font-size: 1.28rem; line-height: 1.3; }
a { color: var(--red); text-underline-offset: 3px; }
button, input, textarea, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .53; }
:focus-visible { outline: 3px solid #b6802d; outline-offset: 3px; }

.shell { width: min(70rem, calc(100% - 2rem)); margin-inline: auto; }
main.shell { padding-block: clamp(1.5rem, 5vw, 3.5rem) 4rem; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner, .topbar-actions, .dashboard-heading, .section-heading, .form-actions {
  display: flex;
  align-items: center;
  gap: .8rem;
  flex-wrap: wrap;
}
.topbar-inner, .dashboard-heading, .section-heading { justify-content: space-between; }
.topbar-inner { min-height: 4rem; padding-block: .5rem; }
.topbar-actions { margin-left: auto; justify-content: flex-end; }
.account-menu { position: relative; }
.account-menu summary {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
  cursor: pointer;
  font-size: 1.25rem;
  list-style: none;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu-items {
  position: absolute;
  z-index: 2;
  inset-inline-end: 0;
  top: calc(100% + .35rem);
  display: grid;
  min-width: 11rem;
  padding: .28rem;
  border: 1px solid var(--line);
  border-radius: .3rem;
  background: var(--surface);
  box-shadow: 0 .35rem .9rem rgb(23 23 21 / 12%);
}
.account-menu-items > :is(a, button) {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: .45rem .7rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: start;
  text-decoration: none;
  white-space: nowrap;
}
.account-menu-items > :is(a, button):hover { background: var(--soft); }
.brand { display: flex; }
.brand img { object-fit: contain; }
.backoffice-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0 .45rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}
.backoffice-tabs a {
  display: flex;
  align-items: center;
  min-height: 50px;
  padding: .65rem .95rem;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-size: .94rem;
  font-weight: 500;
}
.backoffice-tabs a[aria-current="page"] {
  border-color: var(--red);
  color: var(--ink);
  font-weight: 600;
}
.dashboard-heading { margin-bottom: 1rem; }
.dashboard-heading h1 { margin-block: .15rem .3rem; }
.surface {
  margin-block: 1rem;
  padding: clamp(1rem, 4vw, 1.6rem);
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: var(--surface);
}
.section-heading { margin-bottom: 1rem; }
.section-heading h2 + p { margin-top: .3rem; }
.auth { max-width: 31rem; margin: clamp(.5rem, 6vw, 3rem) auto; }
.auth h1 { margin: .4rem 0; font-size: clamp(1.8rem, 5vw, 2.6rem); }
.auth form, .chart-form, .chart-inputs { display: grid; gap: .55rem; }
.auth form { margin-top: 1rem; }
.auth form label, .chart-form label { margin-top: .35rem; }
.auth form .button, .auth-links { margin-top: .55rem; }
.auth-links { display: flex; flex-wrap: wrap; gap: .45rem 1rem; }
.proof { display: grid; gap: .5rem; }
.eyebrow { color: var(--red); font-size: .8rem; font-weight: 700; letter-spacing: .05em; }
.muted, small { color: var(--muted); }
.terms { white-space: pre-line; overflow-wrap: anywhere; margin-bottom: .6rem; }
.notice { padding: .7rem .8rem; border: 1px solid var(--line); border-radius: .3rem; background: var(--soft); }
.notice[data-error] { color: #810f18; border-color: #dcb6b8; background: #fff1f1; }
.form-actions { margin-top: .9rem; }
.button {
  min-height: 42px;
  padding: .46rem .9rem;
  border: 1px solid transparent;
  border-radius: .28rem;
  font-weight: 600;
}
.button-primary { color: #fff; background: var(--red); }
.button-primary:hover:not(:disabled) { background: #760813; }
.button-outline { background: var(--surface); border-color: #a7a094; }
.button-outline:hover:not(:disabled) { background: var(--soft); }
.text-button {
  border: 0;
  padding: .2rem 0;
  color: var(--red);
  background: transparent;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}
label, legend { font-weight: 600; }
input, textarea, select {
  min-width: 0;
  max-width: 100%;
  min-height: 42px;
  padding: .45rem .55rem;
  border: 1px solid #a7a094;
  border-radius: .28rem;
  background: #fff;
}
textarea { resize: vertical; }
.select-label { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.select-label select { max-width: min(18rem, 100%); }
fieldset { border: 1px solid var(--line); border-radius: .4rem; min-width: 0; margin: .9rem 0; padding: .75rem; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; }
.form-grid label { display: grid; gap: .22rem; }
.span-all { grid-column: 1 / -1; }
#removeSet { margin-top: .6rem; }
#editTable { margin-top: 1rem; }
#settingsStatus { margin-top: .7rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: .3rem; }
table { border-collapse: collapse; width: 100%; text-align: left; }
th, td { padding: .55rem .65rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
thead th { background: var(--soft); }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 600; }
tbody th small { display: block; font-size: .82rem; font-weight: 400; }
.price-cell { width: 8.5rem; text-align: right; }
.price-input { width: 8rem; text-align: right; }
.extra-columns-editor { padding-block: 1rem; margin-top: .6rem; border-top: 1px solid var(--line); }
.extra-columns-editor h3 { margin: 0; font-size: 1rem; }
.extra-columns-editor .section-heading { align-items: flex-start; }
.extra-columns-editor .section-heading > div { flex: 1 1 20rem; min-width: 0; }
.extra-columns-list { display: grid; gap: .75rem; margin-top: .65rem; }
.extra-column-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .6rem; }
.extra-column-control label { display: grid; gap: .3rem; min-width: 0; }
.extra-column-control input { width: 100%; }
.extra-prices-table { min-width: calc(24rem + var(--extra-count) * 11rem); }
.extra-detail-cell { min-width: 11rem; max-width: 16rem; text-align: left; overflow-wrap: anywhere; }
.extra-detail-input { display: block; min-width: 9rem; width: 100%; min-height: 4.5rem; resize: vertical; }
.extra-detail-value { white-space: pre-wrap; overflow-wrap: anywhere; }
.list-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.list-row strong, .list-row small { overflow-wrap: anywhere; }
.account-group { margin-block: 1.25rem; }
.account-group h2 { margin-bottom: .7rem; }
.account-card { padding: .85rem 0; border-top: 1px solid var(--line); }
.account-identity { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .6rem; }
.account-identity strong { overflow-wrap: anywhere; }
.account-permissions { margin-block: .55rem 0; }
.account-permissions legend { padding-inline: .25rem; overflow-wrap: anywhere; }
.account-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
.account-checks label { display: flex; align-items: center; gap: .5rem; min-height: 44px; font-weight: 400; }
.account-checks input { flex: none; width: 1.12rem; height: 1.12rem; min-height: 0; padding: 0; accent-color: var(--red); }

dialog {
  width: min(34rem, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  padding: clamp(1rem, 4vw, 1.45rem);
  border: 1px solid var(--line);
  border-radius: .6rem;
  color: var(--ink);
  background: var(--surface);
}
dialog::backdrop { background: rgb(23 23 21 / 65%); }
.chart-form .section-heading { margin: 0; }
.chart-form .muted { margin-top: .35rem; }
#chartDialog:has(#chartPreview:not([hidden])) { width: min(58rem, calc(100% - 2rem)); }
#chartPreview { margin-top: .5rem; min-width: 0; }
#chartPreviewTitle { margin: .4rem 0 .65rem; font-size: 1rem; }
#chartPreviewPages { display: grid; gap: .8rem; }
#chartPreviewPages img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: .28rem;
}

@media (max-width: 36rem) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar-actions { font-size: .86rem; }
  .backoffice-tabs { gap: 0; }
  .backoffice-tabs a { padding: .55rem .6rem; font-size: .88rem; }
  .price-input { width: 6.25rem; }
  th, td { padding-inline: .45rem; }
}
