/* PokerJoker palette (same as the fortune-wheel admin); Thai-capable font stack */
:root {
  --bg: #F3F7F6; --surface: #ffffff; --text: #0B2B29; --muted: #5B726E; --line: #DCE7E4;
  --accent: #1E6A5D; --accent-soft: #E3F2EF; --good: #0f8a5f; --good-soft: #e3f6ee;
  --warn: #b25e00; --warn-soft: #fff1dc; --bad: #c62a4a; --bad-soft: #fde8ec;
  --ph: #DDF1EC; --tg: #0E1621; --tg-msg: #182533;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Tahoma, Roboto, sans-serif;
  --mono: ui-monospace, Consolas, "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #06201F; --surface: #0B2B29; --text: #FAFBFB; --muted: #A7C2BC; --line: #1C4541;
    --accent: #30C7B0; --accent-soft: #123C38; --good: #4ade9b; --good-soft: #143326;
    --warn: #fbbf5a; --warn-soft: #3a2a10; --bad: #fb7192; --bad-soft: #3d1621; --ph: #134A43;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
.hidden { display: none !important; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 18px; }
h3 { font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
code { font: 12.5px var(--mono); background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); font-weight: 600; }
button.ghost:hover, button.small:hover { background: var(--accent-soft); }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { width: 100%; resize: vertical; min-height: 92px; line-height: 1.55; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.bad, textarea.bad { border-color: var(--bad); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); min-height: 1.4em; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 420px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; display: flex; align-items: center; gap: 10px; }
.login-logo { width: 34px; height: 34px; }
.login-card form { display: flex; flex-direction: column; gap: 8px; }

/* shell */
.bar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 10px 20px; background: #0B2B29; color: #FAFBFB; border-bottom: 1px solid #1C4541; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.brand img { height: 20px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tab { border: 0; background: transparent; color: #A7C2BC; font-weight: 600; }
.tab.active { background: #123C38; color: #30C7B0; }
.bar-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.bar select { background: #0B2B29; color: #FAFBFB; border-color: #1C4541; }
.bar button.ghost { background: transparent; color: #FAFBFB; border-color: #1C4541; }
.bar button.ghost:hover { background: #123C38; }
.content { max-width: 1240px; margin: 0 auto; padding: 20px 16px 110px; }
.panel { display: flex; flex-direction: column; gap: 16px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.scroll-x { overflow-x: auto; }

/* overview */
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.total { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.total span { color: var(--muted); font-size: 12px; }
.total b { font-size: 20px; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.alerts { margin: 0; padding-left: 18px; font: 12.5px var(--mono); color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

/* tables */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table input[type="text"] { width: 100%; min-width: 140px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.info { background: var(--accent-soft); color: var(--accent); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

/* switches */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { width: 36px; height: 20px; appearance: none; border-radius: 999px; background: var(--line); position: relative; padding: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.fields { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.fields input[type="number"] { width: 100px; }
.fields input[type="time"] { width: 120px; }
.dirty { box-shadow: inset 3px 0 0 var(--warn); }
.field-err { color: var(--bad); font-size: 12px; }

/* save bar */
.save-bar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 8; display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--warn); box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.save-bar span { color: var(--warn); font-weight: 600; }

/* captions editor */
.tpl-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .tpl-layout { grid-template-columns: minmax(0, 1fr); } }
.side-nav { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 70px; }
.side-nav button { text-align: left; border: 0; background: transparent; padding: 8px 10px; display: flex; justify-content: space-between; gap: 8px; }
.side-nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-nav small { color: var(--muted); }
.seg { display: inline-flex; flex-wrap: wrap; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.seg button { border: 0; padding: 6px 12px; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--accent-soft); color: var(--accent); }
.seg button small { font-weight: 400; margin-left: 4px; }
.ph-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ph-chip { font: 12.5px var(--mono); background: var(--ph); color: var(--accent); border: 0; border-radius: 6px; padding: 3px 8px; }
.variant { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 340px); gap: 14px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
@media (max-width: 980px) { .variant { grid-template-columns: minmax(0, 1fr); } }
.variant-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.variant-head b { color: var(--accent); font: 600 13px var(--mono); }
.variant .edit { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.poll-inputs { display: grid; grid-template-columns: 1fr; gap: 6px; }
.count { font-size: 12px; color: var(--muted); }
.count.over { color: var(--bad); }

/* Telegram channel preview */
.tg { background: var(--tg); border-radius: 12px; padding: 10px; color: #F5F5F5; font-size: 13.5px; }
.tg-msg { background: var(--tg-msg); border-radius: 12px 12px 12px 4px; overflow: hidden; }
.tg-msg img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #06201F; }
.tg-chan { font-weight: 700; color: #6AB3F3; padding: 8px 10px 0; font-size: 13px; }
.tg-text { padding: 6px 10px 10px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.tg-poll { padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.tg-poll .q { font-weight: 700; }
.tg-poll .o { border: 1px solid #2B3B4B; border-radius: 8px; padding: 6px 10px; }
.tg-poll .k { font-size: 12px; color: #7F91A4; }

/* card text */
.card-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 16px; align-items: start; }
@media (max-width: 900px) { .card-layout { grid-template-columns: minmax(0, 1fr); } }
.card-preview { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 8px; }
.card-preview img { width: 100%; aspect-ratio: 1; border-radius: 12px; background: #06201F; display: block; transition: opacity .2s; }
.card-preview img.loading { opacity: .55; }
.kind-row { display: grid; grid-template-columns: 140px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer; }
.kind-row.active { background: var(--accent-soft); }
@media (max-width: 640px) { .kind-row { grid-template-columns: minmax(0, 1fr); } }
.search-results { display: flex; flex-wrap: wrap; gap: 6px; }
.team-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.team-chip button { border: 0; background: transparent; padding: 0 6px; color: var(--muted); }

/* history */
.audit td { font-size: 13px; vertical-align: top; }
.audit pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: 12px var(--mono); color: var(--muted); max-height: 140px; overflow: auto; }

.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100% - 32px); }
@media (max-width: 640px) {
  .bar-actions { margin-left: 0; width: 100%; }
  .content { padding: 16px 12px 110px; }
}

/* read-only sections (account has "view") */
.ro button:not(.side-nav button):not(.seg button) { display: none !important; }
.ro-banner { padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.who { color: #A7C2BC; font-size: 13px; align-self: center; }

/* access tab */
.access-table select { min-width: 92px; }
.access-table td { white-space: nowrap; }
.access-table tr.master td { background: var(--accent-soft); }
