/* Tabler-inspired design system (self-hosted, no external assets). */
* { box-sizing: border-box; }
:root {
  --bg: #f5f7fb; --surface: #ffffff; --surface-2: #fbfcfe;
  --border: #e6e8ec; --border-strong: #d7dbe0;
  --text: #1a2330; --muted: #6b7688;
  --primary: #206bc4; --primary-hover: #1a5aa8; --primary-soft: #e9f0fb;
  --danger: #d63939; --danger-hover: #c02f2f; --danger-soft: #fbe9e9;
  --success: #2fb344; --success-soft: #e8f7ea; --warning: #f59f00;
  --radius: 10px; --radius-sm: 7px; --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.04);
  --shadow-lg: 0 16px 48px rgba(15,23,42,.20);
  --nav-w: 264px;
}
:root[data-theme="dark"] {
  --bg: #0e1520; --surface: #172131; --surface-2: #1b2636;
  --border: #29344a; --border-strong: #38455f;
  --text: #e6eaf1; --muted: #8b96aa;
  --primary: #4b8ed6; --primary-hover: #5f9cdd; --primary-soft: #17273c;
  --danger: #e05c5c; --danger-hover: #e97070; --danger-soft: #3a2224;
  --success: #47c05b; --success-soft: #16301c; --warning: #f5b342;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 16px 48px rgba(0,0,0,.55);
}
/* OS preference only applies until the user makes an explicit choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e1520; --surface: #172131; --surface-2: #1b2636;
    --border: #29344a; --border-strong: #38455f;
    --text: #e6eaf1; --muted: #8b96aa;
    --primary: #4b8ed6; --primary-hover: #5f9cdd; --primary-soft: #17273c;
    --danger: #e05c5c; --danger-hover: #e97070; --danger-soft: #3a2224;
    --success: #47c05b; --success-soft: #16301c; --warning: #f5b342;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 16px 48px rgba(0,0,0,.55);
  }
}

html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); transition: background .12s, border-color .12s, box-shadow .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); border-color: var(--primary); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { width: 32px; height: 32px; padding: 0; }
.btn .icon { width: 17px; height: 17px; }

/* Icons */
.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; vertical-align: middle; }

/* Forms */
.form-label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13px; }
.form-hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.form-control, .form-select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px;
  transition: border-color .12s, box-shadow .12s;
}
.form-control:focus, .form-select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.mb { margin-bottom: 16px; }
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row .form-control { flex: 1; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title { font-size: 15px; }
.card-body { padding: 18px; }
.card-subtle { color: var(--muted); font-size: 13px; margin: -6px 0 14px; }

/* Auth */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; margin: 0; }
.auth-card .card-body { padding: 30px; }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; font-weight: 700; font-size: 18px; margin-bottom: 6px; }
.auth-brand .logo { color: var(--primary); }
.auth-title { text-align: center; font-size: 17px; margin-bottom: 22px; color: var(--muted); font-weight: 500; }
.auth-foot { text-align: center; margin: 18px 0 0; color: var(--muted); }
.alert { border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13px; margin-bottom: 16px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid transparent; }

/* Layout */
.layout { min-height: 100vh; display: flex; flex-direction: column; }
.navbar { height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.navbar-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; }
.navbar-brand .logo { color: var(--primary); }
.navbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 4px 8px; cursor: pointer; color: var(--text); font: inherit; }
.user-chip:hover { background: var(--surface-2); border-color: var(--border); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600; text-transform: uppercase; }
.body { flex: 1; display: grid; grid-template-columns: var(--nav-w) 1fr; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; }
.sidebar-title { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 4px 8px 10px; }
.nav-bots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-bots li { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); font-weight: 500; }
.nav-bots li:hover { background: var(--surface-2); }
.nav-bots li.active { background: var(--primary-soft); color: var(--primary); }
.nav-bots li .icon { width: 18px; height: 18px; }
.content { padding: 24px 28px; overflow-x: auto; }

/* Empty state */
.empty { max-width: 380px; margin: 90px auto; text-align: center; }
.empty-icon { font-size: 44px; }
.empty-title { font-size: 17px; font-weight: 600; margin: 10px 0 4px; }
.empty .btn { margin-top: 14px; }

/* Page header + tabs */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.page-pretitle { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.page-title { font-size: 22px; }
.nav-tabs { list-style: none; display: flex; flex-wrap: wrap; gap: 2px; margin: 0 0 22px; padding: 0; border-bottom: 1px solid var(--border); }
.nav-tabs li { display: flex; align-items: center; gap: 7px; padding: 9px 13px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.nav-tabs li:hover { color: var(--text); }
.nav-tabs li.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-tabs li .icon { width: 17px; height: 17px; }

/* Grid + stats */
.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.stat .stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.mono, code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: var(--surface-2); border: 1px solid var(--border); padding: 13px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 12.5px; margin: 0; }

/* Badges + dots */
.badge { display: inline-flex; align-items: center; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 500; margin: 2px 3px 2px 0; }
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.checks { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 4px; }
.check { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; font-size: 13px; user-select: none; }
.check input { accent-color: var(--primary); }

/* Live chat */
.chat-wrap { display: grid; grid-template-columns: 280px 1fr; gap: 16px; min-height: 460px; }
.conv-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.conv { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--primary-soft); }
.conv .conv-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 13px; }
.conv .conv-prev { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; background: var(--surface); }
.msgs { flex: 1; overflow-y: auto; padding: 14px; max-height: 400px; display: flex; flex-direction: column; gap: 6px; }
.msg { padding: 8px 12px; border-radius: 12px; max-width: 76%; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { background: var(--surface-2); border: 1px solid var(--border); align-self: flex-start; }
.msg.bot { background: var(--primary-soft); align-self: flex-start; }
.msg.admin { background: var(--primary); color: #fff; align-self: flex-end; }
.msg.system { background: transparent; color: var(--muted); font-size: 12px; text-align: center; align-self: center; max-width: 100%; }
.send-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.send-row .form-control { flex: 1; }
.online-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; padding: 20px; z-index: 100; opacity: 0; transition: opacity .15s; }
.modal-backdrop.open { opacity: 1; }
.modal { width: 100%; max-width: 460px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); transform: translateY(8px) scale(.98); transition: transform .15s; overflow: hidden; }
.modal-backdrop.open .modal { transform: none; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-body p { margin: 0 0 4px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* Toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: var(--radius); z-index: 200; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .18s, transform .18s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); color: #fff; }

/* Loading spinner */
.loading { display: flex; justify-content: center; padding: 40px; }
.spinner { width: 24px; height: 24px; border: 2.5px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Settings + live widget preview */
.settings-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.wp { --c: #2563eb; position: relative; height: 400px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.wp-panel { position: absolute; bottom: 74px; right: 16px; width: 248px; background: #fff; color: #111; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.28); overflow: hidden; display: flex; flex-direction: column; }
.wp.left .wp-panel { right: auto; left: 16px; }
.wp-head { background: var(--c); color: #fff; padding: 11px 13px; font-weight: 600; font-size: 13px; }
.wp-body { background: #f7f8fa; padding: 11px; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.wp-msg { padding: 7px 10px; border-radius: 11px; font-size: 12px; max-width: 86%; }
.wp-bot { background: #e9edf2; color: #111; align-self: flex-start; }
.wp-user { background: var(--c); color: #fff; align-self: flex-end; }
.wp-form { display: flex; border-top: 1px solid #e5e7eb; background: #fff; }
.wp-input { flex: 1; padding: 10px; font-size: 12px; color: #9aa2ad; }
.wp-send { background: var(--c); color: #fff; padding: 10px 13px; font-size: 12px; font-weight: 600; }
.wp-btn { position: absolute; bottom: 16px; right: 16px; width: 46px; height: 46px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-size: 20px; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
.wp.left .wp-btn { right: auto; left: 16px; }
@media (max-width: 980px) { .settings-grid { grid-template-columns: 1fr; } }

@media (max-width: 820px) {
  .body { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .chat-wrap { grid-template-columns: 1fr; }
  .content { padding: 18px; }
}
