/* =====================================================================
   app.css — LINE LIFF Dashboard (mobile-first)
   ===================================================================== */
:root {
  --brand:        #06c755;
  --brand-dark:   #04a548;
  --bg:           #f4f5f7;
  --surface:      #ffffff;
  --surface-2:    #f0f1f4;
  --text:         #1c1e21;
  --text-soft:    #616772;
  --border:       #e2e4e9;
  --danger:       #d93838;
  --ok:           #1a8f4c;
  --radius:       14px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --maxw:         520px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #17181c;
    --surface:   #202227;
    --surface-2: #2a2d33;
    --text:      #e9eaec;
    --text-soft: #a0a4ad;
    --border:    #34373e;
    --shadow:    0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun",
               "Helvetica Neue", Arial, "Noto Sans Thai", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top, 0));
  padding-top: max(14px, env(safe-area-inset-top, 0));
  background: var(--brand);
  color: #fff;
}
.app-bar__title { font-weight: 700; font-size: 1.05rem; }
.app-bar__avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.6); }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 16px 40px;
}
.app-foot {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom, 0));
  color: var(--text-soft);
  font-size: .8rem;
  text-align: center;
}

/* ---------- welcome ---------- */
.welcome {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.welcome__pic { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.welcome__hi { margin: 0; color: var(--text-soft); font-size: .85rem; }
.welcome__name { margin: 2px 0 0; font-size: 1.25rem; }

.section-title { margin: 26px 4px 12px; font-size: .95rem; color: var(--text-soft); font-weight: 600; }

/* ---- modal (native <dialog>) ---- */
.modal {
  border: none; padding: 0; background: transparent;
  max-width: 360px; width: calc(100% - 40px);
  color: var(--text);
}
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal__box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal__icon { font-size: 2.4rem; line-height: 1; margin-bottom: 8px; }
.modal__title { margin: 0 0 8px; font-size: 1.1rem; }
.modal__body { margin: 0 0 18px; color: var(--text-soft); font-size: .9rem; }
.modal__actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- menu grid ---------- */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.menu-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.menu-card:active { transform: scale(.98); border-color: var(--brand); }
.menu-card__icon { font-size: 1.7rem; line-height: 1; }
.menu-card__name { font-weight: 700; }
.menu-card__desc { font-size: .8rem; color: var(--text-soft); }

/* ---------- identity block ---------- */
.line-identity {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.line-identity__pic {
  width: 60px; height: 60px; border-radius: 50%; object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-size: 1.8rem;
}
.line-identity__pic--empty { border: 1px solid var(--border); }
.line-identity__meta { display: flex; flex-direction: column; }
.line-identity__label { font-size: .78rem; color: var(--text-soft); }
.line-identity__name { font-weight: 700; font-size: 1.1rem; }

.hint { color: var(--text-soft); font-size: .9rem; margin: 0 4px 14px; }

/* ---- guard / verify ---- */
.shield { width: 1em; height: 1em; vertical-align: -0.13em; }
.shield path:first-child { fill: var(--text-soft); }
.shield--ok path:first-child { fill: var(--brand); }
.shield--danger path:first-child { fill: var(--danger); }
.shield__check { stroke: #fff; }
.line-identity__name .shield,
.welcome__name .shield { width: 1.05em; height: 1.05em; margin-left: 4px; }

.verify-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: .78rem; font-weight: 600; margin-left: 6px;
}
.verify-badge--ok { color: var(--brand-dark); }
.verify-badge--danger { color: var(--danger); }
.verify-badge--ok .verify-badge__no,
.verify-badge--danger .verify-badge__ok { display: none; }
.verify-badge__ok, .verify-badge__no { display: inline-flex; align-items: center; gap: 3px; }
.verify-row { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.verify-pin { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.verify-pin input {
  width: 130px; font: inherit; letter-spacing: .18em; text-align: center;
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text);
}
.verify-msg { font-size: .8rem; color: var(--text-soft); }
.verify-msg--ok { color: var(--ok); }
.verify-msg--err { color: var(--danger); }
.btn-link {
  background: none; border: none; color: var(--brand-dark);
  padding: 6px 4px; text-decoration: underline; cursor: pointer; font: inherit;
}
.btn-link:disabled { color: var(--text-soft); text-decoration: none; cursor: default; }
.crumb { color: var(--text-soft); font-size: .85rem; margin: 0 4px 14px; }
.crumb a { color: var(--brand-dark); text-decoration: none; }

/* ---------- form ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: .9rem; font-weight: 600; }
.field__label b { color: var(--danger); }
.field input {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.field--invalid input { border-color: var(--danger); }
.field__err { color: var(--danger); font-size: .8rem; min-height: 1em; }

.form__msg { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.form__msg--error { background: rgba(217,56,56,.12); color: var(--danger); }
.form__msg--ok { background: rgba(26,143,76,.14); color: var(--ok); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  font: inherit; font-weight: 700;
  padding: 13px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, opacity .12s ease;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); margin-top: 4px; }
.btn.is-loading::after {
  content: ""; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.5); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}

/* ---------- empty states ---------- */
.empty, .empty-state { color: var(--text-soft); text-align: center; }
.empty-state { padding: 48px 16px; }
.empty-state__icon { font-size: 2.6rem; margin-bottom: 8px; }

/* ---------- job list ---------- */
.job-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.job-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  box-shadow: var(--shadow);
}
.job-item__title { font-weight: 600; }
.job-item__status { font-size: .78rem; align-self: start; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); }
.job-item__due { grid-column: 1 / -1; font-size: .8rem; color: var(--text-soft); }

/* ---------- auth bootstrap ---------- */
.screen-center {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.loader-box { text-align: center; max-width: 320px; }
.spinner {
  width: 38px; height: 38px; margin: 0 auto 16px;
  border: 3px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.error-text { color: var(--danger); font-size: .88rem; word-break: break-word; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   bots.php — tabs / chat / rules / broadcast
   ===================================================================== */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.btn-sm { padding: 8px 12px; font-size: .85rem; border-radius: 9px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  font: inherit; font-weight: 600; color: var(--text-soft);
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 10px 12px; cursor: pointer;
}
.tab.is-active { color: var(--brand-dark); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ---- chat ---- */
.chat { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .chat { grid-template-columns: 300px 1fr; } }

.chat__list {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 62vh; overflow-y: auto;
}
.thread {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--border);
  padding: 10px 12px; cursor: pointer; color: inherit; font: inherit;
}
.thread:hover { background: var(--surface-2); }
.thread.is-active { background: var(--surface-2); }
.thread__pic { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none;
  display: flex; align-items: center; justify-content: center; background: var(--surface-2); }
.thread__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.thread__name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.thread__last { color: var(--text-soft); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread__time { color: var(--text-soft); font-size: .72rem; flex: none; }
.badge { background: var(--danger); color: #fff; font-size: .7rem; border-radius: 999px; padding: 0 6px; }

.chat__room {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 50vh; max-height: 62vh;
}
.chat__placeholder { margin: auto; color: var(--text-soft); padding: 32px; }
.room__head { padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700; }
.room__body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 8px 11px; border-radius: 12px; font-size: .9rem; }
.msg__meta { font-size: .68rem; color: var(--text-soft); margin-top: 3px; }
.msg--in { align-self: flex-start; background: var(--surface-2); }
.msg--out { align-self: flex-end; background: var(--brand); color: #fff; }
.msg--out .msg__meta { color: rgba(255,255,255,.8); }
.msg--err { outline: 1px solid var(--danger); }
.room__compose { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.room__compose textarea {
  flex: 1; font: inherit; resize: none; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.room__err { color: var(--danger); font-size: .8rem; padding: 0 12px 8px; }

/* ---- rules ---- */
.rule-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.rule-card.is-off { opacity: .6; }
.rule-card__top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.rule-card__order { color: var(--text-soft); font-size: .8rem; }
.rule-card__cond { font-size: .85rem; margin-bottom: 6px; }
.rule-card__cond code, .rule-card__reply { }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: .82rem; }
.rule-card__reply { color: var(--text-soft); font-size: .88rem; white-space: pre-wrap; }
.rule-actions { display: flex; gap: 6px; margin-top: 10px; }
.rule-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 10px; }
.rule-flags { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; margin: 8px 0; }
.rule-card--edit textarea, .rule-card--edit input, .rule-card--edit select {
  font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface); color: var(--text);
}

.tag { display: inline-block; background: var(--surface-2); color: var(--text-soft);
  font-size: .72rem; padding: 2px 7px; border-radius: 999px; }
.tag--default { background: rgba(6,199,85,.15); color: var(--brand-dark); }
.tag--off { background: rgba(217,56,56,.14); color: var(--danger); }

/* ---- broadcast ---- */
.form select, .form textarea {
  font: inherit; width: 100%; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text);
}
.bc-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; }
.bc-item__top { display: flex; align-items: center; gap: 8px; font-size: .78rem; margin-bottom: 6px; }
.bc-item__time { color: var(--text-soft); margin-left: auto; }
.bc-item__text { font-size: .9rem; white-space: pre-wrap; }
.bc-item__err { color: var(--danger); font-size: .8rem; margin-top: 4px; }
.bc-item__status.status--DONE { color: var(--ok); }
.bc-item__status.status--ERROR { color: var(--danger); }
.bc-item__status.status--PENDING, .bc-item__status.status--SENDING { color: var(--text-soft); }

/* =====================================================================
   notify.php — Flex Message backoffice
   ===================================================================== */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.seg__btn {
  font: inherit; padding: 8px 16px; background: var(--surface); color: var(--text-soft);
  border: none; cursor: pointer;
}
.seg__btn.is-active { background: var(--brand); color: #fff; font-weight: 600; }

.flex-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

.flex-preview {
  margin-top: 16px; padding: 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.fp-alt { font-size: .78rem; color: var(--text-soft); margin-bottom: 8px; }
.fp-note { font-size: .85rem; }
.fp-bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; max-width: 300px; }
.fp-bubble img { width: 100%; display: block; max-height: 180px; object-fit: cover; }
.fp-body { padding: 12px; }
.fp-h { margin: 0 0 4px; font-weight: 700; }
.fp-b { margin: 0 0 4px; font-size: .85rem; color: var(--text-soft); white-space: pre-wrap; }
.fp-btn { margin-top: 8px; text-align: center; background: var(--brand); color: #fff; border-radius: 8px; padding: 8px; font-size: .85rem; font-weight: 600; }

.flex-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.flex-item__top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.flex-item__tgt { font-size: .78rem; color: var(--text-soft); }
.flex-item__alt { font-size: .9rem; }
.flex-item__when { font-size: .78rem; color: var(--text-soft); margin-top: 3px; }
.flex-item__err { font-size: .8rem; color: var(--danger); margin-top: 3px; }

.tag--draft { background: var(--surface-2); color: var(--text-soft); }
.tag--scheduled { background: rgba(6,199,85,.15); color: var(--brand-dark); }
.tag--sending { background: rgba(6,199,85,.15); color: var(--brand-dark); }
.tag--sent { background: rgba(26,143,76,.15); color: var(--ok); }
.tag--error { background: rgba(217,56,56,.14); color: var(--danger); }
.tag--cancelled { background: var(--surface-2); color: var(--text-soft); text-decoration: line-through; }
