:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --primary: #1266f1;
  --primary-ink: #ffffff;
  --success: #0f8a5f;
  --danger: #c53b3b;
  --shadow: 0 18px 50px rgba(23, 32, 51, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 28px;
  border-bottom: 1px solid rgba(217, 225, 236, 0.8);
  background: rgba(246, 248, 251, 0.94);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
}

.brand-mark, .avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 800;
}

.brand small, .eyebrow, label span, .status-pill, .muted {
  color: var(--muted);
}

.brand strong, .brand small { display: block; }
.brand small { margin-top: 2px; font-size: 12px; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link, .status-pill {
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--line));
  border-radius: 999px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--primary) 4%, var(--surface));
  color: var(--primary);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(340px, 0.72fr);
  gap: 20px;
  width: min(1400px, calc(100% - 40px));
  margin: 24px auto 48px;
}

.saved-page {
  width: min(1200px, calc(100% - 40px));
  margin: 24px auto 48px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.editor-panel, .qr-panel { padding: 22px; }
.qr-panel { position: sticky; top: 90px; align-self: start; }

.panel-head, .saved-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.panel-head.compact { margin-bottom: 14px; }

.saved-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 5px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1, h2 { margin-bottom: 0; line-height: 1.05; }
h1 { max-width: 780px; font-size: 48px; }
h2 { font-size: 24px; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label, .phone-section {
  display: grid;
  gap: 7px;
}

label span, .label-row span {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.wide { grid-column: 1 / -1; }

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.phone-fields {
  display: grid;
  gap: 10px;
}

.phone-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.55fr) minmax(82px, 110px) minmax(180px, 1fr) 44px 44px;
  gap: 10px;
  align-items: center;
}

.form-actions, .share-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.primary-button, .ghost-button, .icon-button, .share-links a, .text-button, .circle-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 14px;
  font-weight: 800;
  text-decoration: none;
}

.primary-button {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

.ghost-button, .icon-button, .share-links a, .text-button, .circle-button {
  background: #fff;
  color: var(--ink);
}

.text-button {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--primary);
}

.circle-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--primary);
}

.circle-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.remove-phone {
  color: var(--danger);
}

.icon-button:disabled, .circle-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#formMessage { margin: 0; color: var(--success); font-size: 14px; }

.qr-box {
  display: grid;
  place-items: center;
  min-height: 360px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

#qrCanvas {
  width: min(320px, 74vw);
  height: min(320px, 74vw);
}

.qr-error { margin: 14px; color: var(--danger); text-align: center; }

.phone-card {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.phone-card h3 { margin: 14px 0 6px; font-size: 22px; }
.phone-card p { margin-bottom: 8px; color: var(--muted); overflow-wrap: anywhere; }

.contact-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.contact-item {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(23, 32, 51, 0.06);
}

.contact-main {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.contact-main h3 { margin: 0 0 4px; font-size: 18px; }
.contact-main p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-button.danger { color: var(--danger); }

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .qr-panel {
    position: static;
  }
}

@media (max-width: 700px) {
  .topbar {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .workspace, .saved-page {
    width: min(100% - 24px, 1400px);
    margin-top: 14px;
  }

  .editor-panel, .qr-panel {
    padding: 16px;
  }

  .panel-head, .saved-head {
    align-items: stretch;
    flex-direction: column;
  }

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

  .phone-row {
    grid-template-columns: minmax(0, 1fr) minmax(86px, 0.35fr) 44px 44px;
  }

  .phone-number-input {
    grid-column: 1 / -1;
  }

  h1 {
    font-size: 32px;
  }

  .share-links > * {
    flex: 1 1 100%;
    text-align: center;
  }
}

@media (max-width: 520px) {
  .phone-row {
    grid-template-columns: minmax(0, 1fr) 44px 44px;
  }

  .country-code-input,
  .phone-number-input {
    grid-column: 1 / -1;
  }
}

@media (max-width: 430px) {
  .brand small {
    display: none;
  }

  .nav-link, .status-pill {
    padding: 9px 11px;
  }

  .topbar {
    gap: 12px;
  }
}
