:root {
  color-scheme: light;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-secondary: #f2f2f7;
  --input: #f5f5f7;

  --text: #1d1d1f;
  --text-secondary: #86868b;
  --text-muted: #a1a1a6;

  --border: rgba(29, 29, 31, 0.1);
  --border-light: rgba(29, 29, 31, 0.06);

  --blue: #087ff5;
  --blue-hover: #006edb;
  --blue-light: rgba(8, 127, 245, 0.12);

  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;

  --card-radius: 28px;
  --medium-radius: 19px;
  --small-radius: 13px;

  --card-shadow: 0 18px 60px rgba(29, 29, 31, 0.06);
  --small-shadow: 0 4px 18px rgba(29, 29, 31, 0.05);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #1d1d1f;
  --surface: #2a2a2d;
  --surface-secondary: #323236;
  --input: #202023;

  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-muted: #77777d;

  --border: rgba(255, 255, 255, 0.12);
  --border-light: rgba(255, 255, 255, 0.07);

  --blue: #4d9bff;
  --blue-hover: #6aabff;
  --blue-light: rgba(77, 155, 255, 0.16);

  --card-shadow: 0 18px 60px rgba(0, 0, 0, 0.2);
  --small-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;

  color: var(--text);
  background: var(--bg);

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "SF Pro Display",
    "SF Pro Text",
    "Helvetica Neue",
    Helvetica,
    Arial,
    sans-serif;

  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  transition:
    color 300ms var(--ease),
    background-color 300ms var(--ease);
}

body::before {
  position: fixed;
  z-index: -1;
  top: -220px;
  right: -180px;
  width: 460px;
  height: 460px;
  border-radius: 50%;
  background: rgba(8, 127, 245, 0.08);
  filter: blur(85px);
  pointer-events: none;
  content: "";
}

body::after {
  position: fixed;
  z-index: -1;
  bottom: -220px;
  left: -180px;
  width: 460px;
  height: 460px;
  border-radius: 50%;
  background: rgba(175, 82, 222, 0.07);
  filter: blur(90px);
  pointer-events: none;
  content: "";
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid var(--blue-light);
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}

/* Авторизация */

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px 18px;
}

.login-card {
  width: min(100%, 650px);
  padding: 62px 52px 42px;
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
  animation: card-enter 650ms var(--ease);
}

.login-logo {
  display: grid;
  width: 66px;
  height: 66px;
  margin-bottom: 42px;
  place-items: center;
  border-radius: 21px;
  color: #ffffff;
  background: linear-gradient(135deg, #087ff5, #5856d6);
  box-shadow: 0 12px 28px rgba(8, 127, 245, 0.25);
}

.login-logo span {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.08em;
}

.login-heading {
  text-align: left !important;
}

.eyebrow,
.section-kicker {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
}

.login-heading h1 {
  margin: 26px 0 12px;
  color: var(--text);
  font-size: clamp(36px, 7vw, 56px);
  font-weight: 700;
  letter-spacing: -0.065em;
  line-height: 1.03;
  text-align: left !important;
}

.login-heading p {
  max-width: 470px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 21px;
  line-height: 1.4;
  text-align: left !important;
}

.login-form {
  display: grid;
  gap: 20px;
  margin-top: 46px;
  text-align: left !important;
}

.field {
  display: grid;
  gap: 10px;
  text-align: left !important;
}

.field > span {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: left !important;
}

.field input {
  width: 100%;
  height: 68px;
  padding: 0 24px;
  border: 1px solid var(--border);
  border-radius: 20px;
  outline: none;
  color: var(--text);
  background: var(--input);
  font-size: 19px;
  text-align: left !important;
}

.field input:focus {
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: 0 0 0 5px var(--blue-light);
}

.primary-button {
  display: inline-flex;
  min-height: 66px;
  align-items: center;
  justify-content: center;
  gap: 25px;
  padding: 0 28px;
  border-radius: 34px;
  color: #ffffff;
  background: var(--blue);
  box-shadow: 0 12px 26px rgba(8, 127, 245, 0.22);
  font-size: 18px;
  font-weight: 600;
  transition:
    background-color 220ms var(--ease),
    transform 220ms var(--ease),
    box-shadow 220ms var(--ease);
}

.primary-button:hover {
  background: var(--blue-hover);
  box-shadow: 0 16px 32px rgba(8, 127, 245, 0.3);
  transform: translateY(-2px);
}

.primary-button:active {
  transform: scale(0.98);
}

.login-button {
  width: 100%;
  margin-top: 18px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 14px;
  text-align: center !important;
}

.login-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 32px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center !important;
}

/* Верхняя панель */

.panel {
  min-height: 100vh;
  animation: fade-in 500ms var(--ease);
}

.topbar {
  display: flex;
  width: min(1380px, calc(100% - 72px));
  min-height: 104px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 14px;
  color: #ffffff;
  background: linear-gradient(135deg, #087ff5, #5856d6);
  font-size: 22px;
  font-weight: 700;
}

.brand-text {
  display: grid;
  gap: 2px;
  text-align: left !important;
}

.brand-text strong {
  font-size: 17px;
  letter-spacing: -0.03em;
}

.brand-text span {
  color: var(--text-secondary);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 11px;
}

.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--small-shadow);
  font-size: 21px;
  transition:
    background-color 220ms var(--ease),
    transform 220ms var(--ease);
}

.icon-button:hover {
  background: var(--input);
  transform: rotate(10deg);
}

.profile-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  gap: 9px;
  padding: 5px 15px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 25px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--small-shadow);
  font-size: 13px;
  font-weight: 600;
}

.profile-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: linear-gradient(135deg, #ff9500, #ff3b30);
}

/* Контент */

.content {
  width: min(1380px, calc(100% - 72px));
  margin: 0 auto;
  padding: 64px 0 32px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 38px;
  text-align: left !important;
}

.hero h1 {
  margin: 17px 0 12px;
  font-size: clamp(38px, 7vw, 62px);
  font-weight: 700;
  letter-spacing: -0.07em;
  line-height: 1;
  text-align: left !important;
}

.hero p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1.4;
  text-align: left !important;
}

.hero-date {
  padding-bottom: 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Статистика */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.stat-card {
  min-height: 145px;
  padding: 23px;
  border: 1px solid var(--border);
  border-radius: var(--medium-radius);
  background: var(--surface);
  box-shadow: var(--small-shadow);
  animation: card-enter 650ms var(--ease) both;
  text-align: left !important;
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left !important;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 14px;
  text-align: left !important;
}

.stat-value {
  display: block;
  margin-top: 23px;
  font-size: 35px;
  font-weight: 700;
  letter-spacing: -0.06em;
  text-align: left !important;
}

/* Рабочая область */

.workspace {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  min-height: 650px;
}

.sidebar-card,
.conversation-card {
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.sidebar-card {
  overflow: hidden;
}

.sidebar-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 27px 24px 19px;
  text-align: left !important;
}

.sidebar-heading h2 {
  margin: 7px 0 0;
  font-size: 25px;
  letter-spacing: -0.05em;
  text-align: left !important;
}

.filter-wrapper {
  padding: 0 17px 17px;
  text-align: left !important;
}

.filter-select,
.status-select {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--small-radius);
  outline: none;
  color: var(--text-secondary);
  background: var(--input);
  font-size: 13px;
  text-align: left !important;
}

.ticket-list {
  max-height: 525px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  text-align: left !important;
}

.ticket-item {
  display: grid;
  width: 100%;
  gap: 8px;
  padding: 18px 21px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  background: transparent;
  text-align: left !important;
  transition:
    background-color 220ms var(--ease),
    padding-left 220ms var(--ease);
}

.ticket-item:hover {
  background: var(--input);
}

.ticket-item.active {
  padding-left: 26px;
  background: var(--blue-light);
  box-shadow: inset 3px 0 0 var(--blue);
}

.ticket-title,
.ticket-meta,
.ticket-date {
  display: block;
  overflow: hidden;
  color: inherit;
  text-align: left !important;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-title {
  font-size: 14px;
  font-weight: 650;
}

.ticket-meta {
  color: var(--text-secondary);
  font-size: 12px;
}

.ticket-date {
  color: var(--text-muted);
  font-size: 11px;
}

.no-tickets {
  display: grid;
  min-height: 180px;
  place-items: center;
  padding: 22px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center !important;
}

/* Окно переписки */

.conversation-card {
  min-width: 0;
  padding: 29px;
  animation: card-enter 800ms var(--ease);
}

.empty-state {
  display: grid;
  min-height: 590px;
  place-items: center;
  align-content: center;
  text-align: center !important;
}

.empty-state h2,
.empty-state p {
  text-align: center !important;
}

.ticket-view {
  min-width: 0;
  text-align: left !important;
}

.conversation-header {
  display: flex;
  min-height: 78px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 21px;
  border-bottom: 1px solid var(--border);
  text-align: left !important;
}

.ticket-header {
  min-width: 0;
  text-align: left !important;
}

.ticket-header h2 {
  margin: 0 0 9px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 24px;
  letter-spacing: -0.045em;
  text-align: left !important;
}

.ticket-header p {
  margin: 5px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
  text-align: left !important;
}

.ticket-header p:last-child {
  margin-top: 16px;
  color: var(--text);
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: left !important;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.messages {
  display: flex;
  min-height: 390px;
  max-height: 445px;
  flex-direction: column;
  align-items: stretch !important;
  gap: 14px;
  padding: 25px 3px;
  overflow-y: auto;
  text-align: left !important;
}

/*
 * Главное исправление:
 * текст внутри сообщений всегда слева.
 * Пузырь агента остаётся справа,
 * но содержимое пузыря не центрируется.
 */

.messages .message,
.messages .message *,
.message,
.message *,
.message-body,
.message-meta {
  text-align: left !important;
}

.message {
  display: block;
  width: fit-content;
  max-width: min(78%, 650px);
  padding: 15px 17px;
  border: 1px solid var(--border);
  border-radius: 19px;
  color: var(--text);
  background: var(--input);
  animation: message-enter 400ms var(--ease) both;
}

.message.user {
  align-self: flex-start !important;
  border-bottom-left-radius: 6px;
}

.message.admin {
  align-self: flex-end !important;
  border-color: rgba(8, 127, 245, 0.12);
  border-bottom-right-radius: 6px;
  background: var(--blue-light);
}

.message.system {
  align-self: center !important;
  color: var(--text-secondary);
  background: var(--input);
  font-size: 13px;
}

.message-body {
  display: block;
  width: 100%;
  color: inherit;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-meta {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  width: 100%;
  margin-top: 9px;
  color: var(--text-muted);
  font-size: 10px;
}

/* Форма ответа */

.reply-form {
  display: grid;
  gap: 13px;
  text-align: left !important;
}

.reply-box {
  padding: 15px 17px 11px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: var(--input);
  text-align: left !important;
}

.reply-box textarea,
.reply-box textarea::placeholder {
  display: block;
  width: 100%;
  min-height: 82px;
  padding: 0;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 14px;
  line-height: 1.55;
  text-align: left !important;
}

.reply-box textarea::placeholder {
  color: var(--text-secondary);
}

.reply-box-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  text-align: left !important;
}

.reply-hint,
.character-count {
  color: var(--text-muted);
  font-size: 11px;
  text-align: left !important;
}

.reply-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 11px;
}

.status-select {
  width: 155px;
}

.send-button {
  min-width: 150px;
  min-height: 48px;
  font-size: 15px;
}

/* Подвал */

.footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 25px 20px 32px;
  color: var(--text-muted);
  font-size: 11px;
  text-align: center !important;
}

/* Анимации */

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(9px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Адаптация */

@media (max-width: 1000px) {
  .workspace {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .profile-name {
    display: none;
  }
}

@media (max-width: 800px) {
  .topbar,
  .content {
    width: min(100% - 36px, 1380px);
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .ticket-list {
    max-height: 320px;
  }
}

@media (max-width: 560px) {
  .login-card {
    padding: 36px 28px 30px;
    border-radius: 27px;
  }

  .login-heading h1 {
    font-size: 39px;
  }

  .login-heading p {
    font-size: 17px;
  }

  .field input {
    height: 60px;
    font-size: 17px;
  }

  .topbar,
  .content {
    width: min(100% - 24px, 1380px);
  }

  .topbar {
    min-height: 82px;
  }

  .content {
    padding-top: 32px;
  }

  .hero {
    display: block;
    margin-bottom: 28px;
  }

  .hero h1 {
    font-size: 40px;
  }

  .hero p {
    font-size: 17px;
  }

  .hero-date {
    padding-top: 15px;
    padding-bottom: 0;
  }

  .stat-card {
    min-height: 115px;
    padding: 17px;
    border-radius: 17px;
  }

  .stat-value {
    font-size: 27px;
  }

  .sidebar-heading {
    padding: 22px 19px 17px;
  }

  .conversation-card {
    padding: 19px 14px;
    border-radius: 23px;
  }

  .conversation-header {
    display: block;
  }

  #conversation-status {
    margin-top: 14px;
  }

  .ticket-header h2 {
    font-size: 21px;
  }

  .messages {
    min-height: 330px;
    max-height: 430px;
    padding: 20px 2px;
  }

  .message {
    max-width: 91%;
  }

  .reply-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .status-select,
  .send-button {
    width: 100%;
  }

  .empty-state {
    min-height: 430px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}