:root {
  --brand-primary: #3C50E0;
  --brand-secondary: #80CAEE;
}

.bg-brand { background-color: var(--brand-primary); }
.text-brand { color: var(--brand-primary); }
.shadow-brand\/30 { --tw-shadow-color: color-mix(in srgb, var(--brand-primary) 30%, transparent); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border-radius: 0.5rem;
  padding: 0.45rem 0.6rem;
  color: #94a3b8;
  font-weight: 600;
  line-height: 1.25;
  transition: 0.15s ease;
}
.nav-link > i {
  width: 1.1rem;
  text-align: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: color 0.15s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--brand-primary); color: #fff; }
.nav-link.active > i { color: #fff !important; }

/* Warna ikon per menu */
.nav-link[data-nav="dashboard"] > i { color: #60a5fa; }
.nav-link[data-nav="devices"] > i { color: #34d399; }
.nav-link[data-nav="contacts"] > i { color: #fbbf24; }
.nav-link[data-nav="groups"] > i { color: #a78bfa; }
.nav-link[data-nav="messages"] > i { color: #2dd4bf; }
.nav-link[data-nav="docs"] > i { color: #67e8f9; }
.nav-link[data-nav="api_tokens"] > i { color: #fb923c; }
.nav-link[data-nav="users"] > i { color: #38bdf8; }
.nav-link[data-nav="tenants"] > i { color: #c084fc; }
.nav-link[data-nav="settings"] > i { color: #94a3b8; }
.nav-link[data-nav="branding"] > i { color: #f472b6; }
.nav-link[data-nav="fail2ban"] > i { color: #fb7185; }

.app-sidebar {
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}
.sidebar-nav {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}
.nav-section {
  margin: 0.7rem 0 0.25rem;
  padding: 0 0.6rem;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}
.nav-section:first-child {
  margin-top: 0.15rem;
}

/* Anti-flash: if HTML somehow includes elevated links before role is known, keep them hidden */
body:not(.nav-ready) #sidebar-nav a[href="/tenants"],
body:not(.nav-ready) #sidebar-nav a[href="/settings"],
body:not(.nav-ready) #sidebar-nav a[href="/branding"],
body:not(.nav-ready) #sidebar-nav a[href="/fail2ban"],
body:not(.nav-ready) #sidebar-nav a[href="/users"],
body:not(.nav-ready) #sidebar-nav .nav-section[data-section] {
  display: none !important;
}

.card {
  border-radius: 1rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  padding: 1.25rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.input {
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #0f172a;
  padding: 0.65rem 0.85rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.input:hover:not(:disabled):not(:focus) {
  border-color: #94a3b8;
  background: #eef2f7;
}
.input:focus {
  border-color: var(--brand-primary);
  background: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 18%, transparent);
}
.input:disabled,
.input[readonly] {
  background: #e2e8f0;
  color: #64748b;
  cursor: not-allowed;
}
select.input {
  cursor: pointer;
}
textarea.input {
  resize: vertical;
  min-height: 4.5rem;
}

.label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #1e293b;
}
.label .font-normal,
.label .pwd-hint {
  font-weight: 400;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 0.75rem;
  background: var(--brand-primary);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: 0.15s ease;
  border: none;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  transition: 0.15s ease;
}
.btn-ghost:hover:not(:disabled) { background: #f8fafc; }
.btn-ghost:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; table-layout: auto; }
.table th {
  text-align: left;
  padding: 0.7rem 0.65rem;
  color: #64748b;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
.table td {
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr.table-row-link { cursor: pointer; }
.table tbody tr.table-row-link:hover .table-row-title { color: var(--brand-primary, #3C50E0); }
.table-row-anchor {
  display: block;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.table-row-title {
  display: block;
  font-weight: 650;
  color: #0f172a;
}
.table-row-preview {
  display: block;
  margin-top: 0.15rem;
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 400;
  color: #64748b;
}

.table .col-actions,
.table th.col-actions {
  text-align: right;
  width: 1%;
  white-space: nowrap;
  padding-right: 0.75rem;
}
.table td.col-actions .crud-actions {
  justify-content: flex-end;
  width: 100%;
}
.table .col-status { width: 7.5rem; white-space: nowrap; }
.table .col-narrow { width: 1%; white-space: nowrap; }
.table .col-phone {
  width: 11rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge-wa {
  background: #dcfce7;
  color: #14532d;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.badge-wa i {
  color: #16a34a;
  font-size: 0.85em;
}
.table .col-time { width: 9.5rem; white-space: nowrap; color: #94a3b8; font-size: 0.8rem; }
.table .col-num,
.table th.col-num { width: 4.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-primary {
  font-weight: 600;
  color: #1e293b;
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table .cell-muted {
  color: #94a3b8;
  font-size: 0.8rem;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crud-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  align-items: center;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
}
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-err { background: #ffe4e6; color: #9f1239; }
.badge-muted { background: #f1f5f9; color: #475569; }

/* Badge / tombol CRUD seragam */
.badge-crud,
.btn-crud {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.28rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: 0.15s ease;
}
.btn-crud:hover { filter: brightness(0.97); transform: translateY(-1px); }
.btn-crud:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.badge-crud-create, .btn-crud.badge-crud-create { background: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; }
.badge-crud-read, .btn-crud.badge-crud-read { background: #f1f5f9; color: #334155; border-color: #e2e8f0; }
.badge-crud-update, .btn-crud.badge-crud-update { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-crud-delete, .btn-crud.badge-crud-delete { background: #ffe4e6; color: #9f1239; border-color: #fecdd3; }
.badge-crud-connect, .btn-crud.badge-crud-connect { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-crud-disconnect, .btn-crud.badge-crud-disconnect { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.badge-crud-logout, .btn-crud.badge-crud-logout { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }

.toast {
  pointer-events: auto;
  border-radius: 0.75rem;
  background: #1e293b;
  color: #fff;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  box-shadow: 0 10px 30px rgba(15,23,42,0.2);
  display: flex;
  align-items: center;
  max-width: min(22rem, calc(100vw - 2rem));
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
dialog.dlg-confirm { width: min(calc(100vw - 2rem), 26rem); z-index: 70; }

/* Native <dialog> panels — keep browser [open] display, center reliably */
dialog.dlg-panel {
  width: min(calc(100vw - 2rem), 36rem);
  max-height: min(90vh, 720px);
  padding: 0;
  border: none;
  border-radius: 1rem;
  background: #fff;
  color: inherit;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.35);
  overflow: hidden;
}
dialog.dlg-panel[open] {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}
dialog.dlg-panel::backdrop {
  background: rgba(15, 23, 42, 0.5);
}
.dlg-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.1rem 1.25rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.dlg-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.dlg-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem 1.15rem;
  border-top: 1px solid #f1f5f9;
  background: #fff;
  flex-shrink: 0;
}
.dlg-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #64748b;
  cursor: pointer;
  flex-shrink: 0;
  z-index: 1;
}
.dlg-x:hover { background: #f8fafc; color: #0f172a; }

/* Prevent stacked/open dialogs from looking glued together */
dialog.dlg-panel + dialog.dlg-panel[open] {
  z-index: 60;
}

/* Branding drag-drop upload */
.upload-zone {
  position: relative;
  display: flex;
  min-height: 10rem;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 1rem;
  border: 2px dashed #cbd5e1;
  background: #f8fafc;
  padding: 1rem;
  text-align: center;
  transition: 0.15s ease;
}
.upload-zone:hover,
.upload-zone.is-dragover {
  border-color: var(--brand-primary, #3C50E0);
  background: color-mix(in srgb, var(--brand-primary, #3C50E0) 6%, white);
}
.upload-zone.has-file {
  border-style: solid;
  border-color: #e2e8f0;
  background: #fff;
  padding: 0.5rem;
}
.upload-preview {
  display: flex;
  height: 100%;
  width: 100%;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 0.75rem;
}
.upload-preview img {
  max-height: 8.5rem;
  max-width: 100%;
  object-fit: contain;
}
.upload-zone[data-kind="login_bg"] .upload-preview img {
  max-height: 9rem;
  width: 100%;
  object-fit: cover;
}
.upload-clear {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  height: 2rem;
  width: 2rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  border: 1px solid #fecdd3;
  background: #fff1f2;
  color: #9f1239;
  cursor: pointer;
  z-index: 2;
}
.upload-clear:hover { background: #ffe4e6; }
.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;
}

/* Settings tabs layout */
.settings-layout {
  display: grid;
  gap: 1rem;
}
@media (min-width: 900px) {
  .settings-layout {
    grid-template-columns: 14rem minmax(0, 1fr);
    align-items: start;
  }
}
.settings-tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}
@media (min-width: 900px) {
  .settings-tabs {
    flex-direction: column;
    overflow: visible;
    position: sticky;
    top: 1rem;
  }
}
.settings-tab {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  white-space: nowrap;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
  text-align: left;
}
.settings-tab i { width: 1.1rem; text-align: center; color: #94a3b8; }
.settings-tab-label { flex: 1; min-width: 0; }
.settings-tab-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: #94a3b8;
  background: #f1f5f9;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}
.settings-tab:hover { border-color: #cbd5e1; background: #f8fafc; }
.settings-tab.active {
  border-color: color-mix(in srgb, var(--brand-primary, #3C50E0) 35%, white);
  background: color-mix(in srgb, var(--brand-primary, #3C50E0) 10%, white);
  color: #0f172a;
}
.settings-tab.active i { color: var(--brand-primary, #3C50E0); }
.settings-tab.active .settings-tab-count {
  background: color-mix(in srgb, var(--brand-primary, #3C50E0) 18%, white);
  color: var(--brand-primary, #3C50E0);
}
.settings-panel { min-height: 24rem; }
.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-start;
  border: 1px solid #e2e8f0;
  border-radius: 0.9rem;
  padding: 0.9rem 1rem;
  background: #fff;
}
.settings-row.is-readonly { background: #f8fafc; }
.settings-row-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  padding-top: 0.15rem;
}
.settings-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}
.settings-switch input { width: 1.05rem; height: 1.05rem; }

/* WhatsApp-style chat shell — roomier layout */
body[data-page="messages"] main,
body.page-messages main {
  display: flex;
  flex-direction: column;
  padding: 0.55rem 0.85rem 0.75rem;
  min-height: calc(100vh - 3rem);
  font-size: 13px;
}
@media (min-width: 1024px) {
  body[data-page="messages"] main,
  body.page-messages main {
    padding: 0.6rem 1rem 0.85rem;
  }
}
body[data-page="messages"] #page-header,
body.page-messages #page-header {
  margin-bottom: 0.35rem;
  flex-shrink: 0;
}
body[data-page="messages"] #page-header .mb-6,
body.page-messages #page-header .mb-6 {
  margin-bottom: 0 !important;
  gap: 0.5rem;
}
body[data-page="messages"] #page-header h1,
body.page-messages #page-header h1 {
  font-size: 1.05rem;
  line-height: 1.25;
}
body[data-page="messages"] #page-header p,
body.page-messages #page-header p {
  font-size: 0.72rem;
  line-height: 1.35;
}
body[data-page="messages"] #page-header .h-11,
body.page-messages #page-header .h-11 {
  height: 2rem;
  width: 2rem;
}
body[data-page="messages"] #page-header .text-lg,
body.page-messages #page-header .text-lg {
  font-size: 0.85rem;
}

.chat-shell {
  display: grid;
  grid-template-columns: minmax(240px, 22vw) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: calc(100vh - 6.4rem);
  max-height: calc(100vh - 6.4rem);
  padding: 0;
  overflow: hidden;
}
@media (min-width: 1400px) {
  .chat-shell {
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  }
}
@media (max-width: 1024px) {
  .chat-shell {
    grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
  }
}
@media (max-width: 900px) {
  .chat-shell {
    grid-template-columns: 1fr;
    min-height: auto;
    max-height: none;
  }
}
.chat-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e2e8f0;
  background: #fff;
  min-height: 0;
  min-width: 0;
}
.chat-sidebar-head {
  display: grid;
  gap: 0.35rem;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.chat-field-label {
  display: block;
  margin-bottom: 0.12rem;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
}
.chat-sidebar-actions {
  display: grid;
  gap: 0.3rem;
}
.chat-field { min-width: 0; }
.chat-shell .input {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  line-height: 1.3;
  border-radius: 0.5rem;
  min-height: 1.8rem;
  height: 1.8rem;
}
.chat-search-wrap {
  position: relative;
}
.chat-search-wrap .input {
  padding-left: 1.7rem;
}
.chat-search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.7rem;
  pointer-events: none;
}
.chat-list-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.55rem 0.45rem;
  border-bottom: 1px solid #f1f5f9;
  background: #fff;
  flex-shrink: 0;
}
.chat-list-toolbar .chat-search-wrap {
  flex: 1 1 auto;
  min-width: 0;
}
.chat-header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  min-width: 0;
}
.chat-header-tools .chat-new-row {
  width: min(22rem, 100%);
}
.chat-header-tools .input {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  line-height: 1.3;
  border-radius: 0.5rem;
  min-height: 1.8rem;
  height: 1.8rem;
}
.chat-header-tools .chat-new-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex: 0 0 auto;
  width: auto;
  min-width: max-content;
  height: 1.8rem;
  padding: 0 0.7rem;
  border-radius: 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: visible;
}
@media (max-width: 640px) {
  .chat-header-tools {
    width: 100%;
  }
  .chat-header-tools .chat-new-row {
    width: 100%;
  }
  .chat-header-tools .chat-new-btn span {
    display: none;
  }
  .chat-header-tools .chat-new-btn {
    width: 1.8rem;
    min-width: 1.8rem;
    padding: 0;
  }
}
.chat-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  background: #f1f5f9;
  border-radius: 0.65rem;
  padding: 0.2rem;
}
.chat-tab {
  border: 0;
  background: transparent;
  border-radius: 0.4rem;
  padding: 0.26rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
}
.chat-tab.active {
  background: #fff;
  color: #0f172a;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
.chat-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.chat-list-empty {
  padding: 1.5rem 0.85rem;
  text-align: center;
  color: #94a3b8;
  font-size: 0.75rem;
}
.chat-item {
  display: flex;
  width: 100%;
  gap: 0.55rem;
  align-items: center;
  padding: 0.5rem 0.7rem;
  border: 0;
  border-bottom: 1px solid #f8fafc;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.chat-item:hover { background: #f8fafc; }
.chat-item.active { background: color-mix(in srgb, var(--brand-primary, #3C50E0) 10%, white); }
.chat-avatar {
  display: inline-flex;
  height: 2.1rem;
  width: 2.1rem;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-weight: 700;
  font-size: 0.75rem;
}
.chat-avatar.is-group {
  background: #dbeafe;
  color: #1d4ed8;
}
.chat-chip {
  flex-shrink: 0;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #1d4ed8;
  background: #dbeafe;
  border-radius: 999px;
  padding: 0.05rem 0.32rem;
  line-height: 1.25;
}
.chat-item .font-semibold {
  font-size: 0.78rem;
  line-height: 1.25;
}
.chat-item .text-xs {
  font-size: 0.68rem;
  line-height: 1.3;
}
.chat-item .text-\[10px\] {
  font-size: 0.58rem;
}
.chat-bubble-sender {
  font-size: 0.65rem;
  font-weight: 700;
  color: #1d4ed8;
  margin-bottom: 0.12rem;
  line-height: 1.2;
  word-break: break-word;
}
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: #f8fafc;
}
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  text-align: center;
}
.chat-empty .text-5xl { font-size: 2.25rem; }
.chat-empty .text-lg { font-size: 0.95rem; }
.chat-empty .text-sm { font-size: 0.75rem; }
.chat-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat-thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  padding: 0.55rem 0.85rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
#chat-title {
  font-size: 0.85rem;
  line-height: 1.25;
}
#chat-subtitle {
  font-size: 0.68rem;
}
.chat-thread-head .badge {
  font-size: 0.62rem;
  padding: 0.12rem 0.4rem;
}
.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(15, 23, 42, 0.03), transparent 40%),
    #eef2f7;
}
.chat-thread-empty {
  margin: auto;
  color: #94a3b8;
  font-size: 0.75rem;
}
.chat-bubble {
  max-width: min(72%, 36rem);
  border-radius: 0.7rem;
  padding: 0.4rem 0.6rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.chat-bubble.out {
  align-self: flex-end;
  background: #dcf8c6;
  border-bottom-right-radius: 0.25rem;
}
.chat-bubble.in {
  align-self: flex-start;
  background: #fff;
  border-bottom-left-radius: 0.25rem;
}
.chat-bubble-body {
  white-space: pre-wrap;
  word-break: break-word;
  color: #0f172a;
  font-size: 0.8rem;
  line-height: 1.4;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", Satoshi, "Nunito Sans", system-ui, sans-serif;
}
.chat-bubble-meta {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.18rem;
  font-size: 0.58rem;
  color: #64748b;
}
.chat-bubble-error {
  margin-top: 0.3rem;
  padding-top: 0.28rem;
  border-top: 1px solid rgba(225, 29, 72, 0.18);
  color: #be123c;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.35;
}
.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}
.chat-status-label { opacity: 0.9; }
.chat-ticks {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  line-height: 1;
}
.chat-ticks.sent { color: #64748b; }
.chat-ticks.delivered { color: #64748b; }
.chat-ticks.read { color: #53bdeb; }
.chat-ticks.failed { color: #e11d48; }
.chat-new-row {
  display: flex;
  gap: 0.45rem;
  align-items: stretch;
}
.chat-new-row .input { flex: 1 1 auto; min-width: 0; }
.chat-new-row .btn-primary:not(.chat-new-btn) {
  padding: 0;
  width: 1.8rem;
  min-width: 1.8rem;
  height: 1.8rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
}
.chat-header-tools .chat-new-row .chat-new-btn {
  flex: 0 0 auto;
  width: auto;
  min-width: max-content;
  height: 1.8rem;
  padding: 0 0.7rem;
}
.chat-compose-wrap {
  position: relative;
  flex-shrink: 0;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  padding: 0.25rem 0.6rem 0.4rem;
}
.chat-compose-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.05rem;
  align-items: center;
  margin-bottom: 0.25rem;
}
.chat-tool-btn {
  width: 1.7rem;
  height: 1.7rem;
  border: none;
  border-radius: 0.4rem;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.chat-tool-btn:hover,
.chat-tool-btn:focus-visible {
  background: #f1f5f9;
  color: #0f172a;
  outline: none;
}
.chat-compose {
  display: flex;
  gap: 0.55rem;
  align-items: flex-end;
  padding: 0;
  border: 0;
  background: transparent;
}
.chat-compose-input-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.emoji-panel {
  position: absolute;
  bottom: calc(100% + 0.35rem);
  left: 0.85rem;
  z-index: 30;
  width: min(22rem, calc(100% - 1.7rem));
  max-height: 13.5rem;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.2rem;
  padding: 0.55rem;
  border-radius: 0.9rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  box-shadow: 0 16px 36px -14px rgba(15, 23, 42, 0.35);
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
}
.emoji-panel.hidden { display: none; }
.emoji-btn {
  border: none;
  background: transparent;
  border-radius: 0.45rem;
  font-size: 1.35rem;
  line-height: 1.35;
  cursor: pointer;
  padding: 0.2rem;
  min-height: 2rem;
  font-family: inherit;
}
.emoji-btn:hover { background: #f1f5f9; }
.chat-attach-preview {
  padding: 0.55rem 0.85rem 0;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}
.chat-attach-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
}
.chat-attach-thumb {
  width: 3rem;
  height: 3rem;
  object-fit: cover;
  border-radius: 0.45rem;
}
.chat-attach-icon { font-size: 1.4rem; color: #64748b; }
.chat-media-img {
  display: block;
  max-width: min(100%, 18rem);
  max-height: 16rem;
  border-radius: 0.55rem;
  margin-bottom: 0.25rem;
}
.chat-media-video {
  display: block;
  max-width: min(100%, 18rem);
  border-radius: 0.55rem;
}
.chat-media-audio { width: min(100%, 16rem); }
.chat-media-caption { margin-top: 0.25rem; }
.chat-doc, .chat-loc {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.55rem;
  background: rgba(15, 23, 42, 0.04);
  color: inherit;
  text-decoration: none;
}
.chat-doc i, .chat-loc i { color: #0ea5e9; font-size: 1.15rem; }
.chat-doc:hover, .chat-loc:hover { background: rgba(15, 23, 42, 0.07); }
.chat-compose .input {
  resize: none;
  height: auto;
  min-height: 1.8rem;
  max-height: 6.5rem;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  line-height: 1.3;
  font-size: 0.8rem;
}
.chat-compose #btn-chat-send {
  width: 1.8rem;
  min-width: 1.8rem;
  height: 1.8rem;
  padding: 0;
  border-radius: 0.5rem;
  font-size: 0.75rem;
}

/* —— Login page —— */
.login-page {
  --login-overlay: 0.55;
  --login-panel-bg: rgba(255, 255, 255, 0.78);
  --login-panel-border: rgba(255, 255, 255, 0.55);
  margin: 0;
  min-height: 100%;
  background: #0f172a;
}

.login-shell {
  position: relative;
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 12% 10%, color-mix(in srgb, var(--brand-primary) 45%, transparent), transparent 60%),
    radial-gradient(900px 500px at 88% 85%, color-mix(in srgb, var(--brand-secondary) 40%, transparent), transparent 55%),
    linear-gradient(145deg, #0b1220 0%, #1e293b 48%, #0f172a 100%);
  background-size: cover;
  background-position: center;
  transform: scale(1.02);
}

.login-has-bg .login-bg {
  background-color: #0f172a;
  background-repeat: no-repeat;
}

.login-bg-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      160deg,
      rgba(15, 23, 42, calc(var(--login-overlay) + 0.12)) 0%,
      rgba(15, 23, 42, var(--login-overlay)) 45%,
      rgba(15, 23, 42, calc(var(--login-overlay) + 0.18)) 100%
    );
  backdrop-filter: blur(2px);
}

.login-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 26rem;
  padding: 2rem 1.75rem 1.5rem;
  border-radius: 1.35rem;
  border: 1px solid var(--login-panel-border);
  background: var(--login-panel-bg);
  box-shadow:
    0 25px 50px -12px rgba(15, 23, 42, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  backdrop-filter: blur(18px) saturate(1.35);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  animation: login-rise 0.55s ease-out both;
}

@keyframes login-rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: 0.9rem;
  border-radius: 1rem;
  background: var(--brand-primary);
  color: #fff;
  font-size: 1.55rem;
  box-shadow: 0 12px 24px color-mix(in srgb, var(--brand-primary) 35%, transparent);
}

.login-logo-img {
  display: block;
  height: 3.5rem;
  max-width: 10rem;
  margin: 0 auto 0.9rem;
  object-fit: contain;
}

.login-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.login-subtitle {
  margin: 0.4rem 0 0;
  font-size: 0.875rem;
  color: #64748b;
}

.login-form {
  display: grid;
  gap: 1rem;
}

.login-field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #1e293b;
}

.login-input-wrap {
  position: relative;
}

.login-input-wrap > i {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.85rem;
  pointer-events: none;
}

.login-input {
  padding-left: 2.45rem !important;
  background: #f1f5f9 !important;
  border-color: #cbd5e1 !important;
}

.login-input:focus {
  background: #fff !important;
}

.login-error {
  margin: 0;
  padding: 0.65rem 0.8rem;
  border-radius: 0.75rem;
  background: rgba(255, 241, 242, 0.92);
  border: 1px solid #fecdd3;
  color: #be123c;
  font-size: 0.8125rem;
}

.login-submit {
  width: 100%;
  justify-content: center;
  padding: 0.75rem 1rem;
  margin-top: 0.25rem;
  font-size: 0.9375rem;
  box-shadow: 0 10px 20px color-mix(in srgb, var(--brand-primary) 28%, transparent);
}

.login-submit:disabled {
  opacity: 0.65;
  cursor: wait;
}

.login-foot {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: #94a3b8;
  min-height: 1rem;
}

@media (max-width: 420px) {
  .login-panel {
    padding: 1.5rem 1.15rem 1.25rem;
    border-radius: 1.15rem;
  }
}

/* —— QR pairing dialog —— */
dialog.dlg-qr-panel {
  width: min(calc(100vw - 2rem), 28rem);
  max-height: min(92vh, 820px);
}
.qr-dlg-head {
  align-items: center;
}
.qr-dlg-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}
.qr-dlg-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.qr-dlg-title i { color: var(--brand-primary, #3C50E0); }
.qr-status-badge .badge { font-size: 0.72rem; }
.qr-dlg-body {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.qr-steps {
  margin: 0;
  padding: 0.75rem 0.9rem 0.75rem 1.6rem;
  border-radius: 0.85rem;
  background: #f8fafc;
  border: 1px solid #eef2f7;
  color: #64748b;
  font-size: 0.78rem;
  line-height: 1.45;
}
.qr-steps li + li { margin-top: 0.2rem; }
.qr-steps strong { color: #334155; font-weight: 600; }
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: 1rem;
  border-radius: 1rem;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px solid #e2e8f0;
}
.qr-box canvas,
.qr-box img {
  border-radius: 0.5rem;
  background: #fff;
}
.qr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.qr-actions .btn-primary,
.qr-actions .btn-ghost {
  flex: 1 1 9rem;
  justify-content: center;
}
.qr-panel {
  border-radius: 0.9rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  padding: 0.85rem 0.95rem;
}
.qr-panel-head h4 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 650;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.qr-panel-head p {
  margin: 0.25rem 0 0;
  font-size: 0.72rem;
  color: #94a3b8;
}
.qr-pin-row,
.qr-share-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.65rem;
  align-items: stretch;
}
.qr-pin-row .input,
.qr-share-row .input {
  flex: 1 1 auto;
  min-width: 0;
}
.qr-pin-row .btn-primary,
.qr-share-row .btn-primary {
  flex-shrink: 0;
  white-space: nowrap;
}
.qr-pin-result {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-radius: 0.75rem;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
}
.qr-pin-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #047857;
}
.qr-pin-code {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #064e3b;
  font-variant-numeric: tabular-nums;
}
.btn-sm {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
}

/* —— Public /pair page —— */
.pair-page {
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, color-mix(in srgb, var(--brand-primary, #3C50E0) 18%, transparent), transparent),
    linear-gradient(160deg, #f8fafc 0%, #eef2ff 45%, #f1f5f9 100%);
}
.pair-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}
.pair-card {
  width: min(100%, 26rem);
  background: #fff;
  border-radius: 1.25rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 20px 40px -18px rgba(15, 23, 42, 0.28);
  padding: 1.35rem 1.25rem 1.5rem;
}
.pair-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.pair-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  min-width: 0;
}
.pair-logo {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--brand-primary, #25D366) 14%, white);
  color: #16a34a;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.pair-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
}
.pair-sub {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 12rem;
}
.pair-steps {
  margin: 0 0 1rem;
  padding: 0.7rem 0.85rem 0.7rem 1.5rem;
  border-radius: 0.85rem;
  background: #f8fafc;
  font-size: 0.78rem;
  color: #64748b;
  line-height: 1.45;
}
.pair-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  border-radius: 1rem;
  background: linear-gradient(180deg, #f8fafc, #f1f5f9);
  border: 1px solid #e2e8f0;
  padding: 1rem;
}
.pair-pin-wrap {
  margin-top: 1rem;
  text-align: center;
  padding: 0.75rem;
  border-radius: 0.85rem;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
}
.pair-pin-label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #047857;
}
.pair-pin-code {
  margin: 0.35rem 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #064e3b;
  font-variant-numeric: tabular-nums;
}
.pair-meta {
  margin: 0.85rem 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: #94a3b8;
}
.pair-error {
  margin: 0.65rem 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: #be123c;
}

.docs-layout {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 900px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-toc { position: static; }
}
.docs-toc {
  position: sticky;
  top: 3.75rem;
  padding: 1rem;
  display: grid;
  gap: 0.2rem;
}
.docs-toc-title {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 0.25rem;
}
.docs-toc a {
  border-radius: 0.5rem;
  padding: 0.4rem 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #475569;
  text-decoration: none;
}
.docs-toc a:hover { background: #f1f5f9; color: #0f172a; }
.docs-section h2 {
  font-size: 1.1rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 0.65rem;
}
.docs-section p { font-size: 0.9rem; color: #475569; margin: 0.4rem 0; }
.docs-list {
  margin: 0.5rem 0 0.5rem 1.1rem;
  font-size: 0.9rem;
  color: #334155;
}
.docs-list li { margin: 0.25rem 0; }
.docs-note {
  margin-top: 0.75rem;
  padding: 0.65rem 0.8rem;
  border-radius: 0.7rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 0.82rem;
  color: #64748b;
}
.docs-table {
  width: 100%;
  margin-top: 0.7rem;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.docs-table th, .docs-table td {
  text-align: left;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.docs-table th { color: #64748b; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.docs-code {
  position: relative;
  margin-top: 0.7rem;
  padding: 0.85rem 2.4rem 0.85rem 0.9rem;
  border-radius: 0.75rem;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-x: auto;
}
.docs-code code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; }
.docs-copy {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 1.85rem;
  height: 1.85rem;
  border: 0;
  border-radius: 0.45rem;
  background: rgba(255,255,255,0.08);
  color: #cbd5e1;
  cursor: pointer;
}
.docs-copy:hover { background: rgba(255,255,255,0.16); color: #fff; }
.docs-section code:not(.docs-code code) {
  font-size: 0.78rem;
  background: #f1f5f9;
  padding: 0.1rem 0.3rem;
  border-radius: 0.3rem;
}


