:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.14);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --green: #1d9d4f;
  --green-soft: rgba(52, 199, 89, 0.14);
  --orange: #c45c00;
  --orange-soft: rgba(255, 149, 0, 0.16);
  --red: #d70015;
  --red-soft: rgba(255, 59, 48, 0.12);
  --gray-soft: rgba(118, 118, 128, 0.12);
  --nav: rgba(251, 251, 253, 0.8);
  --segment-active: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8e8e93;
    --line: rgba(255, 255, 255, 0.1);
    --line-strong: rgba(255, 255, 255, 0.18);
    --accent: #2997ff;
    --accent-hover: #47a6ff;
    --accent-soft: rgba(41, 151, 255, 0.16);
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --nav: rgba(22, 22, 23, 0.72);
    --segment-active: #636366;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased;
}

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

[hidden] { display: none !important; }

/* Навигация */

header.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--nav);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}

.bar-inner {
  max-width: 980px;
  margin: 0 auto;
  height: 52px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: linear-gradient(180deg, #3a9bff, #0066d6);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
}

.segmented {
  display: flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--gray-soft);
}

.segmented a {
  padding: 4px 14px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.segmented a:hover { text-decoration: none; }
.segmented a.active {
  background: var(--segment-active);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.nav-end { display: flex; align-items: center; }

/* Раскладка */

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 22px 96px;
}

.page-head { margin-bottom: 32px; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.lead {
  margin: 10px 0 0;
  font-size: 19px;
  line-height: 1.42;
  color: var(--text-2);
}

.head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

section { margin-top: 44px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 0 4px 10px;
}

h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.hint {
  margin: 8px 4px 0;
  font-size: 13px;
  color: var(--text-3);
  line-height: 1.4;
}

.muted { color: var(--text-2); }

/* Карточки и группы */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.group {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.row-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  min-height: 60px;
  position: relative;
  color: var(--text);
}
.row-item + .row-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 20px;
  right: 0;
  border-top: 1px solid var(--line);
}
a.row-item:hover { text-decoration: none; background: var(--surface-2); }

.row-main { flex: 1; min-width: 0; }
.row-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-title.read { font-weight: 500; }
.row-sub {
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-end {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: var(--text-3);
  font-size: 14px;
}
.chevron { color: var(--text-3); font-size: 18px; line-height: 1; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(180deg, #a1a1a6, #7c7c80);
}
.avatar.blue { background: linear-gradient(180deg, #5ac8fa, #007aff); }
.avatar.green { background: linear-gradient(180deg, #5ee08a, #28b04f); }
.avatar.purple { background: linear-gradient(180deg, #c78bff, #8e44ec); }
.avatar.orange { background: linear-gradient(180deg, #ffbd59, #ff8a00); }
.avatar.pink { background: linear-gradient(180deg, #ff8fb1, #ff2d6f); }

.unread-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.unread-dot.off { background: transparent; }

.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-2);
}
.empty-icon { font-size: 36px; margin-bottom: 10px; opacity: 0.6; }
.empty-title { font-size: 19px; font-weight: 600; color: var(--text); }
.empty p { margin: 6px 0 0; }

/* Статусы */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  background: var(--gray-soft);
  color: var(--text-2);
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.orange { background: var(--orange-soft); color: var(--orange); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.blue { background: var(--accent-soft); color: var(--accent); }

/* Кнопки */

button, .button {
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  border: 0;
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  white-space: nowrap;
}
button:hover { background: var(--accent-hover); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }

button.large { padding: 12px 22px; font-size: 17px; }
button.wide { width: 100%; }

button.secondary {
  background: var(--accent-soft);
  color: var(--accent);
}
button.secondary:hover { background: var(--accent-soft); filter: brightness(0.96); }

button.plain {
  background: transparent;
  color: var(--accent);
  padding: 6px 10px;
}
button.plain:hover { background: var(--accent-soft); }

button.danger {
  background: transparent;
  color: var(--red);
  padding: 6px 10px;
}
button.danger:hover { background: var(--red-soft); }

.actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.row-end .actions { flex-wrap: wrap; justify-content: flex-end; }

/* Формы */

.fields { display: grid; gap: 16px; }

.actions-end { margin-left: auto; }

.field { display: grid; gap: 6px; }
.field > span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  padding-left: 2px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

input, textarea, select {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2386868b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}

textarea { min-height: 140px; resize: vertical; line-height: 1.47; }
textarea.short { min-height: 96px; }

input[type="file"] {
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  margin-right: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
}

.form-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.error {
  margin: 0;
  font-size: 14px;
  color: var(--red);
}

.notice {
  margin: 0;
  font-size: 14px;
  color: var(--green);
}

/* Панель, которая раскрывается по кнопке */

.panel {
  margin-bottom: 16px;
  animation: rise 0.22s ease;
}

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

/* Кампании */

.campaign + .campaign { margin-top: 12px; }

.campaign-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.campaign-title { font-weight: 600; font-size: 17px; }
.campaign-meta { font-size: 14px; color: var(--text-2); margin-top: 2px; }

.progress {
  margin-top: 14px;
  height: 6px;
  border-radius: 999px;
  background: var(--gray-soft);
  overflow: hidden;
  display: flex;
}
.progress span { display: block; height: 100%; }
.progress .ok { background: var(--green); }
.progress .bad { background: var(--red); }

.recipients {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.recipient {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
}
.recipient-mail { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipient-error { font-size: 12px; color: var(--red); }

details.more > summary {
  list-style: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--accent);
  margin-top: 10px;
}
details.more > summary::-webkit-details-marker { display: none; }

/* Письмо */

.message-card { padding: 28px; }

.message-from {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.message-from-name { font-weight: 600; }
.message-from-mail { font-size: 14px; color: var(--text-2); }
.message-date { margin-left: auto; font-size: 14px; color: var(--text-3); white-space: nowrap; }

.message-body {
  padding-top: 20px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
}

.attachments {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 20px;
}
.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--text);
}
.attachment:hover { text-decoration: none; border-color: var(--accent); }

.reply-from {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-2);
}
.reply-from strong { color: var(--text); font-weight: 600; }

/* Вход */

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

.login {
  width: min(400px, 100%);
  text-align: center;
}

.login-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 22px;
  border-radius: 16px;
  background: linear-gradient(180deg, #3a9bff, #0066d6);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 30px;
  box-shadow: 0 10px 30px rgba(0, 113, 227, 0.3);
}

.login h1 { font-size: 34px; }
.login .lead { font-size: 17px; margin-bottom: 30px; }
.login form { text-align: left; }

/* Узкий экран */

@media (max-width: 640px) {
  main { padding: 28px 16px 72px; }
  h1 { font-size: 32px; }
  .lead { font-size: 17px; }
  .bar-inner { padding: 0 16px; }
  .brand-text { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 20px; }
  .row-item { padding: 12px 16px; }
  .row-item + .row-item::before { left: 16px; }
  div.row-item { flex-wrap: wrap; }
  div.row-item .row-end { width: 100%; justify-content: space-between; }
  div.row-item .row-end button { padding: 6px 8px; }
  .message-card { padding: 20px; }
  .message-date { display: none; }
}
