:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #737985;
  --line: #dedfdc;
  --accent: #202736;
  --accent-soft: #eceef2;
  --danger: #a33a3a;
  --danger-soft: #fff0f0;
  --success: #1f6f4a;
  --success-soft: #edf9f2;
  --shadow: 0 16px 40px rgba(27, 31, 40, 0.08);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button { cursor: pointer; }

a { color: inherit; }

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.hidden { display: none !important; }

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

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

h1 { margin-bottom: 6px; font-size: clamp(30px, 5vw, 48px); line-height: 1.02; }

h2 { margin-bottom: 4px; font-size: 22px; }

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

.auth-card {
  width: min(440px, 100%);
  margin: 11vh auto 0;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand-block p { color: var(--muted); }

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

label span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #c9cbc8;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
}

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

textarea { min-height: 150px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(32, 39, 54, .12);
  border-color: #7a7f89;
}

.button {
  min-height: 42px;
  padding: 10px 15px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 750;
}

.button:disabled { opacity: .6; cursor: wait; }

.button.primary { color: #fff; background: var(--accent); }

.button.secondary { color: var(--text); background: #fff; border-color: var(--line); }

.button.danger { color: var(--danger); background: var(--danger-soft); border-color: #efc3c3; }

.security-note {
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.message {
  padding: 12px 14px;
  margin-bottom: 18px;
  border-radius: 10px;
  font-size: 14px;
}

.message.error { color: #882727; background: #fff0f0; border: 1px solid #f1c3c3; }

.message.success { color: var(--success); background: var(--success-soft); border: 1px solid #bde3cc; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.topbar h1 { font-size: clamp(34px, 5vw, 58px); }

.toolbar-card, .sidebar-card, .list-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(27, 31, 40, 0.045);
}

.toolbar-card {
  display: flex;
  gap: 14px;
  padding: 14px;
  margin-bottom: 18px;
}

.search-wrap { flex: 1; }

.toolbar-actions { display: flex; gap: 10px; }

.content-grid {
  display: grid;
  grid-template-columns: 235px minmax(0, 1fr);
  gap: 18px;
}

.sidebar-card { padding: 12px; align-self: start; }

.sidebar-title {
  padding: 8px 10px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.filter-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 0;
  border-radius: 9px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.filter-button:hover, .filter-button.active { background: var(--accent-soft); }

.filter-button strong { color: var(--muted); }

.list-card { padding: 20px; min-width: 0; }

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.contact-list { display: grid; }

.contact-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) minmax(180px, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 16px 4px;
  border-bottom: 1px solid var(--line);
}

.contact-row:last-child { border-bottom: 0; }

.contact-name {
  margin: 0 0 5px;
  font-size: 17px;
  font-weight: 800;
}

.contact-meta, .contact-details {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.category-pill {
  display: inline-block;
  padding: 4px 8px;
  margin-top: 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #4f5560;
  font-size: 12px;
  font-weight: 700;
}

.row-actions { display: flex; gap: 8px; }

.empty-state {
  padding: 52px 20px;
  color: var(--muted);
  text-align: center;
}

dialog {
  width: min(720px, calc(100% - 24px));
  border: 0;
  border-radius: 18px;
  padding: 0;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0,0,0,.25);
}

dialog::backdrop { background: rgba(24, 27, 34, .55); }

#contact-form { padding: 24px; }

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 24px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.full-width { grid-column: 1 / -1; }

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}

.dialog-actions-right { display: flex; gap: 10px; margin-left: auto; }

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 1180px); padding-top: 18px; }

  .topbar, .toolbar-card { flex-direction: column; }

  .toolbar-actions { width: 100%; }

  .toolbar-actions .button { flex: 1; }

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

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

  .sidebar-title { grid-column: 1 / -1; }

  .contact-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .row-actions .button { flex: 1; }

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

  .full-width { grid-column: auto; }

  .dialog-actions { flex-direction: column-reverse; }

  .dialog-actions-right { width: 100%; }

  .dialog-actions-right .button { flex: 1; }

  #delete-contact-button { width: 100%; }
}
