:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #d9dde5;
  --text: #1e2430;
  --muted: #657084;
  --accent: #1e5aa7;
  --accent-dark: #17457f;
  --green: #1b6f8f;
  --blue: #1e5aa7;
  --shell-max: 1680px;
  --shell-gutter: max(18px, calc((100vw - var(--shell-max)) / 2));
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

main {
  min-height: calc(100vh - 90px);
}

.htmx-request {
  cursor: progress;
}

.htmx-swapping,
.htmx-settling {
  pointer-events: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
.tab {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
  font-weight: 700;
}

button:hover,
.tab:hover {
  background: var(--accent-dark);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
  background: #fff;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.topbar {
  width: auto;
  max-width: var(--shell-max);
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 14px var(--shell-gutter) 0;
  padding: 10px 12px 10px 16px;
  background: #fff;
  border: 1px solid rgba(30, 90, 167, 0.12);
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(30, 42, 68, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: fit-content;
  padding: 4px 8px 4px 2px;
  color: var(--accent);
}

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.brand-main {
  color: #1e5aa7;
  font-size: 23px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

.brand-divider {
  width: 1px;
  height: 28px;
  background: var(--line);
}

.brand-product {
  color: #263244;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.main-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  color: #526177;
  font-weight: 700;
  white-space: nowrap;
}

.main-nav a:hover {
  background: #eef5ff;
  color: var(--accent-dark);
}

.logout {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: fit-content;
}

.logout button {
  min-height: 38px;
  border-color: #d6e3f6;
  background: #f3f8ff;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 0 14px;
}

.logout button:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border: 1px solid #d6e3f6;
  border-radius: 999px;
  background: #fbfcff;
}

.user-chip strong {
  max-width: 180px;
  overflow: hidden;
  color: #263244;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  padding: 0 8px 0 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip small {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eaf2ff;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.split {
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  width: auto;
  max-width: var(--shell-max);
  height: calc(100vh - 126px);
  margin: 18px var(--shell-gutter) 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(30, 90, 167, 0.12);
  border-radius: 18px;
  box-shadow: 0 12px 34px rgba(30, 42, 68, 0.08);
}

.left-pane,
.content-pane {
  min-height: 0;
}

.content-pane {
  min-width: 0;
  overflow-y: auto;
  background: #f8fafd;
}

.left-pane {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  background: #fff;
  border-right: 1px solid var(--line);
}

.pane-head,
.page-head,
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.pane-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.pane-head p,
.page-head p,
.detail-head p,
small {
  color: var(--muted);
}

.call-list {
  display: grid;
  align-content: start;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.call-row-wrap {
  position: relative;
  border-bottom: 1px solid var(--line);
}

.call-row {
  display: grid;
  gap: 6px;
  padding: 12px 46px 12px 16px;
}

.call-row-wrap:hover .call-row,
.call-row.active {
  background: #f3f7fc;
}

.delete-call-form {
  position: absolute;
  top: 9px;
  right: 10px;
  z-index: 2;
}

.delete-call {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #8b97a8;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.delete-call:hover {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.call-card-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.call-person {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.call-person strong,
.call-person small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-card-head time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.large {
  min-height: 27px;
  padding: 4px 10px;
}

.badge.status-new_call {
  background: #eef1f5;
  color: #536070;
}

.badge.status-feedback_submitted {
  background: #ffe9e9;
  color: #b4232a;
}

.badge.status-in_fix {
  background: #fff3c4;
  color: #8a5b00;
}

.badge.status-needs_manager_check {
  background: #dff2ff;
  color: #12628a;
}

.badge.status-verified {
  background: #e2f7e8;
  color: #1f7a3f;
}

.call-detail {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  padding: 16px;
  min-height: 0;
  height: 100%;
}

.mobile-call-back {
  display: none;
}

.audio {
  width: 100%;
  margin: 12px 0 16px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  min-height: 0;
  height: 100%;
}

.transcript,
.feedback-form,
.panel,
.import-box {
  background: #fff;
  border: 1px solid rgba(30, 90, 167, 0.1);
  border-radius: 14px;
  padding: 14px;
}

.transcript {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
}

.transcript-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.transcript-head h3 {
  margin: 0;
}

.transcript-toggle {
  display: none;
  border: 1px solid rgba(30, 90, 167, 0.18);
  border-radius: 999px;
  background: #eef6ff;
  color: var(--blue);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.feedback-form {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
}

.feedback-form h3 {
  margin-bottom: 8px;
}

.bubble {
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.bubble span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.bubble.user,
.bubble.caller,
.bubble.human {
  background: #edf6ff;
  border-left: 3px solid #7bb7e8;
}

.bubble.agent,
.bubble.assistant {
  background: #f2f7ee;
  border-left: 3px solid #8ec49a;
}

.feedback-form form,
.status-form,
.profile-form,
.user-form,
.user-edit,
.invite-action,
.import-box form {
  display: grid;
  gap: 8px;
}

.score-grid {
  display: grid;
  gap: 6px;
}

.score-slider {
  display: grid;
  gap: 4px;
  padding: 2px 0;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
}

.range-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.range-row output {
  display: grid;
  place-items: center;
  min-height: 24px;
  border-radius: 7px;
  background: #eaf2ff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.range-dots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-right: 36px;
}

.range-dots i {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check input {
  width: auto;
}

.file-picker {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 34px;
  width: 100%;
  overflow: hidden;
  border: 1px solid #d6e3f6;
  border-radius: 8px;
  background: #f3f8ff;
  color: var(--accent-dark);
  font-weight: 800;
  cursor: pointer;
}

.feedback-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.success-action {
  border-color: #b8e2c4;
  background: #e2f7e8;
  color: #1f7a3f;
}

.success-action:hover {
  border-color: #2f8c4d;
  background: #2f8c4d;
  color: #fff;
}

.file-picker:hover {
  border-color: var(--accent);
  background: #eaf2ff;
}

.file-picker input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.page {
  min-height: calc(100vh - 90px);
  padding: 18px;
}

.page.narrow {
  max-width: 920px;
  margin: 0 auto;
}

.users-page {
  width: auto;
  max-width: var(--shell-max);
  margin: 18px var(--shell-gutter) 0;
  padding: 0;
}

.users-page .page-head {
  margin-bottom: 14px;
}

.section-head {
  margin: 18px 0 10px;
}

.section-head h2 {
  margin-bottom: 4px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
}

.table {
  display: grid;
  gap: 7px;
}

.queue-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px 160px 145px;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.queue-row small {
  display: block;
  margin-top: 4px;
}

.status-line,
.score-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.score-strip span {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  background: #fafbfc;
}

.event {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.event span,
.event small {
  display: block;
}

.users-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}

.user-form {
  align-content: start;
}

.user-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  padding: 12px;
}

.user-edit {
  grid-template-columns:
    minmax(140px, 1.1fr)
    minmax(180px, 1.2fr)
    minmax(130px, 0.85fr)
    150px
    minmax(140px, 0.8fr)
    96px
    110px;
  align-items: center;
}

.delete-user {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-color: #ffd6d6;
  border-radius: 999px;
  background: #fff2f2;
  color: #b4232a;
  font-size: 22px;
  line-height: 1;
}

.delete-user:hover {
  border-color: #b4232a;
  background: #b4232a;
  color: #fff;
}

.invite-action button {
  width: 100%;
  background: #fff;
  color: var(--accent-dark);
}

.invite-create {
  display: grid;
  gap: 12px;
  align-content: start;
}

.user-tools {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(360px, 1.15fr);
  gap: 14px;
  align-items: stretch;
}

.user-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.mobile-user-stats {
  display: none;
}

.user-stat-card {
  display: grid;
  align-content: center;
  gap: 10px;
  min-height: 100%;
  padding: 22px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%);
}

.user-stat-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.user-stat-card strong {
  color: var(--accent);
  font-size: 54px;
  line-height: 1;
}

.admin-stat {
  background: linear-gradient(180deg, #f5fbf7 0%, #eaf7ee 100%);
}

.admin-stat strong {
  color: #1f7a3f;
}

.user-create-stack {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 14px;
}

.invite-create h2 {
  margin-bottom: 5px;
  font-size: 16px;
}

.invite-create p,
.user-form p {
  margin: 0;
  color: var(--muted);
}

.user-form h2 {
  margin-bottom: 5px;
  font-size: 16px;
}

.invite-result {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.invite-result p {
  margin: 0;
  color: var(--muted);
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 7px;
}

.attachment-list {
  display: grid;
  gap: 7px;
}

.attachment-list a {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
}

.notice,
.error,
.empty,
.empty-state {
  padding: 12px;
  border-radius: 8px;
}

.notice {
  background: #edf7ef;
  color: var(--green);
}

.error {
  background: #eaf2ff;
  color: var(--accent-dark);
}

.empty,
.empty-state {
  color: var(--muted);
}

pre {
  white-space: pre-wrap;
  font: inherit;
}

@media (max-width: 1050px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .main-nav {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .split,
  .workspace {
    grid-template-columns: 1fr;
  }

  .split {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .workspace {
    grid-template-rows: auto auto;
    overflow: visible;
  }

  .content-pane {
    overflow: visible;
  }

  .call-detail {
    height: auto;
    padding: 16px;
  }

  .transcript,
  .feedback-form {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .left-pane {
    position: static;
    height: auto;
    max-height: 45dvh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .queue-row,
  .user-card,
  .user-edit,
  .invite-create,
  .copy-row,
  .user-tools,
  .user-create-stack {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    width: calc(100% - 20px);
    min-height: 0;
    gap: 6px 8px;
    margin: 6px auto 0;
    border-radius: 12px;
    padding: 6px 8px;
  }

  .split {
    width: calc(100% - 20px);
    margin-top: 6px;
    border-radius: 14px;
  }

  .split.call-list-mode .content-pane {
    display: none;
  }

  .split.call-list-mode {
    height: calc(100dvh - 116px);
    min-height: 0;
    overflow: hidden;
  }

  .split.call-list-mode .left-pane {
    height: 100%;
    max-height: none;
    min-height: 0;
    border-bottom: 0;
  }

  .split.call-list-mode .call-list {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .split.has-call {
    display: block;
    min-height: calc(100dvh - 116px);
  }

  .split.has-call .left-pane {
    display: none;
  }

  .split.has-call .content-pane {
    min-height: calc(100dvh - 116px);
    background: #f8fafd;
  }

  .split.has-call .call-detail {
    min-height: calc(100dvh - 116px);
    padding: 12px;
  }

  .split.has-call .detail-head > div {
    min-width: 0;
  }

  .split.has-call .detail-head .badge {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .mobile-call-back {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    min-height: 36px;
    margin-bottom: 10px;
    padding: 0 12px;
    border: 1px solid rgba(30, 90, 167, 0.18);
    border-radius: 999px;
    background: #eef6ff;
    color: var(--blue);
    font-size: 13px;
    font-weight: 800;
  }

  .users-page {
    width: calc(100% - 20px);
    margin: 10px auto 0;
  }

  .users-page .page-head {
    margin-bottom: 10px;
  }

  .users-page .page-head p {
    display: none;
  }

  .mobile-user-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .user-stats {
    display: none;
  }

  .mobile-user-stats .user-stat-card {
    min-height: 0;
    padding: 12px;
    border-radius: 12px;
  }

  .mobile-user-stats .user-stat-card span {
    font-size: 10px;
    line-height: 1.15;
  }

  .mobile-user-stats .user-stat-card strong {
    font-size: 34px;
  }

  .user-tools {
    gap: 10px;
  }

  .user-create-stack {
    gap: 10px;
  }

  .brand {
    flex: 1 1 auto;
    gap: 6px;
    min-width: 0;
    padding: 0;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .brand-main {
    font-size: 18px;
  }

  .brand-divider {
    height: 20px;
  }

  .brand-product {
    max-width: 126px;
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main-nav {
    gap: 4px;
    order: 3;
    flex-basis: 100%;
    padding-bottom: 0;
  }

  .main-nav a {
    min-height: 28px;
    padding: 0 8px;
    font-size: 12px;
  }

  .logout {
    width: auto;
    gap: 5px;
    justify-content: space-between;
  }

  .logout button {
    min-height: 30px;
    padding: 0 9px;
    font-size: 12px;
  }

  .user-chip {
    min-width: 0;
    max-width: 142px;
    gap: 4px;
    padding: 2px 3px;
  }

  .user-chip small {
    min-height: 24px;
    padding: 0 7px;
    font-size: 10px;
  }

  .user-chip strong {
    max-width: 74px;
    padding: 0 4px 0 0;
    font-size: 12px;
  }

  .transcript-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
  }

  .transcript.is-collapsed {
    padding-bottom: 10px;
  }

  .transcript.is-collapsed .transcript-head {
    margin-bottom: 0;
  }

  .transcript.is-collapsed .transcript-body {
    display: none;
  }
}


/* Действия в шапке списка (переключатель контура + Очередь) */
.pane-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.contour-toggle {
  display: inline-flex;
  gap: 4px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 2px;
}
.contour-toggle .tab {
  border: none;
  border-radius: 5px;
  padding: 6px 12px;
}
.contour-toggle .tab:not(.active) {
  background: transparent;
  color: var(--accent);
}
