:root {
  --brand: #ee4d2d;
  --brand-soft: #fff1ee;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --ok: #1a8f4c;
  --ok-soft: #e6f6ec;
  --warn: #b26b00;
  --warn-soft: #fff5e0;
  --info: #1f5fbf;
  --info-soft: #e8f0fc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113; --card: #1c1c1f; --text: #f2f2f4; --muted: #9a9aa2; --line: #2c2c31;
    --brand-soft: #3a1c16; --ok-soft: #12301f; --warn-soft: #3a2a0b; --info-soft: #142640;
    --ok: #4fd08a; --warn: #f0b14a; --info: #7fb0ff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Sarabun", system-ui, sans-serif; font-size: 16px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; display: block; }
h1 { font-size: 1.35rem; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: .95rem; margin: 0 0 6px; color: var(--muted); font-weight: 600; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; display: flex; gap: 8px; align-items: center; }
.logo { background: var(--brand); color: #fff; border-radius: 8px; width: 28px; height: 28px;
  display: grid; place-items: center; font-size: .8rem; }

main { max-width: 900px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; text-align: center; padding: 6px 0 8px; font-size: .75rem; color: var(--muted); }
.tabbar a span { display: block; font-size: 1.25rem; line-height: 1.3; }
.tabbar a.active { color: var(--brand); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 10px; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
  min-height: 42px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: #d33; }
.btn.sm { padding: 5px 10px; min-height: 34px; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.block { width: 100%; }

label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chip { white-space: nowrap; padding: 5px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line);
  font-size: .88rem; cursor: pointer; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px; font-weight: 600;
  background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; }
.stat span { font-size: .85rem; color: var(--muted); }
.stat.alert b { color: var(--brand); }

.list-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--bg); flex: none;
  display: grid; place-items: center; font-size: 1.4rem; overflow: hidden; }
.thumb.tall { width: 54px; height: 76px; }
.title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ch-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

.slot { margin-bottom: 12px; }
.slot-head { font-weight: 700; font-size: .9rem; margin-bottom: 4px; }

.copybox { position: relative; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px;
  padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: .92rem; margin-bottom: 8px; }
.copybox.empty { color: var(--muted); font-style: italic; }

.post-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.post-row.done { border-color: var(--ok); background: var(--ok-soft); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--card); color: var(--text); font: inherit; font-size: .85rem; padding: 7px 4px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }

.link-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.link-row:last-child { border-bottom: 0; }
.url { font-size: .8rem; color: var(--muted); word-break: break-all; }

.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.previews img { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; }

.hero-img { width: 100%; max-height: 320px; object-fit: contain; border-radius: 12px; background: var(--bg); }
.media-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.media-grid video, .media-grid img { width: 100%; aspect-ratio: 9/16; object-fit: cover; border-radius: 10px; background: #000; }
.media-slot { aspect-ratio: 9/16; border: 2px dashed var(--line); border-radius: 10px; display: grid; place-items: center; color: var(--muted); text-align: center; font-size: .9rem; cursor: pointer; }

.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: .92rem; }
.notice.info { background: var(--info-soft); color: var(--info); }

.week { display: grid; gap: 10px; }
.day h2 { display: flex; justify-content: space-between; }
.day.today { outline: 2px solid var(--brand); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: .95; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.empty-state { text-align: center; color: var(--muted); padding: 24px 8px; }

.login { max-width: 360px; margin: 12vh auto; }
