:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --text: #162033;
  --muted: #8490a3;
  --muted-2: #a4adba;
  --border: #e7ebf1;
  --primary: #0f9f6e;
  --primary-dark: #087a54;
  --primary-soft: #eefaf5;
  --blue: #246bfe;
  --blue-soft: #eff5ff;
  --danger: #c7372f;
  --warning: #e89b18;
  --shadow: 0 18px 44px rgba(24, 35, 56, 0.06);
  --shadow-sm: 0 8px 20px rgba(24, 35, 56, 0.045);
  --radius: 18px;
  --radius-lg: 24px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-dark); text-decoration: none; font-weight: 700; }
a:hover { color: var(--primary); }

.app-shell {
  width: min(1540px, calc(100% - 54px));
  min-height: calc(100vh - 54px);
  margin: 27px auto;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 30px;
  overflow: hidden;
  box-shadow: 0 26px 70px rgba(25, 34, 48, 0.08);
}

.sidebar {
  background: rgba(255,255,255,0.96);
  border-right: 1px solid var(--border);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 16px;
  border-bottom: 1px solid var(--border);
}
.avatar,
.auth-icon,
.account-avatar {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: #0f9f6e;
  color: #ffffff;
  font-weight: 900;
  letter-spacing: -0.02em;
}
.sidebar-profile strong { display: block; font-size: 15px; line-height: 1.2; }
.sidebar-profile small { display: block; color: var(--muted); margin-top: 2px; }
.sidebar-search,
.workspace-search {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 12px;
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--muted-2);
}
.sidebar-search input,
.workspace-search input {
  margin: 0;
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
  min-width: 0;
}
.sidebar-search input:focus,
.workspace-search input:focus { box-shadow: none; }
.sidebar-search input::placeholder,
.workspace-search input::placeholder { color: var(--muted-2); }
.sidebar-nav { display: grid; gap: 4px; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: #7d8796;
  border-radius: 12px;
  font-weight: 750;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.sidebar-nav a span { width: 20px; color: #b1bac6; text-align: center; }
.sidebar-nav a:hover,
.sidebar-nav a.is-active {
  background: #eff2f6;
  color: var(--text);
  transform: translateX(1px);
}
.sidebar-nav a.is-active { box-shadow: inset 3px 0 0 var(--primary); }

.workspace {
  min-width: 0;
  background: #f7f8fb;
  display: flex;
  flex-direction: column;
}
.workspace-topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 28px;
  background: rgba(255,255,255,0.9);
  border-bottom: 1px solid var(--border);
}
.workspace-search { flex: 1; max-width: 560px; background: #fff; }
.workspace-actions { display: flex; align-items: center; gap: 16px; }
.notification-dot { color: #dc3545; font-size: 13px; }
.account-chip { display: flex; align-items: center; gap: 10px; }
.account-avatar { width: 36px; height: 36px; border-radius: 999px; background: #57d690; }
.account-chip strong { display: block; font-size: 13px; }
.account-chip small { display: block; color: var(--muted); font-size: 11px; text-transform: capitalize; }
.inline-form { display: inline; margin: 0; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  padding: 0;
}
.link-button.danger { color: var(--danger); }

.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 28px 42px;
}
.container.narrow { max-width: 860px; }
.container.wide-container { max-width: 1440px; }
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 20px;
}
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 6px;
  font-size: clamp(28px, 3.2vw, 38px);
  line-height: 1.08;
  letter-spacing: -0.045em;
}
h2 { font-size: 22px; letter-spacing: -0.025em; margin-bottom: 0; }
.page-heading p, .auth-card p { color: var(--muted); margin-bottom: 0; }

.panel,
.stat-card,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.panel { padding: 24px; margin-bottom: 22px; }
.panel-heading { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; }

.cards-grid,
.cards-grid.wide {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card { min-height: 112px; padding: 18px; }
.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 14px;
}
.stat-card strong {
  display: block;
  font-size: 34px;
  line-height: 1;
  letter-spacing: -0.05em;
}
.stat-card small { display: block; color: var(--muted); margin-top: 8px; font-size: 13px; }
.stat-card.bot-status { background: #f7fffb; border-color: #d9f2e5; }
.stat-card.bot-status strong { color: #0e8a5e; }

.two-column { display: grid; grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr); gap: 22px; }
.two-column.wide-left { grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 18px; background: #fff; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; border-bottom: 1px solid var(--border); padding: 14px 16px; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; background: #fbfcfe; }
tbody tr:hover { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); text-align: center; padding: 34px; }
.empty.small { padding: 12px; font-size: 13px; }
.actions { display: flex; gap: 10px; align-items: center; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #eaf8f1;
  color: var(--primary-dark);
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}
.badge.urgent { background: #fff4e4; color: #b46b00; }
.badge.muted { background: #f1f5f9; color: #475569; }

.button {
  border: 0;
  border-radius: 13px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  transition: background .16s ease, transform .16s ease, box-shadow .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--primary); color: white; box-shadow: 0 10px 20px rgba(15,159,110,0.16); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { background: #eefaf5; color: var(--primary-dark); border: 1px solid #d9f2e6; }
.button.full { width: 100%; }
.button.tiny { padding: 7px 10px; border-radius: 9px; font-size: 13px; background: #e8f7ef; color: var(--primary-dark); }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.button-row form { margin: 0; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: white;
  color: var(--text);
  font: inherit;
  margin-top: 6px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: #b9dfcb; box-shadow: 0 0 0 4px rgba(15,159,110,0.08); }
textarea { resize: vertical; }
label { font-weight: 760; color: #263246; }
label small { display: block; color: var(--muted); font-weight: 500; margin-top: 6px; }
input:disabled { background: #f8fafc; color: var(--muted); }

.help-text { color: var(--muted); background: #fbfcfe; border: 1px dashed var(--border); border-radius: 14px; padding: 13px; }
.help-text code { display: inline; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
.form-stack { display: grid; gap: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.checkbox { display: flex; align-items: center; gap: 10px; }
.checkbox input { width: auto; margin: 0; }
.filters { display: grid; grid-template-columns: 1fr 220px auto; gap: 12px; margin-bottom: 18px; }
.top-gap { margin-top: 18px; }

.auth-page { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(430px, 100%); padding: 34px; }
.auth-icon { margin-bottom: 18px; }
.auth-footer { padding-top: 0; }

.flash { padding: 13px 15px; border-radius: 14px; margin-bottom: 18px; border: 1px solid var(--border); background: white; }
.flash.success { border-color: #b7e4c7; background: #effaf3; color: #0f5132; }
.flash.error { border-color: #fecaca; background: #fff1f2; color: #991b1b; }

.details-list { display: grid; grid-template-columns: 160px 1fr; gap: 9px 12px; }
.details-list dt { color: var(--muted); font-weight: 780; }
.details-list dd { margin: 0; }
.two-col-details { grid-template-columns: 170px 1fr; }
.chat-log, .conversation-box { display: grid; gap: 12px; max-height: 720px; overflow-y: auto; padding: 4px; }
.chat-bubble { border-radius: 15px; padding: 12px 14px; max-width: 92%; border: 1px solid var(--border); }
.chat-bubble.in { background: #f8fafc; justify-self: start; }
.chat-bubble.out { background: #eaf8f1; justify-self: end; }
.chat-bubble small { color: var(--muted); }
.chat-bubble p { margin: 6px 0 0; white-space: pre-wrap; }
.chat-bubble em { color: var(--danger); display: block; margin-top: 6px; }

.events-list { display: grid; gap: 10px; }
.event-row { border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: grid; gap: 4px; background: #fff; }
.event-row.error { border-color: #fecaca; background: #fff1f2; }
.event-row.warning { border-color: #fed7aa; background: #fff7ed; }
.event-row small { color: var(--muted); }
pre, code { background: #111827; color: #e5e7eb; border-radius: 12px; padding: 12px; display: block; overflow-x: auto; white-space: pre-wrap; }
.menu-preview { min-height: 260px; }
.error-box { text-align: left; }
.centered { text-align: center; }
.footer { text-align: center; padding: 20px 28px 28px; color: var(--muted); font-size: 13px; }

.translation-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.translation-box { border: 1px dashed var(--border); border-radius: 14px; padding: 14px; background: #fbfcfe; }
.translation-box summary { cursor: pointer; font-weight: 800; margin-bottom: 12px; }
.translation-box label { display: block; margin-top: 12px; }
.compact-table th, .compact-table td { padding: 9px 8px; }
.notes-list { display: grid; gap: 12px; }
.note-item { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: #f8fafc; }
.note-item p { margin: 6px 0; white-space: pre-wrap; }
.note-item small { color: var(--muted); }
.mini-list { display: grid; gap: 10px; }
.mini-item { border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: grid; gap: 4px; background: #f8fafc; }
.mini-item span, .lead-card small, .lead-card em { color: var(--muted); }

.pipeline-grid { display: grid; grid-template-columns: repeat(7, minmax(220px, 1fr)); gap: 14px; align-items: start; overflow-x: auto; padding-bottom: 12px; }
.pipeline-column { background: rgba(255,255,255,.72); border: 1px solid var(--border); border-radius: 18px; padding: 14px; min-height: 340px; }
.pipeline-column h2 { font-size: 16px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.pipeline-column h2 span { background: #e8f7ef; color: var(--primary-dark); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.lead-card { display: grid; gap: 5px; background: white; border: 1px solid var(--border); border-radius: 15px; padding: 12px; box-shadow: 0 8px 25px rgba(15,23,42,.06); margin-bottom: 10px; }
.lead-card p { margin: 2px 0; color: var(--text); }
.pipeline-card { padding: 0; overflow: hidden; }
.pipeline-card .card-link { display: grid; gap: 5px; padding: 12px; color: inherit; text-decoration: none; }
.pipeline-card .card-link:hover strong { text-decoration: underline; }
.mini-status-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 0 12px 12px; }
.mini-status-form select { padding: 8px 9px; border-radius: 9px; }
.stack-actions { display: grid; gap: 8px; min-width: 190px; }
.stack-actions form { display: flex; gap: 6px; align-items: center; }
.stack-actions select { padding: 7px 8px; border-radius: 9px; }
.inline-test-form { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(140px, 1fr) auto; gap: 6px; }
.inline-test-form input { margin-top: 0; padding: 8px 9px; border-radius: 9px; }
.info-box { border: 1px solid #bfe8d1; background: #f0fdf4; color: #14532d; border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; }

@media (max-width: 1320px) {
  .app-shell { width: min(100% - 24px, calc(100% - 24px)); grid-template-columns: 245px minmax(0, 1fr); }
  .cards-grid, .cards-grid.wide { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .app-shell { display: block; border-radius: 22px; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sidebar-nav a { justify-content: center; font-size: 13px; padding: 10px 8px; }
  .sidebar-nav a span { display: none; }
  .workspace-topbar { flex-direction: column; align-items: stretch; }
  .workspace-search { max-width: none; }
  .page-heading { flex-direction: column; }
  .cards-grid, .cards-grid.wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column, .two-column.wide-left { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
}
@media (max-width: 760px) { .translation-grid { grid-template-columns: 1fr; } .inline-test-form { grid-template-columns: 1fr; } }
@media (max-width: 620px) {
  .app-shell { width: 100%; min-height: 100vh; margin: 0; border-radius: 0; }
  .container { padding: 22px 16px 34px; }
  .sidebar-profile { align-items: flex-start; }
  .sidebar-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards-grid, .cards-grid.wide, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .panel { padding: 16px; }
  th, td { padding: 10px 9px; }
  .details-list { grid-template-columns: 1fr; }
  .account-chip { display: none; }
}
