/* =====================================================================
   รอบ 40: หน้าแจ้งเตือน Telegram ของร้าน (/telegram, TelegramPage.razor)
   - โครง .fit ของ fit.css: หัว (ชื่อ + ชิปสถานะบอท) อยู่กับที่ ส่วนที่เหลือเลื่อนใน .fit-body.scroll
   - .tg-grid  จอคอม: ซ้าย = รายการแชต (กว้าง) | ขวา = เชื่อมแชตใหม่ / ตั้งค่า / คำอธิบาย
               มือถือ: คอลัมน์เดียว เรียง เชื่อม → แชต → ตั้งค่า → คำอธิบาย
   - สีใช้ตัวแปรของธีมทั้งหมด (โหมดมืดทับตัวแปรเองใน dark.css)
   ===================================================================== */

@media screen {
  /* ---------- หัว ---------- */
  .tg-head-text { min-width: 0; }
  .tg-lead { margin: 4px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.5; max-width: 640px; }
  .tg-chips { gap: 8px; }
  .tg-chip {
    display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 12px; border-radius: 999px;
    background: var(--chip); color: var(--muted); font-size: .82rem; font-weight: 600; white-space: nowrap; text-decoration: none;
  }
  .tg-chip.bot { background: var(--brand-soft); color: var(--brand-strong, var(--brand)); }
  .tg-chip.bot:hover { background: rgba(var(--brand-rgb), .2); }
  .tg-chip.warn { background: var(--warn-soft); color: var(--warn-text, #7a5300); }
  .tg-chip.bad { background: var(--danger-soft); color: var(--danger); }

  /* ---------- โครงการ์ด ---------- */
  .tg-grid {
    display: grid; gap: 16px; align-items: start; min-width: 0;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
    grid-template-areas: "chats connect" "chats settings" "chats help" "sched sched";
    grid-template-rows: auto auto 1fr auto;
  }
  .tg-grid > * { min-width: 0; }
  .tg-connect { grid-area: connect; }
  .tg-chats { grid-area: chats; }
  .tg-settings { grid-area: settings; }
  .tg-help { grid-area: help; }
  .rsch-card { grid-area: sched; } /* รอบ 129b: รายงานที่ตั้งเวลาไว้ (report-schedule.css) */
  .tg-card { margin: 0; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
  .tg-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
  .tg-card-head h2 { margin: 0; font-size: 1.04rem; }
  .tg-muted { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }
  .tg-hint { display: block; color: var(--muted); font-size: .78rem; line-height: 1.45; font-weight: 400; }
  .tg-max { margin: 0; font-size: .88rem; }

  /* ---------- บอทยังไม่พร้อม ---------- */
  .tg-notready {
    max-width: 520px; margin: 24px auto 0; padding: 32px 24px; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
  }
  .tg-notready h2 { margin: 6px 0 0; font-size: 1.15rem; }
  .tg-notready p { margin: 0; color: var(--muted); }
  .tg-notready-ico {
    display: grid; place-items: center; width: 64px; height: 64px; border-radius: 20px;
    background: var(--chip); color: var(--muted);
  }

  /* ---------- เชื่อมแชตใหม่ ---------- */
  .tg-connect-btns { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .tg-big {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: 68px; padding: 12px 14px; text-align: left;
    border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
    font: inherit; cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s;
  }
  .tg-big:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-tint); box-shadow: 0 0 0 3px var(--brand-soft); }
  .tg-big:disabled { opacity: .55; cursor: not-allowed; }
  .tg-big-ico {
    flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px;
    background: var(--brand); color: var(--brand-ink);
  }
  .tg-big-ico.grp { background: var(--brand-soft); color: var(--brand-strong, var(--brand)); }
  .tg-big-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .tg-big-text strong { font-size: .98rem; font-weight: 700; }
  .tg-big-text small { color: var(--muted); font-size: .8rem; line-height: 1.4; }

  .tg-link { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .tg-link-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
  .tg-link-kind { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: .92rem; }
  .tg-link-kind svg { color: var(--brand); }
  .tg-timer {
    display: inline-flex; align-items: baseline; gap: 6px; min-height: 30px; padding: 3px 12px; border-radius: 999px;
    background: var(--brand-soft); color: var(--brand-strong, var(--brand)); font-size: .8rem; font-weight: 600;
  }
  .tg-timer strong { font-size: 1rem; font-weight: 800; letter-spacing: .02em; }
  .tg-timer.off { background: var(--danger-soft); color: var(--danger); align-items: center; }
  .tg-open { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; font-size: 1rem; font-weight: 700; text-decoration: none; }
  .tg-link-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

  .tg-steps { margin: 0; padding: 0; list-style: none; counter-reset: tgstep; display: flex; flex-direction: column; gap: 8px; }
  .tg-steps li { counter-increment: tgstep; display: flex; align-items: flex-start; gap: 10px; font-size: .9rem; line-height: 1.45; }
  .tg-steps li::before {
    content: counter(tgstep); flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 999px;
    background: var(--chip); color: var(--ink); font-size: .78rem; font-weight: 700;
  }
  .tg-url { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .78rem; }
  .tg-url input {
    width: 100%; min-width: 0; padding: 7px 10px; border: 1px dashed var(--line); border-radius: 10px;
    background: var(--bg); color: var(--ink); font: inherit; font-size: .8rem; font-family: var(--font-mono);
  }
  .tg-wait {
    display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-radius: 12px;
    background: var(--brand-tint); color: var(--muted); font-size: .86rem;
  }
  .tg-wait > span:nth-child(2) { flex: 1 1 auto; min-width: 0; }
  .tg-dot { flex: none; width: 10px; height: 10px; border-radius: 999px; background: var(--brand); animation: tg-pulse 1.2s ease-in-out infinite; }
  @keyframes tg-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }

  /* ---------- รายการแชต ---------- */
  .tg-empty {
    display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 36px 16px; text-align: center;
    border: 1px dashed var(--line); border-radius: 14px; color: var(--muted);
  }
  .tg-empty strong { color: var(--ink); font-size: 1rem; }
  .tg-empty p { margin: 0; font-size: .88rem; max-width: 420px; }
  .tg-empty-ico { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 18px; background: var(--brand-soft); color: var(--brand-strong, var(--brand)); }

  .tg-chat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); gap: 14px; align-items: start; }
  .tg-chat {
    display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 14px;
    border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  }
  .tg-chat.dirty { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
  .tg-chat.off .tg-chat-ico { background: var(--chip); color: var(--muted); }
  .tg-chat.off .tg-chat-title strong { color: var(--muted); }
  .tg-chat-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .tg-chat-ico {
    flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
    background: var(--brand-soft); color: var(--brand-strong, var(--brand));
  }
  .tg-chat-ico.grp { background: var(--brand); color: var(--brand-ink); }
  .tg-chat-title { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
  .tg-chat-title strong { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tg-chat-title small { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* สวิตช์เปิด/ปิด */
  .tg-switch { flex: none; position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .8rem; font-weight: 600; color: var(--muted); }
  .tg-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
  .tg-switch-ui {
    position: relative; width: 40px; height: 24px; border-radius: 999px; background: var(--line); transition: background .15s;
  }
  .tg-switch-ui::after {
    content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 999px;
    background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
  }
  .tg-switch input:checked + .tg-switch-ui { background: var(--ok); }
  .tg-switch input:checked + .tg-switch-ui::after { transform: translateX(16px); }
  .tg-switch input:focus-visible + .tg-switch-ui { outline: 2px solid var(--brand); outline-offset: 2px; }
  .tg-switch input:checked ~ .tg-switch-txt { color: var(--ok); }

  .tg-chat-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
  .tg-chat-meta div { min-width: 0; padding: 6px 10px; border-radius: 10px; background: var(--bg); }
  .tg-chat-meta dt { color: var(--muted); font-size: .72rem; }
  .tg-chat-meta dd { margin: 0; font-size: .84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tg-chat-err {
    margin: 0; padding: 8px 10px; border-radius: 10px; background: var(--danger-soft); color: var(--danger);
    font-size: .82rem; line-height: 1.45; overflow-wrap: anywhere;
  }

  .tg-chat-opts { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; }
  .tg-chat-opts .field { gap: 4px; font-size: .8rem; min-width: 0; }
  .tg-branch select { width: 100%; min-width: 0; }
  .tg-seg { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; border-radius: 12px; background: var(--chip); }
  .tg-seg button {
    min-height: 36px; min-width: 56px; padding: 0 12px; border: 0; border-radius: 9px; background: none;
    color: var(--muted); font: inherit; font-size: .86rem; font-weight: 600; cursor: pointer;
  }
  .tg-seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

  .tg-evgroups { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .tg-evgroup { margin: 0; padding: 0; border: 0; min-width: 0; }
  .tg-evgroup legend {
    display: flex; align-items: baseline; gap: 8px; padding: 0; margin-bottom: 6px;
    font-size: .8rem; font-weight: 700; color: var(--ink);
  }
  .tg-evgroup legend small { color: var(--muted); font-weight: 600; font-size: .74rem; }
  .tg-evs { display: flex; flex-wrap: wrap; gap: 6px; }
  .tg-ev {
    position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; max-width: 100%; padding: 4px 10px 4px 8px;
    border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted);
    font-size: .8rem; font-weight: 600; cursor: pointer; user-select: none;
  }
  .tg-ev input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); flex: none; }
  .tg-ev-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tg-ev.on { border-color: rgba(var(--brand-rgb), .45); background: var(--brand-tint); color: var(--ink); }
  .tg-ev:focus-within { box-shadow: 0 0 0 3px var(--brand-soft); }
  .tg-ev.locked { cursor: not-allowed; background: var(--bg); border-style: dashed; opacity: .85; }
  .tg-lock {
    display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border-radius: 999px;
    background: var(--warn-soft); color: var(--warn-text, #7a5300); font-size: .7rem; font-weight: 700; white-space: nowrap;
  }

  .tg-chat-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--line); }
  .tg-foot-gap { flex: 1 1 auto; }
  .tg-unlink { color: var(--danger); }
  .tg-unlink:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
  .tg-unsaved { color: var(--brand-strong, var(--brand)); font-size: .76rem; font-weight: 700; }

  /* ---------- ตั้งค่า ---------- */
  .tg-form { display: flex; flex-direction: column; gap: 12px; }
  .tg-form .field select, .tg-form .field input { width: 100%; }
  .tg-check { align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--bg); }
  .tg-check input { margin-top: 2px; flex: none; }
  .tg-check span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .tg-check strong { font-size: .9rem; font-weight: 600; }
  .tg-settings-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--line); }
  .tg-lastdaily { display: flex; flex-direction: column; min-width: 0; font-size: .76rem; color: var(--muted); }
  .tg-lastdaily strong { color: var(--ink); font-size: .86rem; }

  /* ---------- คำอธิบาย ---------- */
  .tg-help-group { margin: 2px 0 0; font-size: .82rem; font-weight: 700; color: var(--muted); text-transform: none; }
  .tg-help-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
  .tg-help-list li { display: flex; flex-direction: column; gap: 0; font-size: .84rem; line-height: 1.45; padding-left: 12px; border-left: 3px solid var(--brand-soft); }
  .tg-help-list li strong { font-weight: 600; }
  .tg-help-list li span { color: var(--muted); font-size: .8rem; }
  .tg-note { display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--bg); font-size: .84rem; line-height: 1.45; }
  .tg-note svg { flex: none; margin-top: 2px; color: var(--muted); }
  .tg-note.privacy { background: var(--ok-soft); color: var(--ok); }
  .tg-note.privacy svg { color: var(--ok); }

  /* ---------- แท็บเล็ต: คอลัมน์เดียว ---------- */
  @media (max-width: 1024px) {
    .tg-grid {
      grid-template-columns: minmax(0, 1fr);
      grid-template-areas: "connect" "chats" "settings" "help" "sched";
      grid-template-rows: none;
    }
    .tg-connect-btns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  /* ---------- มือถือ ---------- */
  @media (max-width: 760px) {
    .tg-lead { font-size: .84rem; }
    .tg-chips { flex-wrap: wrap; justify-content: flex-start; }
    .tg-grid { gap: 12px; }
    .tg-card { padding: 14px; }
    .tg-connect-btns { grid-template-columns: minmax(0, 1fr); }
    .tg-chat { padding: 12px; }
    .tg-chat-opts { grid-template-columns: minmax(0, 1fr); }
    .tg-seg { display: grid; }
    .tg-chat-foot .btn { min-height: 40px; }
    .tg-chat-foot .tg-unlink { order: 9; flex: 1 1 100%; }
    .tg-foot-gap { display: none; }
    .tg-chat-foot .btn:not(.tg-unlink) { flex: 1 1 0; }
    .tg-unsaved { flex: 1 1 100%; }
    .tg-toast { bottom: calc(146px + env(safe-area-inset-bottom)); }
  }
}
