:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e4e7ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #059669;
  --warning: #b45309;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--primary); }

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: none;
  background: #0f172a;
  color: #cbd5e1;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 17px; padding: 6px 10px 18px; display: block; text-decoration: none; }
.sidebar a.nav {
  display: flex; align-items: center; gap: 10px;
  color: #cbd5e1; text-decoration: none;
  padding: 10px 12px; border-radius: 10px; font-weight: 500;
}
.sidebar a.nav:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar a.nav.active { background: var(--primary); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .who { font-size: 12.5px; color: #94a3b8; padding: 12px; border-top: 1px solid rgba(255, 255, 255, .1); }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 23px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card .hint { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* The website list needs room for its action buttons, so it only shares the
   row with the create form on wide screens. */
.sites-layout { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 1500px) {
  .sites-layout { grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr); align-items: start; }
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { display: inline-flex; }
td .mono { word-break: break-word; }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 27px; font-weight: 700; margin-top: 6px; }

label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field .help { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(79, 70, 229, .25); border-color: var(--primary); }
textarea { resize: vertical; min-height: 90px; }
input[type=color] { width: 54px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=text] { max-width: 120px; }
.checkbox { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.checkbox input { width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; font: 600 14px/1 inherit; cursor: pointer;
  background: var(--primary); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #f8fafc; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn[hidden], [hidden] { display: none !important; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
th { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef2ff; color: var(--primary); }
.badge.green { background: #ecfdf5; color: var(--success); }
.badge.amber { background: #fffbeb; color: var(--warning); }
.badge.red { background: #fef2f2; color: var(--danger); }
.badge.grey { background: #f1f5f9; color: var(--muted); }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.alert.success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert.error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert.warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert.info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

.release-notice {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 14px; margin-bottom: 18px;
  background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 10px;
  color: #065f46; font-size: 13.5px; line-height: 1.4;
}
.release-notice .mono { font-size: 12.5px; }
.release-notice form { display: flex; line-height: 0; }
.release-close {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 20px; line-height: 1; padding: 0 2px; opacity: .55;
}
.release-close:hover { opacity: 1; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--muted);
  font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { transition: opacity .15s ease; }
.tab-panel.is-loading { opacity: .45; }
.tab-panel.is-entering { animation: tab-in .22s ease both; }
@keyframes tab-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tab-panel.is-entering { animation: none; }
}

.kb-summary { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; font-size: 13.5px; }

.faq-card .faq-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.faq-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fff; }
.faq-item.is-new { animation: tab-in .2s ease both; }
.faq-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.faq-head .spacer { flex: 1; }
.faq-question { font-size: 14.5px; }
.faq-answer { font-size: 13.5px; margin-top: 6px; white-space: pre-wrap; }
.faq-form { border-top: 1px solid var(--border); padding-top: 16px; }


pre.code {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 10px;
  overflow-x: auto; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; margin: 0;
  white-space: pre-wrap; word-break: break-all;
}

.transcript { display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 74%; padding: 11px 14px; border-radius: 14px; font-size: 14.5px; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: #f1f5f9; border-bottom-left-radius: 4px; }
.bubble .time { display: block; font-size: 11px; opacity: .7; margin-top: 5px; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 6px; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(140deg, #4f46e5, #0f172a); }
.auth-card { background: #fff; width: 100%; max-width: 400px; border-radius: 16px; padding: 30px; box-shadow: 0 24px 60px rgba(15, 23, 42, .3); }
.auth-card h1 { margin: 0 0 4px; font-size: 21px; }
.auth-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline-form { display: inline; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .sidebar .spacer, .sidebar .who { display: none; }
  .main { padding: 18px 16px 50px; }
}


/* ---------- app shell motion ---------- */
.app-progress {
  position: fixed; top: 0; left: 0; z-index: 2000;
  height: 3px; width: 0; opacity: 0;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  box-shadow: 0 0 10px rgba(79, 70, 229, .45);
  pointer-events: none;
}

.page.is-leaving {
  opacity: 0; transform: translateY(-4px);
  transition: opacity .14s ease, transform .14s ease;
}
.page.is-entering > *,
.page.is-entering .grid > *,
.page.is-entering .sites-layout > * {
  animation: rise .4s cubic-bezier(.2, .7, .2, 1) both;
}
.page.is-entering > *:nth-child(2) { animation-delay: .04s; }
.page.is-entering > *:nth-child(3) { animation-delay: .08s; }
.page.is-entering > *:nth-child(4) { animation-delay: .12s; }
.page.is-entering > *:nth-child(5) { animation-delay: .16s; }
.page.is-entering > *:nth-child(n+6) { animation-delay: .2s; }
.page.is-entering .grid > *:nth-child(2),
.page.is-entering .sites-layout > *:nth-child(2) { animation-delay: .07s; }
.page.is-entering .grid > *:nth-child(3) { animation-delay: .12s; }
.page.is-entering .grid > *:nth-child(4) { animation-delay: .17s; }
.page.is-entering tbody tr { animation: fade .35s ease both; animation-delay: .12s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sidebar a.nav { transition: background .2s ease, color .2s ease, transform .15s ease; }
.sidebar a.nav:active { transform: scale(.98); }

.btn { transition: background .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease, opacity .15s ease; }
.btn:active { transform: scale(.97); }
.btn.is-busy { opacity: .7; cursor: progress; }

.card { transition: box-shadow .2s ease; }

.is-collapsing {
  overflow: hidden; opacity: 0;
  margin-top: 0 !important; margin-bottom: 0 !important;
  padding-top: 0 !important; padding-bottom: 0 !important;
  transition: height .28s ease, opacity .2s ease, margin .28s ease, padding .28s ease;
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed; top: 16px; right: 16px; z-index: 1800;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 260px; max-width: 380px; padding: 12px 10px 12px 14px;
  background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 12px; box-shadow: 0 12px 30px rgba(15, 23, 42, .14);
  font-size: 14px; line-height: 1.4;
  opacity: 0; transform: translateX(18px);
  transition: opacity .22s ease, transform .26s cubic-bezier(.2, .8, .2, 1);
}
.toast.show { opacity: 1; transform: none; }
.toast.hide { opacity: 0; transform: translateX(18px); }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast-text { flex: 1; }
.toast-close {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 0 2px;
}

/* ---------- confirm modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1500;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .18s ease;
}
.modal-overlay.open { opacity: 1; }
.modal {
  width: 100%; max-width: 400px; padding: 22px;
  background: #fff; border-radius: 14px; box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
  transform: translateY(10px) scale(.96);
  transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
.modal-overlay.open .modal { transform: none; }
.modal-text { margin: 0 0 18px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 600px) {
  .toasts { left: 12px; right: 12px; }
  .toast { min-width: 0; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- website sync & products ---------- */
.sync-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sync-row input[type=text] { flex: 1 1 260px; }
.sync-row .checkbox { margin: 0; font-weight: 500; }
.sync-progress { margin-top: 14px; }
.sync-bar { height: 8px; border-radius: 999px; background: #eef2ff; overflow: hidden; }
.sync-bar span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: inherit; transition: width .35s ease;
}
.sync-label { font-size: 13px; margin-top: 6px; }
.sync-status { font-size: 13.5px; margin: 14px 0 0; }
.sync-error { font-size: 13.5px; color: var(--danger); margin: 6px 0 0; }
.cron-line { margin: 10px 0 0; }
.cron-line .mono { word-break: break-all; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .product-total { font-weight: 500; font-size: 14px; margin-left: 4px; }
.product-search { max-width: 300px; padding: 8px 12px; }
.product-list { display: flex; flex-direction: column; }
.product-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 14px;
  padding: 10px 2px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.product-row:last-child { border-bottom: 0; }
.product-row.is-new { animation: fade .25s ease both; }
.product-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-name a { color: var(--text); text-decoration: none; font-weight: 600; }
.product-name a:hover { color: var(--primary); }
.product-name .mono { margin-left: 8px; font-size: 12px; }
.product-price { font-weight: 600; white-space: nowrap; }
.csv-import {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13.5px;
}

/* ---------- knowledge tabs ---------- */
.seg-tabs {
  display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; margin-bottom: 16px;
  background: #f1f5f9; border-radius: 12px;
}
.seg {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: transparent; cursor: pointer;
  padding: 8px 14px; border-radius: 9px;
  font: 600 14px/1 inherit; color: var(--muted);
  transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}
.seg:hover { color: var(--text); }
.seg.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.seg .count {
  min-width: 22px; padding: 3px 7px; border-radius: 999px;
  background: #e2e8f0; color: var(--muted); font-size: 12px; text-align: center;
}
.seg.active .count { background: #eef2ff; color: var(--primary); }
.kb-pane.is-entering { animation: tab-in .22s ease both; }
.doc-title { font-weight: 600; color: var(--text); text-decoration: none; }
.doc-title:hover { color: var(--primary); }

/* ---------- users ---------- */
.reset-password { position: relative; display: inline-block; }
.reset-password > summary { list-style: none; }
.reset-password > summary::-webkit-details-marker { display: none; }
.reset-password[open] > summary { background: #eef2ff; border-color: #c7d2fe; color: var(--primary); }
.reset-form {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  display: flex; gap: 8px; padding: 10px; width: 300px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .14);
  animation: rise .18s cubic-bezier(.2, .7, .2, 1) both;
}
.reset-form input { flex: 1; padding: 8px 10px; }
