:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1a2233;
  background: #f4f6f9;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #e5e9f0;
  --text: #1a2233;
  --muted: #6b7484;
  --accent: #1f5eff;
  --accent-soft: #edf3ff;
  --good: #18794e;
  --warn: #a15c00;
  --bad: #b42318;
  --shadow: 0 10px 30px rgba(23, 35, 55, .08);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--bad); margin: 0; }
.eyebrow { margin: 0 0 6px; font-size: 11px; letter-spacing: .14em; font-weight: 800; color: var(--muted); }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(560px, 100%);
  display: grid;
  gap: 22px;
  padding: 34px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 8px; font-size: 30px; line-height: 1.15; }
.brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: #111827;
  color: white;
  font-size: 28px;
  font-weight: 900;
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 18px; }

.stack { display: grid; gap: 14px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
input, textarea, select {
  width: 100%;
  border: 1px solid #cfd6e1;
  border-radius: 12px;
  padding: 11px 12px;
  background: white;
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.button {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  font-weight: 800;
  min-height: 40px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.button.primary { background: var(--accent); color: white; }
.button.secondary { background: #edf0f5; color: #273142; }
.button.ghost { background: transparent; color: #d5dbea; border: 1px solid #414b5e; }
.button.danger { background: #fff0ef; color: var(--bad); }
.button.small { min-height: 32px; padding: 7px 10px; font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: #111827;
  color: white;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 7px; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand span { margin-top: 3px; color: #9ea8bb; font-size: 12px; }
#nav { display: grid; gap: 5px; }
.nav-item {
  border: 0;
  background: transparent;
  color: #c7cfdd;
  text-align: left;
  border-radius: 10px;
  padding: 11px 12px;
  font-weight: 700;
}
.nav-item:hover, .nav-item.active { background: #202a3a; color: white; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; padding: 0 7px; }
#admin-name { font-size: 12px; color: #9ea8bb; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; padding: 28px 32px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.topbar h2 { margin: 0; font-size: 26px; }
.view { display: grid; gap: 18px; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.stat, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 3px 12px rgba(23, 35, 55, .04);
}
.stat { padding: 18px; }
.stat span { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat strong { display: block; margin-top: 8px; font-size: 26px; letter-spacing: -.02em; }
.panel { padding: 18px; }
.panel h3 { margin: 0 0 14px; font-size: 16px; }
.panel-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input { width: min(360px, 100%); }
.toolbar .spacer { flex: 1; }
.toolbar strong { display: block; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.panel-soft { padding: 12px 14px; border-radius: 12px; background: var(--panel-soft); color: var(--muted); font-size: 13px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: #f8fafc; color: #667085; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 800;
  background: #eef1f5;
}
.badge.good { background: #e9f7ef; color: var(--good); }
.badge.warn { background: #fff4df; color: var(--warn); }
.badge.bad { background: #fff0ef; color: var(--bad); }

.code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border: 1px dashed #aab3c0;
  background: #f8fafc;
  padding: 14px;
  border-radius: 12px;
  overflow-wrap: anywhere;
}
.connector-card { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.connector-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.connector-head strong { display: block; }
.meta { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.meta > div { padding: 10px; border-radius: 10px; background: var(--panel-soft); }
.meta span { display: block; font-size: 11px; color: var(--muted); }
.meta strong { display: block; margin-top: 4px; font-size: 12px; overflow-wrap: anywhere; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }

.empty { padding: 34px; text-align: center; color: var(--muted); }
.loading { min-height: 120px; display: grid; place-items: center; color: var(--muted); }

.modal { width: min(860px, calc(100vw - 40px)); border: 0; border-radius: 18px; padding: 0; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(15, 23, 42, .5); }
#modal-content { padding: 22px; max-height: 70vh; overflow: auto; }
.modal-actions { padding: 14px 22px; border-top: 1px solid var(--line); text-align: right; }

.toast {
  position: fixed;
  z-index: 20;
  right: 20px;
  top: 20px;
  max-width: 440px;
  padding: 12px 15px;
  border-radius: 12px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #b42318; }
.mt-14 { margin-top: 14px; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .panel-grid, .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  #nav { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .nav-item { text-align: center; font-size: 12px; }
  .main { padding: 20px 14px 50px; }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .meta { grid-template-columns: 1fr; }
}


.chat-admin-layout { display: grid; grid-template-columns: minmax(250px, 340px) minmax(0, 1fr); gap: 18px; min-height: 620px; }
.chat-thread-list { padding: 0; overflow: hidden; }
.chat-thread-list-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 17px; border-bottom: 1px solid var(--line); }
.chat-thread-list-body { max-height: 680px; overflow: auto; }
.chat-thread-button { width: 100%; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 5px 10px; border: 0; border-bottom: 1px solid var(--line); padding: 13px 14px; background: #fff; text-align: left; color: var(--text); }
.chat-thread-button:hover, .chat-thread-button.active { background: var(--accent-soft); }
.chat-thread-button span strong, .chat-thread-button span small { display: block; }
.chat-thread-button small { color: var(--muted); font-size: 11px; margin-top: 3px; }
.chat-thread-button em { grid-column: 1 / -1; font-style: normal; font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-thread-meta { text-align: right; }
.chat-conversation { padding: 0; display: grid; grid-template-rows: auto minmax(360px,1fr) auto; min-width: 0; overflow: hidden; }
.chat-conversation-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.chat-conversation-head h3 { margin: 0 0 4px; }
.chat-messages { padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; }
.chat-message { max-width: min(78%, 720px); padding: 10px 12px; border-radius: 14px; box-shadow: 0 1px 4px rgba(23,35,55,.06); line-height: 1.4; overflow-wrap: anywhere; }
.chat-message.customer { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.chat-message.operator { align-self: flex-end; background: #e7efff; border: 1px solid #c8d8ff; border-bottom-right-radius: 5px; }
.chat-message small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; }
.chat-reply-form { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: #fff; align-items: end; }
.chat-reply-form textarea { resize: vertical; min-height: 70px; }
@media (max-width: 900px) {
  .chat-admin-layout { grid-template-columns: 1fr; }
  .chat-thread-list-body { max-height: 300px; }
}

.theme-editor { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr); gap: 18px; align-items: start; }
.theme-settings-panel .toolbar h3 { margin-bottom: 4px; }
.theme-settings-panel .toolbar p { margin: 0; }
.color-input { min-height: 48px; padding: 5px; cursor: pointer; }
.module-controls { display: grid; gap: 9px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); }
.module-controls > p { margin: -3px 0 4px; }
.theme-preview-panel { position: sticky; top: 24px; }
.theme-preview-canvas { display: block; width: min(390px, 100%); height: auto; margin: 14px auto 0; border: 1px solid var(--line); border-radius: 22px; background: #f3f7f9; box-shadow: var(--shadow); }
.theme-logo-preview { display: block; max-width: 180px; max-height: 64px; object-fit: contain; margin: 12px auto 0; }
.theme-logo-actions { align-items: center; }
@media (max-width: 1050px) {
  .theme-editor { grid-template-columns: 1fr; }
  .theme-preview-panel { position: static; }
}
.mono-small { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; overflow-wrap: anywhere; }
.link-button { border: 0; padding: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.mapper-template-action { align-items: end; }
#mapper-json { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; min-height: 280px; }
