:root {
  color-scheme: light;
  --navy: #102a56;
  --blue: #155eef;
  --blue-soft: #eaf1ff;
  --ink: #172b4d;
  --muted: #64748b;
  --line: #dbe5f2;
  --canvas: #f4f7fb;
  --card: #ffffff;
  --green: #067647;
  --green-bg: #ecfdf3;
  --amber: #a15c07;
  --amber-bg: #fff8e7;
  --red: #b42318;
  --red-bg: #fff1f1;
  font-family: "Noto Sans Thai", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.boot-screen, .auth-page { min-height: 100vh; display: grid; place-content: center; text-align: center; gap: 10px; }
.spinner { width: 26px; height: 26px; border: 3px solid #cbd8ec; border-top-color: var(--blue); border-radius: 50%; margin: auto; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-page { padding: 24px; background: radial-gradient(circle at 15% 10%, #e6f0ff, transparent 42%), #f7faff; }
.auth-card { width: min(100%, 420px); text-align: left; padding: 34px; border: 1px solid var(--line); border-radius: 20px; background: white; box-shadow: 0 20px 55px rgba(29, 60, 118, .12); }
.brand-mark { width: 44px; height: 44px; display: grid; place-content: center; color: white; background: var(--blue); font-weight: 800; border-radius: 13px; }
h1 { margin: 15px 0 4px; font-size: 25px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0; font-size: 16px; }
p { margin: 0; }
.subtle, .hint { color: var(--muted); font-size: 14px; line-height: 1.55; }
.auth-card form, .form-grid { display: grid; gap: 14px; margin-top: 24px; }
label { display: grid; gap: 6px; color: #344764; font-size: 14px; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #c9d7e9; color: var(--ink); background: white; border-radius: 9px; padding: 10px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #dfeaff; }
textarea { min-height: 88px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 39px; border: 1px solid transparent; border-radius: 9px; padding: 8px 13px; font-weight: 700; transition: .15s ease; }
.btn:hover { filter: brightness(.97); }
.btn-primary { color: white; background: var(--blue); }
.btn-secondary { color: #26436d; background: white; border-color: #bcd0e9; }
.btn-danger { color: var(--red); background: white; border-color: #f6b9b4; }
.btn-small { min-height: 32px; padding: 5px 9px; font-size: 13px; }
.text-button { padding: 0; color: var(--blue); border: 0; background: none; font-weight: 700; }
.error { color: var(--red); background: var(--red-bg); border-radius: 8px; padding: 10px; font-size: 14px; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 242px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 22px 14px; color: #dce8fb; background: var(--navy); }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 10px; color: white; font-weight: 800; }
.side-brand .brand-mark { width: 34px; height: 34px; font-size: 12px; background: #3475f7; border-radius: 10px; }
.portal-label { padding: 0 10px; color: #a8bbdc; font-size: 12px; }
.nav { display: grid; gap: 5px; }
.nav button { width: 100%; padding: 10px 12px; color: #cfddf4; text-align: left; border: 0; border-radius: 8px; background: transparent; }
.nav button.active, .nav button:hover { color: white; background: #214372; }
.side-user { margin-top: auto; display: grid; gap: 3px; padding: 12px 10px; border-top: 1px solid #2b4c7a; }
.side-user strong { color: white; }
.side-user span { color: #a8bbdc; font-size: 12px; }
.main-content { min-width: 0; padding: 30px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.page-head p { margin-top: 5px; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: 13px; background: var(--card); box-shadow: 0 2px 8px rgba(27, 66, 125, .03); }
.card-pad { padding: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stat-card { padding: 20px; }
.stat-card .number { margin-top: 8px; font-size: 32px; font-weight: 800; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .75fr); gap: 18px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(310px, .9fr); gap: 18px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 15px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 12px 9px; border-bottom: 1px solid #edf1f7; text-align: left; vertical-align: middle; }
.data-table th { color: #62718a; font-size: 12px; font-weight: 750; }
.data-table tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { color: var(--green); background: var(--green-bg); }
.badge-blue { color: var(--blue); background: var(--blue-soft); }
.badge-amber { color: var(--amber); background: var(--amber-bg); }
.badge-gray { color: #52637a; background: #edf2f7; }
.badge-red { color: var(--red); background: var(--red-bg); }
.line-account-list { display: grid; gap: 12px; }
.line-account { padding: 16px; display: grid; gap: 12px; }
.line-account-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.line-account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.webhook-url { overflow: auto; padding: 8px 10px; color: #29466f; background: #f2f6fb; border: 1px solid #dce6f3; border-radius: 7px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: nowrap; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.connection-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px solid #e8eef7; padding-top: 13px; }
.connection-form .wide { grid-column: 1 / -1; }
.assignment-list { display: grid; gap: 7px; margin: 8px 0 12px; }
.check-row { display: flex; align-items: center; gap: 8px; padding: 7px; border: 1px solid #e4ebf5; border-radius: 7px; }
.check-row input { width: auto; }
.inbox { height: calc(100vh - 147px); min-height: 540px; display: grid; grid-template-columns: 330px minmax(0, 1fr); overflow: hidden; }
.conversation-pane { overflow: auto; border-right: 1px solid var(--line); }
.inbox-tools { display: grid; gap: 9px; padding: 14px; border-bottom: 1px solid var(--line); }
.conversation-row { width: 100%; display: grid; gap: 4px; padding: 13px 15px; color: var(--ink); text-align: left; border: 0; border-bottom: 1px solid #edf1f6; background: white; }
.conversation-row:hover, .conversation-row.active { background: #edf4ff; }
.conversation-row-top { display: flex; justify-content: space-between; gap: 10px; }
.conversation-row small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread { min-width: 19px; padding: 1px 6px; color: white; text-align: center; background: var(--blue); border-radius: 99px; font-size: 11px; }
.chat-pane { min-width: 0; display: grid; grid-template-rows: auto 1fr auto; background: #f8fbff; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); background: white; }
.chat-messages { display: grid; align-content: start; gap: 11px; overflow: auto; padding: 20px; }
.bubble-row { display: flex; }
.bubble-row.outbound { justify-content: flex-end; }
.bubble-row.internal { justify-content: center; }
.bubble { max-width: min(80%, 580px); padding: 10px 12px; border-radius: 12px; background: white; box-shadow: 0 1px 4px rgba(25, 58, 107, .08); line-height: 1.45; }
.bubble-row.outbound .bubble { color: white; background: var(--blue); }
.bubble-row.internal .bubble { max-width: 90%; color: #655318; background: #fff7d8; font-size: 13px; }
.bubble-meta { margin-top: 5px; opacity: .72; font-size: 11px; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: white; }
.composer textarea { min-height: 42px; max-height: 140px; }
.empty { padding: 36px 20px; color: var(--muted); text-align: center; }
.toast-area { position: fixed; right: 20px; bottom: 20px; z-index: 10; display: grid; gap: 8px; max-width: min(390px, calc(100vw - 40px)); }
.toast { padding: 12px 15px; color: #17423a; border: 1px solid #aee6cf; border-radius: 10px; background: white; box-shadow: 0 12px 26px rgba(14, 63, 88, .16); }
.toast.error { color: var(--red); border-color: #f2aaa5; }
.hidden { display: none !important; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .portal-label, .side-user { display: none; }
  .nav { display: flex; gap: 4px; overflow: auto; }
  .nav button { width: auto; white-space: nowrap; }
  .main-content { padding: 18px; }
  .stat-grid, .grid-2, .split { grid-template-columns: 1fr; }
  .inbox { height: auto; min-height: 600px; grid-template-columns: 1fr; }
  .conversation-pane { max-height: 310px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-pane { min-height: 460px; }
  .inline-form, .connection-form { grid-template-columns: 1fr; }
  .connection-form .wide { grid-column: auto; }
}
