:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --soft-line: rgba(60, 60, 67, 0.12);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --danger: #d70015;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.95), transparent 28rem),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: 0; }
h2 { margin-top: 32px; font-size: 21px; font-weight: 650; letter-spacing: 0; }
input, select, textarea, button {
  width: 100%;
  border: 1px solid var(--soft-line);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(0, 113, 227, 0.55);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
  outline: none;
}
textarea { min-height: 120px; resize: vertical; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:active, .button:active { transform: translateY(1px); }
button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}
button.secondary, .button.secondary { background: rgba(255, 255, 255, 0.76); color: var(--text); border-color: var(--soft-line); }
button.secondary:hover, .button.secondary:hover { background: #fff; border-color: var(--line); }
button.danger { background: var(--danger); border-color: var(--danger); }
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 64px;
  padding: 0 30px;
  background: rgba(251, 251, 253, 0.78);
  border-bottom: 1px solid var(--soft-line);
  backdrop-filter: blur(22px) saturate(180%);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 750; color: var(--text); font-size: 18px; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.topbar nav a {
  border-radius: 999px;
  color: var(--muted);
  padding: 7px 11px;
}
.topbar nav a:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
}
.link-button { background: transparent; color: var(--accent); border: 0; padding: 0; }
.account-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.account-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 600;
}
.account-link img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--soft-line);
}
.container { max-width: 1200px; margin: 0 auto; padding: 38px 24px; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head p { margin: 6px 0 0; color: var(--muted); }
.toolbar, .form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  padding: 18px;
  margin-bottom: 22px;
}
.toolbar input:first-child { grid-column: span 2; }
.form-grid label, fieldset { display: grid; gap: 6px; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
fieldset {
  border: 1px solid var(--soft-line);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.55);
}
legend { color: var(--text); padding: 0 4px; }
.check { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel-solid);
  border: 1px solid var(--soft-line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 13px 16px;
  border-bottom: 1px solid var(--soft-line);
  vertical-align: middle;
}
th {
  background: rgba(247, 247, 249, 0.82);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
tbody tr:hover { background: #fafafa; }
tr:last-child td { border-bottom: 0; }
.actions { text-align: right; white-space: nowrap; }
.actions-row { display: flex; gap: 10px; }
.bulk-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.bulk-actions select { width: min(260px, 100%); }
.select-col { width: 44px; text-align: center; }
.select-col input { width: auto; }
.columns-panel { padding: 12px 16px; }
.columns-panel summary { cursor: pointer; font-weight: 600; }
.columns-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}
.menu-filter,
.icon-menu {
  position: relative;
}
.menu-filter summary,
.icon-menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--soft-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  list-style: none;
  padding: 8px 12px;
}
.icon-menu summary {
  width: 38px;
  min-height: 34px;
  padding: 6px;
}
.menu-filter summary::-webkit-details-marker,
.icon-menu summary::-webkit-details-marker { display: none; }
.menu-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  min-width: 240px;
  display: grid;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--soft-line);
  border-radius: 16px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.14);
  padding: 14px;
}
.menu-filter .menu-popover {
  left: 0;
  right: auto;
}
.menu-actions {
  display: flex;
  gap: 8px;
}
.table-menu-cell {
  position: relative;
  width: 54px;
  text-align: right;
}
.chip {
  display: inline-flex;
  margin: 2px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f2f2f7;
  color: #3a3a3c;
  font-size: 12px;
}
.color-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.empty { color: var(--muted); text-align: center; padding: 28px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: 18px;
  margin-bottom: 18px;
  padding: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.panel h2 { margin: 0 0 12px; }
.muted { color: var(--muted); }
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.mapping-grid label { display: grid; gap: 6px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.merge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.merge-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  background: var(--panel-solid);
  border: 1px solid var(--soft-line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.merge-option input { width: auto; margin-top: 4px; }
.merge-option strong,
.merge-option span { display: block; }
.merge-detail { margin-top: 10px; color: var(--muted); }
.contact-photo-row { display: block; }
.contact-photo {
  width: 112px;
  height: 112px;
  object-fit: cover;
  border: 1px solid var(--soft-line);
  border-radius: 18px;
}
.relation-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px;
  backdrop-filter: blur(18px);
}
.login-box p { color: var(--muted); }
.stack { display: grid; gap: 14px; }
.alert {
  background: #fef3f2;
  color: var(--danger);
  border: 1px solid #fecdca;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 14px 0;
}
.notice {
  background: #ecfdf3;
  color: #027a48;
  border: 1px solid #abefc6;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 14px 0;
}
.public-shell {
  display: grid;
  gap: 34px;
}
.public-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.public-nav nav {
  display: flex;
  align-items: center;
  gap: 12px;
}
.public-hero {
  display: grid;
  gap: 18px;
  max-width: 760px;
  padding: 44px 0 18px;
}
.public-hero h1 {
  font-size: 48px;
}
.public-hero p {
  color: var(--muted);
  font-size: 19px;
  line-height: 1.55;
  margin: 0;
}
.public-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.public-grid article,
.legal-page {
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: 18px;
  padding: 22px;
}
.public-grid h2 {
  margin: 0 0 10px;
}
.public-grid p,
.legal-page p {
  color: var(--muted);
  line-height: 1.55;
}
.legal-page {
  max-width: 860px;
}
.legal-page h2 {
  margin-top: 28px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 650;
}
.status-on {
  background: #ecfdf3;
  color: #027a48;
}
.status-paused {
  background: #f2f2f7;
  color: var(--muted);
}
.sync-error {
  max-width: 340px;
  margin-top: 6px;
  white-space: normal;
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 14px 18px; gap: 12px; }
  .topbar nav { flex-wrap: wrap; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .toolbar, .form-grid, .compact, .mapping-grid { grid-template-columns: 1fr; }
  .public-grid { grid-template-columns: 1fr; }
  .public-nav { align-items: flex-start; flex-direction: column; }
  .public-hero h1 { font-size: 38px; }
  .toolbar input:first-child { grid-column: auto; }
  .bulk-actions { align-items: stretch; flex-direction: column; }
  .bulk-actions select, .bulk-actions button { width: 100%; }
  .relation-row { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; }
}
