:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #071d20;
  --panel: #102f34;
  --line: rgba(246, 240, 232, 0.14);
  --ink: #f6f0e8;
  --muted: #b7c5c0;
  --teal: #18b9ad;
  --purple: #a78bfa;
  --amber: #e9b45d;
  --coral: #ed7566;
  --green: #7fd66b;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.26);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 86% 6%, rgba(167, 139, 250, 0.16), transparent 30%),
    linear-gradient(135deg, #071d20 0%, #102f34 56%, #221f2b 100%);
  color: var(--ink);
}

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

button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal), #8ad9cb);
  color: #042326;
  cursor: pointer;
  font-weight: 850;
  padding: 0 11px;
}

button:hover,
button:focus-visible {
  background: linear-gradient(135deg, #35c9be, #f0d08d);
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(246, 240, 232, 0.17);
  border-radius: 8px;
  outline: 0;
  background: rgba(5, 18, 21, 0.66);
  color: var(--ink);
  padding: 8px 10px;
}

input,
select {
  min-height: 36px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(233, 180, 93, 0.86);
  box-shadow: 0 0 0 4px rgba(233, 180, 93, 0.14);
}

label {
  display: grid;
  gap: 5px;
  color: #dbe3df;
  font-size: 0.76rem;
  font-weight: 760;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.55rem;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.02rem;
}

h3 {
  margin: 0 0 10px;
  font-size: 0.84rem;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 29, 32, 0.84);
  padding: 14px 26px;
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-weight: 820;
  text-decoration: none;
}

.brand-lockup img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.section-nav {
  display: flex;
  gap: 8px;
}

.nav-link,
.nav-button {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 9px 12px;
  text-decoration: none;
}

.nav-link.active,
.nav-link:hover,
.nav-link:focus-visible,
.nav-button:hover,
.nav-button:focus-visible {
  border-color: rgba(233, 180, 93, 0.72);
  background: rgba(233, 180, 93, 0.1);
  color: var(--ink);
}

.contacts-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 22px 22px 40px;
}

.module-intro,
.panel-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.module-intro {
  margin-bottom: 10px;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--amber);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sync-status {
  max-width: 560px;
  margin: 0;
  border: 1px solid rgba(127, 214, 107, 0.26);
  border-radius: 999px;
  background: rgba(127, 214, 107, 0.08);
  color: #dff5d9;
  font-size: 0.76rem;
  font-weight: 800;
  padding: 8px 12px;
}

.sync-status.waiting {
  border-color: rgba(233, 180, 93, 0.32);
  background: rgba(233, 180, 93, 0.12);
  color: #ffe0a6;
}

.sync-status.error {
  border-color: rgba(237, 117, 102, 0.48);
  background: rgba(237, 117, 102, 0.14);
  color: #ffc1b9;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.summary-card,
.contacts-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 47, 52, 0.74);
  box-shadow: var(--shadow);
}

.summary-card {
  min-height: 86px;
  padding: 14px 16px;
}

.summary-card span {
  color: var(--amber);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  margin: 4px 0 3px;
  font-size: 1.45rem;
  line-height: 1;
}

.summary-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.74rem;
}

.action-card {
  display: grid;
  align-content: center;
  gap: 8px;
}

.contacts-panel {
  padding: 14px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 150px;
  gap: 8px;
}

.contact-list {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}

.contact-row {
  display: grid;
  grid-template-columns: 34px minmax(180px, 1.2fr) minmax(160px, 0.9fr) minmax(160px, 0.9fr) minmax(138px, 0.75fr) minmax(132px, 0.7fr) minmax(120px, auto);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid rgba(246, 240, 232, 0.1);
  border-radius: 8px;
  background: rgba(5, 18, 21, 0.28);
  padding: 5px 8px;
  font-size: 0.78rem;
}

.contact-header {
  min-height: 20px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  padding-top: 0;
  text-transform: uppercase;
}

.avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(233, 180, 93, 0.3);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(24, 185, 173, 0.28), rgba(167, 139, 250, 0.28));
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 900;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.contact-name,
.contact-cell {
  min-width: 0;
}

.contact-name strong,
.contact-cell strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-name small,
.contact-cell small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-row,
.row-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  width: fit-content;
  border: 1px solid rgba(246, 240, 232, 0.14);
  border-radius: 999px;
  background: rgba(246, 240, 232, 0.07);
  color: #dbe3df;
  font-size: 0.62rem;
  font-weight: 850;
  line-height: 1;
  padding: 4px 7px;
}

.badge.family {
  border-color: rgba(233, 180, 93, 0.52);
  background: rgba(233, 180, 93, 0.16);
  color: #ffe0a6;
}

.badge.chess {
  border-color: rgba(167, 139, 250, 0.48);
  background: rgba(167, 139, 250, 0.16);
  color: #ddd3ff;
}

.badge.muted {
  color: rgba(219, 227, 223, 0.68);
}

.row-actions {
  justify-content: flex-end;
}

.row-actions button,
.secondary-button,
.dialog-close,
.method-remove {
  border: 1px solid rgba(246, 240, 232, 0.14);
  background: rgba(246, 240, 232, 0.06);
  color: var(--ink);
}

.row-actions button {
  min-height: 28px;
  padding: 0 9px;
  font-size: 0.7rem;
}

.empty-state {
  border: 1px dashed rgba(246, 240, 232, 0.2);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
}

.contact-dialog {
  width: min(1040px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
}

.contact-dialog::backdrop {
  background: rgba(3, 13, 15, 0.78);
  backdrop-filter: blur(8px);
}

.form-panel {
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #102f34;
  box-shadow: var(--shadow);
  padding: 16px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.dialog-close {
  min-height: 30px;
  font-size: 0.72rem;
}

.contact-form {
  display: grid;
  gap: 10px;
}

.form-section {
  border: 1px solid rgba(246, 240, 232, 0.11);
  border-radius: 8px;
  background: rgba(5, 18, 21, 0.24);
  padding: 12px;
}

.form-grid,
.parent-grid {
  display: grid;
  gap: 9px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.tight {
  align-items: end;
}

.chess-role-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 9px;
}

.chess-role-grid .toggle-row {
  min-height: 32px;
  border: 1px solid rgba(167, 139, 250, 0.2);
  border-radius: 8px;
  background: rgba(167, 139, 250, 0.08);
  padding: 6px 8px;
}

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

.parent-box {
  display: grid;
  gap: 9px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.toggle-row input,
.method-main input {
  width: auto;
  min-height: 0;
}

.method-list,
.account-list {
  display: grid;
  gap: 6px;
}

.account-list {
  margin-top: 9px;
}

.method-row {
  display: grid;
  grid-template-columns: 130px 120px minmax(180px, 1fr) 70px 34px;
  align-items: end;
  gap: 7px;
}

.account-row {
  display: grid;
  grid-template-columns: 140px minmax(180px, 1fr) 70px 34px;
  align-items: end;
  gap: 7px;
}

.method-main {
  align-items: center;
  display: flex;
  gap: 6px;
  min-height: 36px;
}

.method-remove {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
}

@media (max-width: 980px) {
  .app-topbar,
  .module-intro,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .section-nav,
  .toolbar {
    flex-wrap: wrap;
  }

  .summary-grid,
  .form-grid.two,
  .form-grid.three,
  .chess-role-grid,
  .parent-grid {
    grid-template-columns: 1fr;
  }

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

  .contact-row {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .contact-header {
    display: none;
  }

  .row-actions {
    justify-content: flex-start;
  }

  .method-row,
  .account-row {
    grid-template-columns: 1fr;
  }
}
