/* Admin UI tuned for older users: large type, high contrast, big targets, words over icons. */
:root {
  --bg: #F5F0E6;
  --card: #FFFFFF;
  --ink: #1D1712;
  --soft: #54463B;
  --line: #D8CBB6;
  --maroon: #7A1F1F;
  --maroon-dark: #5A1414;
  --gold: #C99A3E;
  --green: #1E7B34;
  --green-dark: #155E27;
  --red: #B3261E;
  --focus: #E8B65A;
  --radius: 16px;
}
html { font-size: 20px; }
html[data-fs="s"] { font-size: 17px; }
html[data-fs="l"] { font-size: 24px; }

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 1rem/1.65 "Sarabun", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { line-height: 1.35; margin: 0; }
img { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.loading { text-align: center; padding: 30vh 16px; color: var(--soft); }

.shell { width: min(820px, 100% - 32px); margin: 0 auto; padding: 24px 0 140px; }

/* ---------- Top bar ---------- */
.topbar { background: var(--maroon); color: #fff; position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 10px rgba(0, 0, 0, .15); }
.topbar-inner { width: min(820px, 100% - 32px); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; flex-wrap: wrap; }
.topbar-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; text-decoration: none; color: #fff; }
.topbar-title svg { width: 34px; height: 34px; color: var(--focus); flex: none; }
.topbar-inner { flex-wrap: nowrap; }
.fs-card { margin-top: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.fs-label { font-weight: 700; }
.fs-switch { display: flex; gap: 6px; }
.fs-switch button { background: #fff; border: 2px solid var(--line); color: var(--ink); border-radius: 10px; padding: 4px 16px; cursor: pointer; font-weight: 700; min-height: 48px; }
.fs-switch button[data-size="s"] { font-size: .85rem; }
.fs-switch button[data-size="l"] { font-size: 1.2rem; }
.fs-switch button[aria-pressed="true"] { background: var(--maroon); border-color: var(--maroon); color: #fff; }
.tile-plus { width: 2.6rem; height: 2.6rem; border-radius: 50%; background: #fff; color: var(--maroon); font-weight: 700; font-size: 2rem; line-height: 2.5rem; }
.login-back a, .shell a:not(.btn) { color: var(--maroon); font-weight: 600; }
.btn-logout { background: none; border: 2px solid rgba(255, 255, 255, .6); color: #fff; border-radius: 12px; padding: 4px 14px; min-height: 44px; cursor: pointer; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 3rem; padding: 10px 24px; border-radius: 14px; border: 2px solid transparent;
  font-weight: 700; font-size: 1rem; cursor: pointer; text-decoration: none; text-align: center;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--maroon); color: #fff; }
.btn-primary:hover { background: var(--maroon-dark); }
.btn-save { background: var(--green); color: #fff; font-size: 1.1rem; min-height: 3.3rem; }
.btn-save:hover { background: var(--green-dark); }
.btn-light { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-light:hover { border-color: var(--soft); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger-outline { background: #fff; color: var(--red); border-color: var(--red); }
.btn-block { width: 100%; }
.btn-back {
  background: none; border: 0; color: var(--maroon); font-weight: 700; font-size: 1rem;
  padding: 8px 0; min-height: 48px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn-back:hover { text-decoration: underline; }
.btn-small {
  background: #fff; border: 2px solid var(--line); border-radius: 10px; padding: 4px 12px;
  min-height: 44px; font-weight: 600; cursor: pointer; font-size: .9rem;
}
.btn-small:disabled { opacity: .35; cursor: default; }
.btn-small.danger { color: var(--red); border-color: #E7B7B3; }

/* ---------- Home ---------- */
.hello h1 { font-size: 1.7rem; }
.hello p { margin: 4px 0 24px; color: var(--soft); font-size: 1.05rem; }
.group-title { font-size: 1.1rem; color: var(--soft); margin: 32px 0 12px; font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.tile {
  display: flex; align-items: center; gap: 16px; text-align: left;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; cursor: pointer; min-height: 5.2rem; text-decoration: none; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.tile:hover { border-color: var(--maroon); box-shadow: 0 6px 18px -10px rgba(122, 31, 31, .5); }
.tile-icon { font-size: 2rem; line-height: 1; flex: none; width: 2.6rem; text-align: center; }
.tile strong { display: block; font-size: 1.1rem; }
.tile small { display: block; color: var(--soft); font-size: .88rem; line-height: 1.45; }
.tile-hero {
  grid-column: 1 / -1; background: var(--maroon); border-color: var(--maroon); color: #fff; min-height: 6rem;
}
.tile-hero small { color: rgba(255, 255, 255, .85); }
.tile-hero:hover { background: var(--maroon-dark); }
.tile-hero strong { font-size: 1.3rem; }
.view-site { margin-top: 32px; }

/* ---------- Page header ---------- */
.page-head { margin: 4px 0 20px; }
.page-head h1 { font-size: 1.6rem; display: flex; align-items: center; gap: 10px; }
.page-head p { margin: 4px 0 0; color: var(--soft); }
.note { background: #FFF6DD; border: 2px solid #EFD9A0; border-radius: 12px; padding: 10px 16px; margin: 0 0 18px; font-size: .95rem; }

/* ---------- Item list ---------- */
.items { display: grid; gap: 12px; margin-top: 20px; }
.item {
  display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.item-thumb { width: 96px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--bg); }
.item-thumb.empty { display: grid; place-items: center; color: var(--soft); font-size: .75rem; text-align: center; }
.item-main { min-width: 0; }
.item-title { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.item-sub { color: var(--soft); font-size: .9rem; }
.item-badge { display: inline-block; background: #EEE; color: var(--soft); border-radius: 999px; padding: 0 10px; font-size: .8rem; font-weight: 600; margin-left: 6px; }
.item-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.item-actions .btn { min-height: 2.6rem; padding: 6px 18px; font-size: .95rem; }
.item-actions .spacer { flex: 1; }
.empty-box { background: var(--card); border: 2px dashed var(--line); border-radius: var(--radius); padding: 36px 20px; text-align: center; color: var(--soft); }

/* ---------- Forms ---------- */
.form { display: grid; gap: 22px; }
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 22px; }
.field { display: grid; gap: 6px; min-width: 0; border: 0; padding: 0; margin: 0; }
.label { font-weight: 700; font-size: 1.05rem; padding: 0; }
.req { color: var(--red); font-weight: 600; font-size: .85rem; }
.help { margin: -4px 0 2px; color: var(--soft); font-size: .9rem; }
.input {
  width: 100%; padding: 12px 14px; min-height: 3rem;
  border: 2px solid #A89883; border-radius: 12px; background: #fff; font-size: 1.05rem;
}
.input:focus { border-color: var(--maroon); outline: 4px solid var(--focus); outline-offset: 0; }
textarea.input { resize: vertical; line-height: 1.6; }
.field.has-error .input { border-color: var(--red); background: #FFF7F6; }
.error { margin: 0; color: var(--red); font-weight: 600; }
.date-preview { margin: 0; color: var(--maroon); font-weight: 600; }
.check { display: flex; align-items: center; gap: 14px; cursor: pointer; font-weight: 600; background: #FFF9EC; border: 2px solid #EFD9A0; border-radius: 12px; padding: 12px 16px; }
.check input { width: 1.6rem; height: 1.6rem; accent-color: var(--maroon); flex: none; }

.img-field { display: grid; gap: 10px; }
.img-preview img { width: 100%; max-height: 320px; object-fit: contain; background: var(--bg); border-radius: 12px; border: 2px solid var(--line); }
.img-empty { border: 2px dashed #A89883; border-radius: 12px; padding: 28px; text-align: center; color: var(--soft); background: #fff; }
.img-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

.field-rows .rows { display: grid; gap: 12px; }
.row-box { border: 2px solid var(--line); border-radius: 14px; padding: 14px; background: #FCFAF6; display: grid; gap: 12px; }
.row-box .form { gap: 12px; }
.row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-add { justify-self: start; }

.danger-zone { margin-top: 36px; padding-top: 24px; border-top: 2px dashed var(--line); }

/* ---------- Sticky save bar ---------- */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: #fff; border-top: 2px solid var(--line); box-shadow: 0 -6px 20px rgba(0, 0, 0, .08);
}
.savebar-inner { width: min(820px, 100% - 32px); margin: 0 auto; padding: 12px 0; display: flex; gap: 12px; align-items: center; }
.savebar .btn-save { flex: 1; }
.dirty-hint { display: none; position: absolute; left: 0; right: 0; bottom: 100%; background: #FFF1C9; color: #6B4B00; text-align: center; font-weight: 600; font-size: .9rem; padding: 4px; }
body.is-dirty .dirty-hint { display: block; }

/* ---------- Toast & modal ---------- */
.toast {
  position: fixed; top: 16px; left: 0; right: 0; margin: 0 auto; z-index: 60; translate: 0 -140%;
  width: fit-content; max-width: calc(100% - 32px); padding: 14px 24px; border-radius: 14px; text-align: center;
  font-weight: 700; font-size: 1.05rem; color: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  transition: translate .3s;
}
.toast.show { translate: 0 0; }
.toast-ok { background: var(--green); }
.toast-err { background: var(--red); }

.modal-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(20, 10, 5, .55); display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 20px; padding: 28px; width: min(480px, 100%); box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal h2 { font-size: 1.35rem; }
.modal p { color: var(--soft); margin: 8px 0 0; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { background: #fff; border-radius: 24px; padding: 36px 28px; width: min(460px, 100%); box-shadow: 0 20px 50px -20px rgba(90, 20, 20, .35); display: grid; gap: 18px; }
.login-logo { width: 72px; height: 72px; color: var(--maroon); margin: 0 auto; }
.login-card h1 { text-align: center; font-size: 1.5rem; }
.login-card .sub { text-align: center; color: var(--soft); margin: -12px 0 4px; }
.login-back { text-align: center; color: var(--soft); }
.form-error { background: #FDECEA; color: var(--red); border-radius: 12px; padding: 10px 14px; font-weight: 600; margin: 0; }

@media (max-width: 640px) {
  .shell { padding-top: 16px; }
  .tiles { grid-template-columns: 1fr; }
  .topbar-title { font-size: .95rem; }
  .btn-logout { flex: none; }
  .item-thumb { width: 72px; height: 56px; }
  .item-actions .btn { flex: 1; }
  .item-actions .spacer { display: none; }
  .modal-actions { grid-template-columns: 1fr; }
  .modal-actions .btn-light { order: 2; }
}
