:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-soft: #edf4ef;
  --text: #17211b;
  --muted: #5e6b63;
  --line: #d9e2db;
  --accent: #178f55;
  --accent-dark: #0d6f40;
  --accent-soft: #dff4e8;
  --error: #b93333;
  --error-soft: #fae7e4;
  --shadow: 0 20px 45px rgba(22, 38, 29, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #101b15;
  color: #f8fbf8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
}

.brand span {
  margin-top: 3px;
  color: #b9c8bf;
  font-size: 0.82rem;
}

.nav-tabs {
  display: grid;
  gap: 6px;
}

.nav-link {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 8px;
  color: #dbe6df;
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.nav-link.disabled {
  color: rgba(219, 230, 223, 0.45);
  cursor: default;
}

.nav-link.disabled:hover {
  background: transparent;
}

.nav-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  font-weight: 700;
}

.content {
  min-width: 0;
  padding: 48px;
}

.page-section {
  width: min(940px, 100%);
}

.page[hidden] {
  display: none;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.page-copy {
  margin-bottom: 34px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(2.15rem, 6vw, 4.4rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.description {
  max-width: 700px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.6;
}

.join-form {
  display: grid;
  gap: 10px;
  width: min(760px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.join-form label,
.contact-form label,
.contact-import-panel label {
  font-size: 0.94rem;
  font-weight: 700;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  color: var(--text);
  outline: none;
}

input {
  min-height: 48px;
}

select {
  min-height: 48px;
  cursor: pointer;
}

textarea {
  min-height: 150px;
  padding-top: 12px;
  padding-bottom: 12px;
  line-height: 1.45;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #f3f6f4;
  color: var(--text);
  cursor: default;
  opacity: 1;
}

.primary-button {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 174px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

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

.primary-button:active {
  transform: translateY(1px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.field-hint {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.field-hint.error {
  color: var(--error);
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(760px, 100%);
  min-height: 58px;
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 700;
}

.status-panel[hidden] {
  display: none;
}

.status-panel.success {
  border-color: #b9e2ca;
  background: var(--accent-soft);
  color: #145c39;
}

.status-panel.error {
  border-color: #efc7c1;
  background: var(--error-soft);
  color: var(--error);
}

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  width: min(980px, 100%);
  margin-top: 18px;
}

.group-card {
  display: grid;
  gap: 14px;
  min-height: 154px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(22, 38, 29, 0.06);
}

.group-card.importing {
  opacity: 0.78;
}

.group-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.group-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.group-card h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.35;
  letter-spacing: 0;
}

.group-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.group-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.group-meta span,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  color: var(--muted);
}

.group-meta span {
  padding: 6px 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.pv-card-controls {
  display: grid;
  gap: 10px;
}

.pv-card-controls label {
  display: grid;
  gap: 7px;
  font-size: 0.88rem;
  font-weight: 800;
}

.toggle-button.active {
  border-color: #b9e2ca;
  background: var(--accent-soft);
  color: #145c39;
}

.secondary-button {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  color: var(--accent-dark);
  font-weight: 800;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.secondary-button:hover {
  border-color: #a9d7bb;
  background: var(--accent-soft);
}

.secondary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
}

.message-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  width: min(1040px, 100%);
}

.message-card,
.add-message-card {
  min-height: 310px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(22, 38, 29, 0.06);
}

.message-card {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.message-card label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
}

.message-card-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: auto;
}

.danger-button {
  display: inline-grid;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid #efc7c1;
  border-radius: 8px;
  background: #fff9f8;
  color: var(--error);
  font-weight: 800;
  cursor: pointer;
}

.danger-button:hover {
  background: var(--error-soft);
}

.add-message-card {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--accent-dark);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.add-message-card:hover {
  border-color: #a9d7bb;
  background: #fbfdfb;
}

.add-message-plus {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
}

.add-message-card span:last-child {
  color: var(--text);
  font-weight: 800;
}

.contacts-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, 0.75fr);
  gap: 14px;
  width: min(980px, 100%);
  margin-bottom: 22px;
}

.contact-form,
.contact-import-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 164px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(22, 38, 29, 0.06);
}

.contact-import-panel input[type="file"] {
  min-height: 48px;
  padding: 10px;
}

.contacts-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: min(980px, 100%);
  margin-bottom: 10px;
  color: var(--muted);
}

.contacts-summary div {
  display: grid;
  gap: 4px;
}

.contacts-summary strong {
  color: var(--text);
}

.contacts-table-wrap {
  width: min(980px, 100%);
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(22, 38, 29, 0.06);
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
}

.contacts-table th,
.contacts-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.contacts-table th {
  background: #fbfdfb;
  color: var(--muted);
  font-size: 0.84rem;
  text-transform: uppercase;
}

.contacts-table tr:last-child td {
  border-bottom: 0;
}

.contacts-table td {
  font-weight: 700;
}

.pagination-controls {
  display: flex;
  gap: 10px;
  width: min(980px, 100%);
  margin-top: 14px;
}

.pagination-controls .secondary-button {
  width: auto;
  min-width: 120px;
}

.loader {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border: 3px solid #cfe1d5;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 14px;
    padding: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding: 0 2px 10px;
  }

  .nav-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-link {
    grid-template-columns: 24px max-content;
    flex: 0 0 auto;
  }

  .content {
    padding: 32px 18px;
  }

  .page-header {
    display: grid;
    gap: 0;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }

  .contacts-actions {
    grid-template-columns: 1fr;
  }

  .contacts-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .pagination-controls .secondary-button {
    width: 100%;
  }

  .message-card-actions {
    grid-template-columns: 1fr;
  }
}
