:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --border: #e2e8f0;
  --nav: #0c1629;
  --nav-soft: #16233a;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Noto Sans Thai", sans-serif; font-size: 15px; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(37, 99, 235, .25); outline-offset: 2px; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 999; padding: 10px 14px; background: #fff; color: var(--text); border-radius: 8px; }
.skip-link:focus { top: 12px; }
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 240px; padding: 24px 16px; background: var(--nav); color: #fff; display: flex; flex-direction: column; z-index: 10; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; padding: 0 8px 28px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(145deg, #3b82f6, #22c55e); font: 700 21px "Roboto Mono"; }
.brand strong, .brand small { display: block; }
.brand small { color: #94a3b8; font-size: 11px; letter-spacing: .08em; }
nav { display: grid; gap: 6px; }
.nav-item { min-height: 48px; width: 100%; padding: 0 13px; border: 0; border-radius: 10px; color: #aebbd0; background: transparent; display: flex; align-items: center; gap: 12px; text-align: left; transition: .2s ease; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: var(--nav-soft); box-shadow: inset 3px 0 #3b82f6; }
.nav-item svg, .button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-status { margin-top: auto; padding: 14px 10px; display: flex; gap: 10px; align-items: center; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-status strong, .sidebar-status small { display: block; }
.sidebar-status strong { font-size: 12px; }
.sidebar-status small { color: #8290a7; font-size: 10px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,.12); }
main { margin-left: 240px; min-height: 100vh; padding: 30px 36px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 26px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; letter-spacing: -.02em; }
h2 { margin-bottom: 3px; font-size: 17px; }
.eyebrow { margin-bottom: 3px; color: var(--primary); font: 600 10px "Roboto Mono"; letter-spacing: .14em; }
.button { min-height: 44px; border-radius: 9px; border: 1px solid var(--border); padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; transition: .2s; }
.button.secondary { background: var(--surface); color: var(--text); }
.button.secondary:hover { border-color: #aab7c8; background: var(--surface-soft); }
.button.primary { color: #fff; border-color: var(--primary); background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.view { display: none; }
.view.active { display: block; animation: fade-in .2s ease-out; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.metric-card { min-height: 130px; padding: 22px; display: flex; gap: 16px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric-card > div { min-width: 0; }
.metric-card span { color: var(--muted); font-size: 12px; }
.metric-card strong { display: block; margin: 2px 0 1px; font: 700 28px "Roboto Mono"; }
.metric-card small { color: #94a3b8; font-size: 10px; }
.metric-icon { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; }
.metric-icon svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.metric-icon.blue { color: #2563eb; background: #eff6ff; }.metric-icon.green { color: #16a34a; background: #f0fdf4; }.metric-icon.amber { color: #d97706; background: #fffbeb; }.metric-icon.violet { color: #7c3aed; background: #f5f3ff; }
.content-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .8fr); gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { min-height: 78px; padding: 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); }
.panel-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.text-button { border: 0; color: var(--primary); background: transparent; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 12px 18px; color: #758399; background: var(--surface-soft); border-bottom: 1px solid var(--border); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td { max-width: 300px; padding: 15px 18px; border-bottom: 1px solid #edf1f6; font-size: 12px; vertical-align: middle; }
tbody tr:hover { background: #fafcff; }
tbody tr:last-child td { border-bottom: 0; }
.sender { display: flex; align-items: center; gap: 10px; min-width: 135px; }
.avatar { width: 32px; height: 32px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 9px; background: #e9eff8; color: #31527d; font-weight: 700; }
.sender strong, .sender small { display: block; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender small { color: var(--muted); font: 9px "Roboto Mono"; }
.content-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-pill { display: inline-flex; padding: 3px 8px; border-radius: 99px; background: #f1f5f9; color: #475569; font-size: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 99px; font-size: 10px; font-weight: 600; white-space: nowrap; }
.status-pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-pill.acknowledged { color: #15803d; background: #f0fdf4; }.status-pill.pending { color: #a16207; background: #fefce8; }
.flow-panel { padding-bottom: 16px; }
.flow { padding: 20px 22px; }
.flow-node { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 11px; }
.flow-node > span { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: #fff; font: 700 16px "Roboto Mono"; }
.line-node { background: #06c755; }.hub-node { background: #2563eb; }.api-node { background: #7c3aed; }
.flow-node strong, .flow-node small { display: block; }
.flow-node strong { font-size: 12px; }.flow-node small { max-width: 160px; color: var(--muted); font-size: 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-node i { font-style: normal; font-size: 9px; font-weight: 600; }
.flow-node i.ok { color: var(--success); }.flow-node i.warn { color: var(--warning); }
.flow-connector { height: 35px; padding-left: 18px; }
.flow-connector span { display: block; width: 2px; height: 100%; background: repeating-linear-gradient(to bottom, #cbd5e1 0 4px, transparent 4px 8px); }
.toolbar { align-items: flex-end; }
.filters { display: flex; gap: 8px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 12px; width: 18px; fill: none; stroke: #94a3b8; stroke-width: 2; }
.search input { padding-left: 38px; width: 240px; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--text); background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; transition: border .2s, box-shadow .2s; }
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #94a3b8; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.mini-button { min-width: 38px; min-height: 38px; border: 0; border-radius: 7px; color: #53647c; background: transparent; }
.mini-button:hover { background: #edf2f7; }
.empty-state { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); }.empty-state p { margin-bottom: 0; }.hidden { display: none !important; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.admin-panel { margin-bottom: 18px; }
.admin-panel > label { max-width: 520px; }
.form-panel { padding-bottom: 24px; }
.form-panel > label, .form-panel > .field-row, .form-panel > .switch-row { margin: 18px 22px 0; }
label { display: block; color: #344258; font-size: 12px; font-weight: 600; }
label input, label textarea { margin-top: 7px; font-weight: 400; }
label small { display: block; margin-top: 5px; color: var(--muted); font-weight: 400; }
.section-badge { padding: 5px 9px; border-radius: 7px; font: 600 10px "Roboto Mono"; }.section-badge.line { color: #087e39; background: #eafbf1; }.section-badge.api { color: #6d28d9; background: #f3e8ff; }
.copy-field { display: flex; margin-top: 7px; }.copy-field input { margin-top: 0; border-radius: 8px 0 0 8px; background: #f8fafc; }.copy-field button { padding: 0 14px; color: var(--primary); background: #eff6ff; border: 1px solid #cbd5e1; border-left: 0; border-radius: 0 8px 8px 0; font-weight: 600; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.api-doc { margin: 18px 22px 0; padding: 16px; border-radius: 10px; background: #0f172a; color: #e2e8f0; }
.api-doc strong, .api-doc small, .api-doc code { display: block; }
.api-doc strong { margin: 10px 0 6px; font-size: 11px; }
.api-doc strong:first-child { margin-top: 0; }
.api-doc code { padding: 9px 10px; border-radius: 6px; background: #1e293b; color: #93c5fd; font: 11px "Roboto Mono"; overflow-wrap: anywhere; }
.api-doc small { margin-top: 7px; color: #94a3b8; }
.switch-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch-row strong, .switch-row small { display: block; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-row i { position: relative; width: 46px; height: 26px; flex: 0 0 auto; border-radius: 99px; background: #cbd5e1; transition: .2s; }
.switch-row i::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .2s; }
.switch-row input:checked + i { background: var(--primary); }.switch-row input:checked + i::after { transform: translateX(20px); }
.switch-row input:focus-visible + i { outline: 3px solid rgba(37,99,235,.25); outline-offset: 2px; }
.form-actions { min-height: 78px; margin-top: 18px; padding: 16px 22px; display: flex; align-items: center; justify-content: flex-end; gap: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
#settings-feedback { color: var(--success); font-size: 12px; }

.bot-connection-card {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.bot-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #06c755, #118c43);
  color: white;
  font-weight: 800;
  background-size: cover;
  background-position: center;
}

.bot-connection-card strong,
.bot-connection-card small {
  display: block;
}

.bot-connection-card small {
  margin-top: 2px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.connection-pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.connection-pill.connected {
  background: #ecfdf5;
  color: #047857;
  border-color: #bbf7d0;
}

.line-action-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
}

.line-connect,
.line-test {
  width: 100%;
  justify-content: center;
}

.line-connect {
  background: #06c755;
  color: white;
  border: 0;
}

.line-connect:hover {
  background: #05b34c;
}

@media (max-width: 720px) {
  .line-action-row {
    grid-template-columns: 1fr;
  }
}
dialog { width: min(540px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 24px 70px rgba(15,23,42,.3); }
dialog::backdrop { background: rgba(15,23,42,.55); backdrop-filter: blur(3px); }
.dialog-card { padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; gap: 16px; }
.dialog-heading h2 { font-size: 20px; }
.dialog-card > p { color: var(--muted); font-size: 13px; }
.icon-button { width: 44px; height: 44px; border: 0; border-radius: 9px; background: #f1f5f9; color: #64748b; font-size: 25px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.detail-card dl { display: grid; grid-template-columns: 120px 1fr; gap: 0; margin: 16px 0 0; font-size: 12px; }
.detail-card dt, .detail-card dd { margin: 0; padding: 11px 8px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.detail-card dt { color: var(--muted); }.detail-card dd { font-family: "Roboto Mono", "Noto Sans Thai"; white-space: pre-wrap; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; padding: 12px 16px; color: #fff; background: #172033; border-radius: 9px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }
@media (max-width: 1100px) { .metric-grid { grid-template-columns: 1fr 1fr; }.content-grid { grid-template-columns: 1fr; }.flow-panel { display: none; }.settings-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .sidebar { position: fixed; inset: auto 0 0 0; width: auto; height: 72px; padding: 8px 12px; flex-direction: row; justify-content: center; border-top: 1px solid #263650; }
  .brand, .sidebar-status { display: none; } nav { width: 100%; max-width: 440px; grid-template-columns: repeat(3, 1fr); }
  .nav-item { min-height: 56px; padding: 5px; flex-direction: column; justify-content: center; gap: 2px; font-size: 10px; }
  .nav-item.active { box-shadow: inset 0 -3px #3b82f6; }.nav-item svg { width: 19px; height: 19px; }
  main { margin-left: 0; padding: 22px 16px 96px; }.topbar { align-items: flex-start; }.topbar .button { width: 44px; padding: 0; font-size: 0; }
  .metric-grid { gap: 10px; }.metric-card { min-height: 120px; padding: 16px; gap: 10px; }.metric-icon { width: 32px; height: 32px; }.metric-card strong { font-size: 23px; }
  .panel-heading.toolbar { align-items: stretch; flex-direction: column; }.filters { flex-direction: column; }.search input { width: 100%; }
  .field-row { grid-template-columns: 1fr; }.form-actions { position: sticky; bottom: 80px; }
}
@media (max-width: 430px) { .metric-grid { grid-template-columns: 1fr; }.metric-card { min-height: 105px; }.panel-heading { padding: 16px; } th, td { padding-left: 14px; padding-right: 14px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
