:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e6e9ef;
  --text: #1f2d3d;
  --muted: #7a8699;

  --brand: #33c892;          /* Teachbase green (logo) */
  --brand-dark: #2ba97b;
  --accent: #2f6ae0;         /* primary blue (buttons, active) */
  --accent-dark: #2559c8;

  --red: #d64545;
  --yellow: #c07d1a;
  --blue: #2f6ae0;
  --green: #1f9d6b;
  --gray: #667085;

  --sidebar-a: #2f3f6b;
  --sidebar-b: #26315200;

  --shadow: 0 1px 2px rgba(20, 30, 55, .04), 0 4px 16px rgba(20, 30, 55, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================ App shell ============================ */
.nav-toggle { display: none; }

.app { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #2f3f6b 0%, #263252 100%);
  color: rgba(255, 255, 255, .85);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 18px; }
.brand-brain { width: 34px; height: 34px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 800; font-size: 18px; color: var(--text); letter-spacing: -.01em; }
.brand-sub { font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-top: 2px; }
.sidebar .brand-name { color: #fff; }
.sidebar .brand-sub { color: rgba(255, 255, 255, .5); }

.sidebar-nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: rgba(255, 255, 255, .4); padding: 16px 12px 5px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px;
  color: rgba(255, 255, 255, .82); font-weight: 500; font-size: 14.5px;
}
.nav-item:hover { background: rgba(255, 255, 255, .08); text-decoration: none; color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, .15); color: #fff; }
.nav-ico { width: 18px; text-align: center; font-size: 15px; }
.nav-count { margin-left: auto; font-size: 12px; background: rgba(255, 255, 255, .13); color: rgba(255, 255, 255, .85); padding: 1px 8px; border-radius: 999px; }
.nav-item.active .nav-count { background: rgba(255, 255, 255, .22); }

.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .1); }
.sidebar-link { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; color: rgba(255, 255, 255, .7); font-size: 13.5px; }
.sidebar-link:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 10px 8px 4px; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #0b3b2a; display: grid; place-items: center; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name { color: #fff; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: rgba(255, 255, 255, .5); font-size: 12px; }
.sidebar-foot .logout { width: 100%; margin-top: 8px; background: transparent; border: 1px solid rgba(255, 255, 255, .18); color: rgba(255, 255, 255, .8); }
.sidebar-foot .logout:hover { background: rgba(255, 255, 255, .1); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { width: 100%; max-width: 1160px; margin: 0 auto; padding: 26px 28px; }
.content-head { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.content-head .search { flex: 1; }
.content-head .search input {
  width: 100%; max-width: 460px;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); font-size: 14px;
}
.content-head .search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 106, 224, .12); }

/* Mobile top bar + off-canvas drawer */
.mobile-bar { display: none; }
.nav-scrim { display: none; }

/* Auth (login) — centred, no sidebar */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }

/* ============================ Components ============================ */
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; font-size: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; background: #f0f2f6; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }

.flash { padding: 11px 15px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.flash-notice { background: #e5f6ef; color: #14724f; border: 1px solid #bce7d4; }
.flash-alert { background: #fdeaea; color: #a12a2a; border: 1px solid #f4c6c6; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tr.contact-row { cursor: pointer; transition: background .1s; }
tr.contact-row:hover { background: #f5f8ff; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-red    { background: #fdeaea; color: var(--red); }
.badge-yellow { background: #fdf3e2; color: var(--yellow); }
.badge-blue   { background: #e8f0fe; color: var(--blue); }
.badge-green  { background: #e5f6ef; color: var(--green); }
.badge-gray   { background: #eef1f5; color: var(--gray); }

.muted { color: var(--muted); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.pill { background: #eef1f5; border-radius: 8px; padding: 4px 10px; font-size: 13px; color: var(--text); }

.page-title { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 18px; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs .tab {
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}
.tabs .tab:hover { text-decoration: none; background: #f0f2f5; }
.tabs .tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  padding: 5px 13px;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--text);
  font-size: 13px;
  border: 1px solid transparent;
}
.chip:hover { text-decoration: none; background: #e2e8f0; }
.chip.active { background: var(--accent); color: #fff; }

small.muted { display: block; margin-top: 4px; font-size: 12px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; }
.pill-warn { background: #fdf3e2; color: var(--yellow); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input[type=text], .field input[type=number], .field input[type=datetime-local],
.field input[type=url], .field input[type=email], .field input[type=password],
.field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 106, 224, .12);
}
.field textarea { min-height: 90px; resize: vertical; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 160px; }

/* Карточка сделки на партнёрской доске: пары «показатель — значение».
   Страница решения, поэтому фактов мало и они крупные. */
.facts { display: flex; flex-wrap: wrap; gap: 10px 32px; margin: 18px 0 4px; }
.facts > div { min-width: 120px; }
.facts dt { font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.facts dd { margin: 0; font-size: 16px; font-weight: 600; }
.facts-title { font-size: 13px; color: var(--muted); font-weight: 500; margin: 20px 0 4px; }

/* Кнопка «Закрепить сделку за собой» разворачивает форму, а не уводит со страницы. */
.btn-wide { display: block; width: 100%; text-align: center; cursor: pointer; list-style: none; }
.btn-wide::-webkit-details-marker { display: none; }
details.claim[open] .btn-wide { border-radius: 10px 10px 0 0; }
.claim-body { padding-top: 16px; }

/* Выбор роли партнёра при закреплении сделки (лидген / пошёл в бой). */
.radio-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; cursor: pointer;
}
.radio-row:hover { border-color: var(--accent); }
.radio-row input { width: 16px; height: 16px; margin-top: 2px; flex: none; }

.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; max-width: 80%; }
.history li.in  { background: #eef1f5; margin-right: auto; }
.history li.out { background: #e8f0fe; margin-left: auto; text-align: right; }
.history .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

.task-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.task-item.done { opacity: .5; text-decoration: line-through; }
.task-item form { display: inline; }
.task-del {
  padding: 2px 9px; font-size: 12px; color: var(--muted);
  background: transparent; border-color: transparent; border-radius: 8px; cursor: pointer;
}
.task-del:hover { color: var(--red); background: #fdeaea; }

.errors { background: #fdeaea; border: 1px solid #f4c6c6; color: #a12a2a; padding: 12px; border-radius: 10px; margin-bottom: 16px; }
.errors ul { margin: 6px 0 0; padding-left: 20px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }

.ai-summary { white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 14px; }

.nav-user { font-size: 13px; }

/* Inline help: a small "?" with a native tooltip, keeps hints out of the layout. */
.hint {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 999px;
  background: #eef1f5; color: var(--muted);
  font-size: 11px; font-weight: 700; cursor: help;
  vertical-align: middle; margin-left: 4px; user-select: none;
}
.hint:hover { background: #e2e8f0; color: var(--text); }

.pill-small { font-size: 11px; padding: 1px 8px; }

/* Portal top bar */
.portal-top {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky; top: 0; z-index: 10;
}
.portal-brand { display: flex; align-items: center; gap: 11px; }

/* Portal admin block: tidy rows with a label above each control group. */
.portal-row { margin-bottom: 14px; }
.portal-row:last-child { margin-bottom: 0; }
.portal-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.portal-inline { display: flex; gap: 10px; align-items: flex-end; }
.portal-inline input[type=text], .portal-inline input[type=password] {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px;
}
.portal-inline .btn { white-space: nowrap; }
.portal-status { margin: 6px 0 0; font-size: 13px; }

/* Communication timeline: AmoCRM tasks + hand-logged touches in one feed. */
.timeline { list-style: none; padding: 0; margin: 18px 0 0; }
.timeline-item { position: relative; padding: 10px 0 10px 16px; border-left: 2px solid var(--border); }
.timeline-item.manual { border-left-color: var(--brand); }
.timeline-item + .timeline-item { margin-top: 2px; }
.timeline-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.timeline-date { font-size: 13px; color: var(--muted); }
.timeline-body { font-size: 14px; }
.timeline-body p { margin: 0; }
.timeline-material { margin: 6px 0 0; font-size: 13px; }
.timeline-del {
  margin-left: auto; padding: 0 7px; font-size: 12px; line-height: 20px;
  color: var(--muted); background: transparent; border-color: transparent;
}
.timeline-del:hover { color: var(--red); background: #fdeaea; }

/* Partner documents: договор / условия / регламент */
.doc-block { margin: 14px 0; padding-top: 14px; border-top: 1px solid var(--border); }
.doc-block:first-of-type { border-top: 0; padding-top: 0; }
.doc-block h3 { margin: 0 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.doc-block p { margin: 0; }

/* ============================ Responsive ============================ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 60; left: -264px; top: 0;
    transition: left .22s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .3);
  }
  .nav-toggle:checked ~ .app .sidebar { left: 0; }
  .nav-toggle:checked ~ .nav-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(15, 20, 40, .45); }

  .mobile-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 16px; background: var(--card); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
  }
  .burger { font-size: 22px; line-height: 1; cursor: pointer; color: var(--text); padding: 2px 6px; }
  .mobile-bar .brand-name { color: var(--text); font-size: 16px; }
  .content { padding: 16px; }
  .content-head { flex-wrap: wrap; }
  .content-head .search input { max-width: none; }
}

@media (max-width: 640px) {
  .container { padding: 14px; }
  .card { padding: 16px; }
  .history li { max-width: 100%; }
  .field-row { flex-direction: column; }

  /* Tables collapse into stacked cards; each cell labelled by its data-label. */
  .stack-table, .stack-table thead, .stack-table tbody,
  .stack-table tr, .stack-table th, .stack-table td { display: block; }
  .stack-table thead { display: none; }
  .stack-table tr {
    border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: 12px; padding: 6px 12px; background: var(--card);
  }
  .stack-table td {
    border: 0; padding: 7px 0;
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right;
  }
  .stack-table td::before {
    content: attr(data-label);
    font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
    text-align: left; flex: 0 0 auto;
  }
  .stack-table td[data-label=""]::before { content: none; }
  .stack-table td[data-label=""] { justify-content: flex-end; }
}
