:root {
  --bg: #faf9f7;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #8a6a3a;
  --line: #e6e2d8;
  --card: #ffffff;
  --error: #b1583b;
  --maxw: 64rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

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

header {
  border-bottom: 1px solid var(--line);
  padding: 1.1rem 2rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  max-width: var(--maxw);
  margin: 0 auto;
  gap: 1rem;
  flex-wrap: wrap;
}

header h1 { margin: 0; font-size: 1.15rem; font-weight: 500; letter-spacing: 0.02em; }
header h1 a { color: var(--fg); }

header nav { display: flex; gap: 1.25rem; align-items: baseline; }
header nav a {
  color: var(--muted);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
header nav a.active { color: var(--fg); }
header nav .muted {
  color: var(--muted);
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2.5rem 2rem;
}

h2 { margin: 0 0 0.5rem 0; font-size: 1.75rem; font-weight: 500; }
h3 {
  margin-top: 2rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--muted);
}

.lead { font-size: 1.05rem; color: var(--muted); margin-bottom: 1.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { padding: 2rem 0; }

code {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.error {
  background: #fdf2ee;
  border: 1px solid #f3c9b8;
  color: var(--error);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

/* ----- Buttons ----- */
button, .btn {
  font: inherit;
  background: var(--fg);
  color: var(--bg);
  border: 1px solid var(--fg);
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-block;
  text-decoration: none;
}
button:hover, .btn:hover { opacity: 0.88; text-decoration: none; }

button.danger { background: var(--error); border-color: var(--error); }
button.primary { background: var(--accent); border-color: var(--accent); }

button.linklike {
  background: none;
  color: var(--muted);
  border: none;
  padding: 0;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
button.linklike:hover { color: var(--fg); }

form.inline { display: inline; }

/* ----- Layout helpers ----- */
.row-between {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ----- Forms ----- */
.form label,
.login label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.form input,
.form select,
.form textarea,
.login input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.form textarea { font-family: inherit; resize: vertical; }
.form input:focus,
.form select:focus,
.form textarea:focus,
.login input:focus {
  outline: none;
  border-color: var(--accent);
}

.checkbox { display: flex; align-items: center; gap: 0.5rem; }
.checkbox input { width: auto; margin: 0; }

.login {
  max-width: 22rem;
  margin: 4rem auto 0;
  background: var(--card);
  border: 1px solid var(--line);
  padding: 2rem;
  border-radius: 8px;
}

.filters {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.filters .inline-label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); }
.filters .grow { flex: 1; min-width: 16rem; }
.filters input, .filters select {
  margin-top: 0.25rem;
  padding: 0.45rem 0.6rem;
  font: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
}

/* ----- Tables ----- */
table.contacts, table.stats {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
table.contacts th, table.contacts td,
table.stats th, table.stats td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
table.contacts thead th {
  background: #f4f1ea;
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
table.contacts tbody tr:last-child td,
table.stats tbody tr:last-child td { border-bottom: none; }
table.stats th { width: 40%; }
table.stats td { text-align: right; font-variant-numeric: tabular-nums; }

/* ----- Badges ----- */
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--line);
  color: var(--fg);
}
.badge.vip { background: var(--accent); color: var(--bg); margin-left: 0.5rem; }
.badge.seg { font-weight: 500; }
.badge.seg-collector { background: #e5d6b8; }
.badge.seg-lead { background: #dde6d6; }
.badge.seg-press { background: #d6dde6; }
.badge.seg-gallery { background: #e6d6dd; }
.badge.seg-family { background: #f0e0d0; }
.badge.seg-other { background: #e0e0e0; }
