:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #07131d;
  --sidebar-dark: #030a11;
  --sidebar-active: #27d9ff;
  --text: #202327;
  --title: #1c3353;
  --muted: #6f7780;
  --line: #cfd2d6;
  --line-soft: #e8eaed;
  --header: #d8d8dc;
  --field: #ffffff;
  --accent: #27d9ff;
  --accent-dark: #096986;
  --accent-alt: #ff8a00;
  --accent-violet: #c45cff;
  --danger: #b94030;
  --ok: #18724b;
  --warn: #9b5b00;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 72% 8%, rgba(39, 217, 255, 0.08) 0 12px, transparent 13px),
    radial-gradient(circle at 84% 32%, rgba(196, 92, 255, 0.05) 0 18px, transparent 19px),
    linear-gradient(90deg, transparent 0 72px, rgba(4, 24, 38, 0.035) 72px 73px, transparent 73px 145px),
    linear-gradient(0deg, transparent 0 72px, rgba(4, 24, 38, 0.03) 72px 73px, transparent 73px 145px),
    var(--bg);
  background-size: auto, auto, 145px 145px, 145px 145px, auto;
  color: var(--text);
}

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

button {
  min-height: 34px;
  border: 1px solid #aeb4ba;
  border-radius: 0;
  background: #f7f7f8;
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.read-only-notice {
  margin: 0 0 12px;
  border-left: 4px solid var(--accent);
  background: #eef6fb;
  color: #28445e;
  padding: 10px 12px;
  font-weight: 700;
}

body.designer-readonly .style-builder-editor,
body.designer-readonly .brand-preview {
  opacity: 0.86;
}

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

button.is-saving {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

button.is-saving::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: #ffffff;
  animation: profiletool-spin 0.75s linear infinite;
}

button.is-confirming {
  position: relative;
  border-color: var(--ok);
  background: #e8f6ef;
  color: var(--ok);
  animation: profiletool-confirm-pulse 0.42s ease-out;
}

button.is-confirming::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  width: 7px;
  height: 13px;
  border: solid var(--ok);
  border-width: 0 2px 2px 0;
  transform: translateY(-58%) rotate(45deg);
}

@keyframes profiletool-confirm-pulse {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

.save-feedback {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 3000;
  display: inline-flex;
  min-width: 220px;
  align-items: center;
  gap: 10px;
  border: 1px solid #9fb7ca;
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.2);
  padding: 12px 14px;
  font-weight: 700;
}

.save-feedback[hidden] {
  display: none;
}

.save-feedback-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: profiletool-spin 0.75s linear infinite;
}

.save-feedback.done {
  border-color: rgba(24, 114, 75, 0.35);
}

.save-feedback.error {
  border-color: rgba(185, 64, 48, 0.35);
}

.save-feedback.done .save-feedback-spinner {
  border-color: var(--ok);
  animation: none;
}

.save-feedback.error .save-feedback-spinner {
  border-color: var(--danger);
  animation: none;
}

.save-feedback.done .save-feedback-spinner::after {
  content: "";
  display: block;
  width: 8px;
  height: 4px;
  margin: 4px 0 0 3px;
  border-left: 2px solid var(--ok);
  border-bottom: 2px solid var(--ok);
  transform: rotate(-45deg);
}

@keyframes profiletool-spin {
  to {
    transform: rotate(360deg);
  }
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #bfc4c9;
  border-radius: 0;
  background: var(--field);
  color: var(--text);
  padding: 8px 9px;
  outline: none;
}

input[type="color"] {
  min-height: 40px;
  padding: 3px;
  cursor: pointer;
  background:
    linear-gradient(135deg, transparent 0 12px, rgba(0, 0, 0, 0.06) 12px 13px, transparent 13px),
    var(--field);
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.24);
}

input[type="color"]::-moz-color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.24);
}

.color-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.color-control input[type="color"] {
  min-width: 0;
}

.color-preview {
  display: grid;
  width: 42px;
  height: 40px;
  place-items: center;
  border: 1px solid #aeb4ba;
  background: var(--color-preview, #ffffff);
  color: #fff;
  font-size: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.72);
}

.color-preview::after {
  content: "";
  width: 16px;
  height: 16px;
  border: 1px solid rgba(0, 0, 0, 0.32);
  background: var(--color-preview, #ffffff);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(45, 140, 203, 0.22);
}

label {
  display: grid;
  gap: 5px;
  color: #34383d;
  font-size: 0.9rem;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.designer-shell {
  display: grid;
  grid-template-columns: 112px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  justify-items: center;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  background:
    radial-gradient(circle at 45% 8%, rgba(39, 217, 255, 0.24), transparent 34%),
    linear-gradient(180deg, #071927 0%, #04101a 45%, #02070d 100%);
  color: #fff;
  border-right: 1px solid rgba(39, 217, 255, 0.18);
  box-shadow: 14px 0 38px rgba(4, 18, 30, 0.18);
}

.brand {
  display: grid;
  place-items: center;
  min-height: 116px;
  padding: 12px 8px 4px;
}

.brand-mark {
  position: relative;
  display: grid;
  width: 92px;
  height: 102px;
  place-items: center;
  overflow: hidden;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.profiletool-home-link {
  position: relative;
  display: grid;
  width: 52px;
  height: 58px;
  place-items: center;
  margin: 0 auto 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #ffffff;
  text-decoration: none;
}

.profiletool-home-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav {
  display: grid;
  width: 100%;
  gap: 2px;
  align-content: start;
  justify-items: center;
  padding-top: 2px;
}

.nav button {
  display: grid;
  width: 94px;
  min-height: 62px;
  justify-items: center;
  align-content: center;
  gap: 3px;
  border: 0;
  border-left: 0;
  background: transparent;
  color: rgba(236, 250, 255, 0.88);
  padding: 5px 4px 6px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 650;
}

.nav button:hover,
.nav button.active {
  color: #ffffff;
  background: rgba(39, 217, 255, 0.08);
}

.nav button.nav-action.active {
  background: transparent;
}

.nav-separator {
  width: 56px;
  height: 2px;
  margin: 7px 0 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-alt), var(--accent-violet));
  box-shadow: 0 0 12px rgba(39, 217, 255, 0.58);
}

.nav-icon {
  position: relative;
  display: grid;
  width: 42px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: currentColor;
}

.nav button:hover .nav-icon,
.nav button.active .nav-icon,
.profiletool-home-link:hover {
  background: rgba(39, 217, 255, 0.08);
  box-shadow:
    inset 0 0 0 1px rgba(39, 217, 255, 0.38),
    0 0 18px rgba(39, 217, 255, 0.22);
}

.nav-icon svg,
.profiletool-home-link svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.portal-box {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 14px 4px 16px;
  align-self: end;
  border-bottom: 28px solid var(--sidebar-active);
  color: #fff;
  font-size: 0.72rem;
  text-align: center;
}

.portal-avatar {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border: 4px solid #fff;
  border-radius: 50%;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: 34px 38px 28px 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 26px;
  border-bottom: 1px solid rgba(9, 105, 134, 0.16);
  padding-bottom: 18px;
}

.topbar h1 {
  margin: 0 0 12px;
  color: #11243d;
  font-size: 2.15rem;
  font-weight: 650;
  line-height: 1.05;
}

.topbar p {
  margin: 0;
  color: #4e6175;
  font-size: 1.45rem;
  font-weight: 300;
}

.topbar-actions {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.play-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: #fff;
  padding: 0 13px 0 10px;
  font-weight: 700;
  white-space: nowrap;
}

.play-action:hover {
  border-color: #155b82;
  background: var(--accent-dark);
  color: #fff;
}

.play-action svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.secondary-play {
  border-color: #aeb4ba;
  background: #ffffff;
  color: var(--accent-dark);
}

.secondary-play:hover {
  border-color: var(--accent-dark);
  background: rgba(45, 140, 203, 0.08);
  color: var(--accent-dark);
}

.language-control {
  min-width: 132px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.language-control select {
  min-height: 34px;
  padding: 6px 8px;
}

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

.inline-select-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px 38px 38px 38px;
  gap: 8px;
  align-items: center;
}

.icon-action {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1;
}

.icon-action svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.actions {
  justify-content: flex-end;
  padding-top: 8px;
}

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

.content.hidden {
  display: none;
}

#configurations > .panel {
  grid-column: 1 / -1;
}

.data-layout {
  grid-template-columns: minmax(390px, 500px) minmax(480px, 1fr);
}

.data-layout .mapping-panel {
  grid-column: 1 / -1;
}

.mode-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: #f7f7f8;
  padding: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.mode-pill {
  display: inline-grid;
  min-width: 116px;
  min-height: 28px;
  place-items: center;
  border: 1px solid var(--accent-dark);
  background: rgba(45, 140, 203, 0.1);
  color: var(--accent-dark);
  font-weight: 800;
}

.panel {
  display: grid;
  gap: 13px;
  align-content: start;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  padding: 14px;
}

.panel h3 {
  margin: -14px -14px 2px;
  border-bottom: 1px solid #bfc2c6;
  background: var(--header);
  color: #15191d;
  padding: 12px 13px;
  font-size: 0.96rem;
  font-weight: 700;
}

.portal-login-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.portal-login-dialog::backdrop {
  background: rgba(244, 246, 247, 0.88);
  backdrop-filter: blur(3px);
}

.portal-login-dialog form {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.portal-login-dialog h2 {
  margin: -16px -16px 2px;
  border-bottom: 1px solid #bfc2c6;
  background: var(--header);
  color: #15191d;
  padding: 13px 16px;
  font-size: 1rem;
}

.portal-login-dialog footer {
  justify-content: flex-end;
}

.ai-style-action {
  color: #0b6374;
  border-color: #76dff1;
  background: #e8fbff;
}

.ai-style-dialog {
  width: min(980px, calc(100vw - 32px));
}

.ai-style-dialog form {
  max-height: min(760px, calc(100vh - 40px));
}

.ai-style-map {
  display: grid;
  gap: 6px;
  overflow: auto;
  max-height: 520px;
  padding-right: 2px;
}

.ai-style-grid {
  display: grid;
  grid-template-columns: minmax(170px, 1.15fr) minmax(82px, 0.42fr) minmax(110px, 0.5fr) minmax(190px, 1fr) minmax(190px, 1fr) minmax(86px, 0.38fr);
  gap: 8px;
  align-items: center;
  border: 1px solid #d4d9de;
  background: #f8fafb;
  padding: 8px;
}

.ai-style-grid:not(.is-left-right) [data-ai-right-field] {
  visibility: hidden;
}

.ai-style-grid-head {
  position: sticky;
  top: 0;
  z-index: 1;
  border-color: #bfc2c6;
  background: var(--header);
  color: #15191d;
  font-weight: 800;
}

.ai-style-grid strong {
  color: var(--text);
}

.ai-style-grid small {
  color: var(--muted);
  font-weight: 700;
}

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

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

.check input {
  width: auto;
}

.status-list {
  display: grid;
  gap: 8px;
}

.status-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  padding: 9px;
  background: #fff;
}

.status-row > span {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 50%;
  font-size: 0.74rem;
  font-weight: 800;
}

.status-row.ok > span {
  background: rgba(24, 114, 75, 0.12);
  color: var(--ok);
}

.status-row.warn > span {
  background: rgba(155, 91, 0, 0.12);
  color: var(--warn);
}

.status-row strong,
.status-row small {
  display: block;
}

.status-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.profile-preview canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  background: #fff;
}

.brand-preview {
  display: flex;
  align-items: center;
  min-height: 170px;
  gap: 14px;
}

.brand-preview-logo {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 800;
  clip-path: polygon(50% 0, 93% 24%, 93% 76%, 50% 100%, 7% 76%, 7% 24%);
}

.brand-preview-logo img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.brand-preview h3 {
  margin: 0;
}

.brand-preview p {
  margin: 4px 0 0;
  color: var(--muted);
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 400;
}

.mapping-table {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-bottom: 0;
}

.mapping-row {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(240px, 1fr);
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 9px;
  background: #fff;
}

.mapping-row:nth-child(odd) {
  background: #f7f7f8;
}

.mapping-label {
  display: grid;
  gap: 3px;
}

.mapping-title {
  color: var(--text);
  font-weight: 700;
}

.mapping-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
}

.mapping-required {
  color: var(--danger);
  font-weight: 800;
}

.style-association-list {
  display: grid;
  gap: 8px;
  min-height: 48px;
  margin: 4px 0 12px;
}

.style-association-list .muted {
  margin: 0;
}

.style-association-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  border: 1px solid #cfd3d8;
  background: #f7f8f9;
  padding: 9px 10px;
}

.style-association-item strong {
  display: block;
  color: var(--text);
  font-size: 0.9rem;
}

.style-association-item small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.style-association-order {
  display: flex;
  gap: 4px;
}

.style-association-order button {
  width: 28px;
  min-height: 28px;
  border: 1px solid #b8c0c8;
  background: #ffffff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.style-association-order button:disabled {
  color: #a7afb7;
  background: #eef1f3;
  cursor: default;
}

.style-builder-panel {
  grid-column: 1 / -1;
}

.style-builder-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.style-builder-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.style-builder-toggle-icon {
  font-size: 1.25rem;
  line-height: 1;
  transition: transform 160ms ease;
}

.style-builder-collapsible:not(.is-collapsed) .style-builder-toggle-icon {
  transform: rotate(90deg);
}

.style-builder-collapsible.is-collapsed > :not(h3) {
  display: none;
}

.style-builder-empty {
  color: var(--muted);
  border: 1px dashed #c3c8ce;
  background: #f8f9fa;
  padding: 10px;
}

.style-builder-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid #cfd3d8;
  background: #f7f8f9;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.style-builder-item.is-selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
  background: #eef6f5;
}

.style-builder-item strong {
  display: block;
  color: var(--text);
}

.style-builder-item small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.style-builder-pill {
  border: 1px solid #b8c1ca;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 4px 7px;
}

.style-builder-editor {
  border-top: 1px solid #d7dade;
  padding-top: 14px;
}

.token-builder {
  display: grid;
  gap: 7px;
}

.token-builder-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.token-builder-actions button {
  min-height: 34px;
  padding: 7px 10px;
}

.token-builder textarea {
  min-height: 74px;
  resize: vertical;
}

.field-hint {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.35;
}

.unit-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 6px;
}

.unit-input select {
  padding-left: 8px;
  padding-right: 8px;
}

.style-field-hidden {
  display: none !important;
}

.data-preview {
  display: grid;
  gap: 8px;
}

.data-preview-summary {
  color: var(--muted);
  font-size: 0.82rem;
}

.data-preview-summary span {
  display: block;
  margin-top: 3px;
}

.data-preview-table-wrap {
  overflow: auto;
  border: 1px solid #c8cdd2;
  background: #ffffff;
  max-height: 260px;
}

.data-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.data-preview-table th,
.data-preview-table td {
  border-bottom: 1px solid #e1e4e7;
  border-right: 1px solid #e1e4e7;
  padding: 6px 8px;
  text-align: left;
  white-space: nowrap;
}

.data-preview-table th {
  background: #f4f6f7;
  color: var(--text);
  position: sticky;
  top: 0;
  z-index: 1;
}

pre {
  min-height: 180px;
  margin: 0;
  overflow: auto;
  border: 1px solid #bfc4c9;
  background: #f7f7f8;
  color: #202327;
  padding: 10px;
  font-size: 0.82rem;
}

.preview pre {
  min-height: 560px;
}

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

  .sidebar {
    position: static;
    grid-template-rows: auto auto auto;
    gap: 0;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .brand {
    min-height: 70px;
    padding: 8px 8px 2px;
  }

  .brand-mark {
    width: 74px;
    height: 82px;
  }

  .profiletool-home-link {
    height: 48px;
    margin: 4px auto 8px;
  }

  .nav {
    grid-template-columns: repeat(5, 1fr);
  }

  .nav button {
    min-height: 62px;
  }

  .portal-box {
    display: none;
  }

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

  .topbar {
    display: grid;
  }

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

@media (max-width: 620px) {
  .workspace {
    padding: 20px 14px;
  }

  .topbar h1 {
    font-size: 2rem;
  }

  .topbar p {
    font-size: 1.35rem;
  }

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

  .mapping-row {
    grid-template-columns: 1fr;
  }
}
