:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c2024;
  --ink-soft: #5b6470;
  --ink-faint: #98a1ad;
  --line: #e3e6ea;
  --brand: #2b6cb0;
  --brand-dark: #245a92;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --warn: #8a6100;
  --warn-bg: #fff6e0;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans Thai", "Sarabun",
               "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.65;
}

/* ---------- แถบบน ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 24px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who { color: var(--ink-soft); font-size: 14px; }
.inline { display: inline; margin: 0; }
.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--brand); font: inherit; font-size: 14px; text-decoration: underline;
}

/* ---------- โครงหน้า ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 24px 64px; }
.center-card { display: flex; justify-content: center; padding: 56px 20px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card.wide { max-width: 520px; }

h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--ink-soft); margin: 0 0 22px; font-size: 15px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { margin: 0; }

/* ---------- ฟอร์ม ---------- */
label { display: block; font-size: 14px; font-weight: 600; margin: 16px 0 6px; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; padding: 11px 13px; font: inherit;
  border: 1px solid #ccd2d9; border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }

button, .btn {
  font: inherit; font-weight: 600; border-radius: 8px;
  padding: 11px 18px; cursor: pointer; border: 1px solid transparent;
  text-decoration: none; display: inline-block; text-align: center;
}
button.primary, .primary.btn { background: var(--brand); color: #fff; width: 100%; margin-top: 22px; }
.primary.btn { width: auto; margin: 0; }
button.primary:hover { background: var(--brand-dark); }
button.secondary {
  background: #fff; color: var(--ink); border-color: #ccd2d9; width: auto; margin: 0;
}
button.secondary:hover { background: #f7f8f9; }
.row-actions { display: flex; gap: 10px; margin: 18px 0; flex-wrap: wrap; }

.check { display: flex; align-items: center; gap: 9px; font-weight: 400; margin-top: 22px; }
.check input { width: auto; }

/* ---------- ข้อความแจ้งเตือน ---------- */
.alert { padding: 12px 14px; border-radius: 8px; font-size: 14.5px; margin-bottom: 18px; }
.alert.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5c6c0; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0dca8; }
.hint { color: var(--ink-soft); font-size: 13.5px; margin: 20px 0 0; }
.hint a, a { color: var(--brand); }

/* ---------- 2FA ---------- */
.steps { color: var(--ink-soft); font-size: 14.5px; padding-inline-start: 22px; margin: 0 0 20px; }
.steps li { margin-bottom: 6px; }
.qr-box { display: flex; justify-content: center; padding: 16px; background: #fff;
          border: 1px solid var(--line); border-radius: 8px; }
.qr-box img { display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
.big-code { font-size: 26px; letter-spacing: 7px; text-align: center; }
.secret { font-size: 17px; letter-spacing: 2px; background: #f4f5f7;
          padding: 10px 12px; border-radius: 6px; user-select: all; }
.manual { margin: 16px 0 4px; font-size: 14px; color: var(--ink-soft); }
.manual summary { cursor: pointer; color: var(--brand); }

.codes { list-style: none; padding: 16px; margin: 16px 0; background: #f4f5f7;
         border-radius: 8px; columns: 2; font-size: 15.5px; }
.codes li { margin-bottom: 6px; break-inside: avoid; }

/* ---------- ภาพรวม ---------- */
.bot-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.bot-card { text-decoration: none; color: inherit; display: block; }
.bot-card:hover { border-color: var(--brand); }
.bot-name { font-weight: 700; }
.bot-username { color: var(--ink-soft); font-size: 14px; }
.empty { text-align: center; color: var(--ink-soft); }
.empty-title { font-weight: 700; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

@media print {
  .topbar, .row-actions, form, .alert.warn { display: none; }
  body { background: #fff; }
  .card { border: 0; }
}

/* ---------- ขั้นที่ 2: บอท ---------- */
.crumb { margin: 0 0 14px; font-size: 14px; }
.row-actions.tight { margin: 0; }
.faint { color: var(--ink-faint); font-style: normal; }
.field-hint { color: var(--ink-soft); font-size: 13.5px; margin: 6px 0 0; }
.field-hint code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; }
.alert.good { background: #e8f5ec; color: #22643c; border: 1px solid #b9dfc8; }
.alert.small { font-size: 13.5px; }
.big-alert { font-size: 15px; margin-bottom: 20px; }

h2 { font-size: 17px; margin: 0 0 4px; }
.card + .card { margin-top: 16px; }
.form-card { max-width: 640px; }

select {
  width: 100%; padding: 11px 13px; font: inherit;
  border: 1px solid #ccd2d9; border-radius: 8px; background: #fff; color: var(--ink);
}
select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

button.danger { background: var(--danger); color: #fff; width: auto; margin-top: 18px; }
button.danger:hover { background: #a33226; }

/* การ์ดบอท */
.bot-card { display: flex; flex-direction: column; gap: 8px; padding: 20px; }
.bot-head { display: flex; align-items: center; gap: 11px; }
.bot-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--bot-color, var(--brand)); flex: none;
}
.inline-dot { display: inline-block; margin-inline-end: 6px; }
.bot-meta { color: var(--ink-soft); font-size: 13.5px; }
.bot-status { font-size: 14.5px; font-weight: 600; margin-top: 2px; }
.bot-status.ok { color: #22643c; }
.bot-status.incomplete { color: var(--warn); }
.bot-status.down { color: var(--danger); }
.bot-status.unknown { color: var(--ink-faint); }
.bot-missing { color: var(--ink-soft); font-size: 13px; }
.bot-card.state-down { border-color: #f0b6ae; }

/* กล่องสถานะหน้าสรุป */
.status-box { border-inline-start: 4px solid var(--line); }
.status-box.ok { border-inline-start-color: #2f855a; }
.status-box.incomplete { border-inline-start-color: #d69e2e; }
.status-box.down { border-inline-start-color: var(--danger); }
.status-box.unknown { border-inline-start-color: var(--ink-faint); }
.status-line { font-weight: 700; font-size: 16px; }
.status-box p { margin: 6px 0 0; color: var(--ink-soft); font-size: 14.5px; }

/* ตารางคู่ค่า */
.kv { display: grid; grid-template-columns: 210px 1fr; gap: 8px 18px; margin: 14px 0 0; }
.kv dt { color: var(--ink-soft); font-size: 14px; }
.kv dd { margin: 0; }

.log { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.log th { text-align: start; color: var(--ink-soft); font-weight: 600; padding: 6px 10px 6px 0; }
.log td { padding: 6px 10px 6px 0; border-top: 1px solid var(--line); }

/* เลือกสี */
.swatches { display: flex; gap: 10px; margin: 14px 0 0; flex-wrap: wrap; }
.swatch { margin: 0; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; }
.swatch span {
  display: block; width: 30px; height: 30px; border-radius: 50%;
  background: var(--c); border: 2px solid transparent; box-shadow: 0 0 0 2px transparent;
}
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.swatch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 3px; }

/* การกระทำที่ย้อนกลับไม่ได้ */
.danger-zone { border-color: #f0b6ae; background: #fffbfa; max-width: 640px; }
.danger-list { list-style: none; padding: 0; margin: 14px 0 0; }
.danger-list li {
  padding: 12px 0; border-top: 1px solid #f2d7d2;
  display: grid; gap: 3px;
}
.danger-list span { color: var(--ink-soft); font-size: 13.5px; }
.danger-list a { font-size: 14px; }
.bot-status.bad_token { color: var(--danger); }
.bot-card.state-bad_token { border-color: #f0b6ae; }
.status-box.bad_token { border-inline-start-color: var(--danger); }

/* ---------- ขั้นที่ 3: แก้ข้อมูลบอท ---------- */
.head-username { font-weight: 400; color: var(--ink-soft); font-size: 15px; margin-inline-start: 8px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 4px 0 22px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 14px; text-decoration: none; color: var(--ink-soft);
  border-bottom: 2px solid transparent; font-size: 14.5px; font-weight: 600;
}
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 22px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

.field { margin-bottom: 20px; }
.field label { display: flex; justify-content: space-between; align-items: baseline; }
.counter { font-weight: 400; font-size: 12.5px; color: var(--ink-faint); }
.counter.near { color: var(--warn); font-weight: 600; }
textarea {
  width: 100%; padding: 11px 13px; font: inherit; line-height: 1.6;
  border: 1px solid #ccd2d9; border-radius: 8px; background: #fff; color: var(--ink);
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
h2.spaced { margin-top: 28px; }
.warn-text { color: var(--danger); font-weight: 600; }
.drift { margin: 8px 0 8px; padding-inline-start: 20px; font-size: 13.5px; }

/* จำลองหน้าจอ Telegram */
.preview-col { position: sticky; top: 20px; }
.preview-title { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 8px; font-weight: 600; }
.tg-frame {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; margin-bottom: 16px;
}
.tg-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #f7f8fa; border-bottom: 1px solid var(--line); }
.tg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--bot-color, var(--brand)); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.tg-avatar.big { width: 64px; height: 64px; font-size: 26px; margin-bottom: 10px; }
.tg-bar-name { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.tg-body { padding: 18px 14px; background: #e9edf2; min-height: 150px;
           display: flex; flex-direction: column; justify-content: center; }
.tg-label { font-size: 11.5px; color: var(--ink-faint); text-align: center; margin: 0 0 10px; }
.tg-desc {
  background: #fff; border-radius: 10px; padding: 12px 14px; font-size: 14px;
  white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 12px;
}
.tg-start {
  background: #fff; border-radius: 8px; padding: 11px; text-align: center;
  font-weight: 700; color: var(--brand); letter-spacing: 1px; font-size: 14px;
}
.tg-profile { padding: 22px 16px; text-align: center; }
.tg-profile-name { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.tg-profile-user { color: var(--ink-soft); font-size: 13.5px; margin-bottom: 8px; }
.tg-short { font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }

.tg-menu { background: #fff; padding: 6px 0; min-height: 60px; }
.tg-menu-row { display: flex; gap: 10px; padding: 8px 14px; font-size: 14px; align-items: baseline; }
.tg-menu-row + .tg-menu-row { border-top: 1px solid #f0f2f4; }
.tg-cmd { color: var(--brand); font-weight: 600; flex: none; }
.tg-cmd-desc { color: var(--ink-soft); font-size: 13px; overflow-wrap: anywhere; }
.tg-input-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #f7f8fa; border-top: 1px solid var(--line); }
.tg-menu-btn { color: var(--ink-soft); font-size: 17px; }
.tg-input { color: var(--ink-faint); font-size: 14px; }

/* แถวคำสั่ง */
.cmd-list { margin: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.cmd-row { display: flex; align-items: center; gap: 7px; }
.cmd-row.dragging { opacity: .4; }
.drag { cursor: grab; color: var(--ink-faint); user-select: none; padding: 0 2px; }
.slash { color: var(--ink-faint); }
.cmd-name { flex: 0 0 140px; }
.cmd-desc { flex: 1 1 auto; min-width: 0; }
.cmd-row input.bad { border-color: var(--danger); background: #fffaf9; }
.row-del {
  background: none; border: 0; color: var(--ink-faint); cursor: pointer;
  font-size: 15px; padding: 6px 8px; width: auto; margin: 0;
}
.row-del:hover { color: var(--danger); }

.radio { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 12px 0 0; }
.radio input { margin-top: 5px; width: auto; flex: none; }
.radio span { font-size: 14.5px; }

/* กล่อง "ยังไม่ได้ตั้ง" */
.todo-box { border-color: #f0dca8; background: #fffdf7; }
.todo-box.all-done { border-color: #b9dfc8; background: #f6fbf8; }
.todo-rows { list-style: none; padding: 0; margin: 14px 0 0; }
.todo-rows li {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 0; border-top: 1px solid #f0e6cf;
}
.todo-row-label { font-weight: 600; font-size: 14.5px; }
.todo-row-impact { color: var(--ink-soft); font-size: 13px; }
.btn.small { padding: 7px 13px; font-size: 13.5px; flex: none; }

/* เช็กลิสต์ botfather */
.todo-list { display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
details.todo { padding: 0; }
details.todo summary {
  display: flex; align-items: center; gap: 10px; padding: 15px 18px;
  cursor: pointer; font-weight: 600; list-style: none;
}
details.todo summary::-webkit-details-marker { display: none; }
details.todo[open] summary { border-bottom: 1px solid var(--line); }
details.todo > *:not(summary) { padding-inline: 18px; }
details.todo > *:last-child { padding-bottom: 16px; }
.todo-check { color: var(--ink-faint); font-size: 15px; }
.todo.is-done .todo-check { color: #2f855a; }
.todo.is-done .todo-title { color: var(--ink-soft); }
.todo-title { flex: 1 1 auto; }
.todo-why { color: var(--ink-soft); font-size: 14px; margin: 14px 0 0; }
.pill {
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: #eef0f3; color: var(--ink-soft); flex: none;
}
.pill.on { background: #e8f5ec; color: #22643c; }
.pill.off { background: #f1f2f4; color: var(--ink-soft); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.log-list { list-style: none; padding: 0; margin: 12px 0 0; }
.log-list li { padding: 9px 0; border-top: 1px solid var(--line); }
.log-list li:first-child { border-top: 0; }
.log-what { font-size: 14px; font-weight: 600; }
.log-who { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- หน้าจัดการเมนูรูป ---------- */
.explain p { margin: 0 0 8px; font-size: 14.5px; }
.explain p:last-child { margin-bottom: 0; }

.tile-list { display: flex; flex-direction: column; gap: 12px; margin: 14px 0; }
.tile-row { display: flex; gap: 12px; align-items: flex-start; }
.tile-thumb {
  position: relative; width: 78px; height: 78px; flex: none; border-radius: 10px;
  overflow: hidden; background: var(--bot-color, #e6e9ed); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tile-thumb.empty { background: #eef0f3; }
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tile-thumb span { font-size: 11.5px; color: var(--ink-faint); }
.tile-thumb input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.thumb-del {
  position: absolute; top: 3px; inset-inline-end: 3px; z-index: 2;
  width: 20px; height: 20px; padding: 0; margin: 0; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; border: 0; font-size: 11px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tile-fields { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.tile-action { display: flex; gap: 7px; }
.tile-action select { flex: 0 0 130px; }
.tile-action input { flex: 1 1 auto; min-width: 0; }
#tile-add { margin-inline-end: 10px; }
#tile-add:disabled { opacity: .5; cursor: not-allowed; }

/* ตัวอย่างหน้าเมนูรูป */
.mini-preview { padding: 14px; background: #fff; }
.mini-head { text-align: center; margin-bottom: 12px; }
.mini-title { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.mini-sub { font-size: 12.5px; color: var(--ink-soft); overflow-wrap: anywhere; }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini-tile {
  position: relative; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden;
  background: var(--bot-color, #2b6cb0); display: flex;
  align-items: flex-end; justify-content: center;
}
.mini-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mini-tile span {
  position: relative; z-index: 1; color: #fff; font-size: 11.5px; font-weight: 700;
  padding: 14px 6px 7px; text-align: center; width: 100%;
  background: linear-gradient(to top, rgba(0,0,0,.65), rgba(0,0,0,0));
  overflow-wrap: anywhere;
}
