@font-face {
  font-family: "Montserrat";
  src: url("/fonts/Montserrat.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

@font-face {
  font-family: "Montserrat";
  src: url("/fonts/Montserrat-Medium.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 500;
}

@font-face {
  font-family: "Montserrat";
  src: url("/fonts/Montserrat-SemiBold.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 600;
}

@font-face {
  font-family: "Montserrat";
  src: url("/fonts/Montserrat-Bold.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 700;
}

@font-face {
  font-family: "Ionicons";
  src: url("/fonts/Ionicons.ttf") format("truetype");
  font-display: block;
}

:root {
  color-scheme: light;
  --app-primary: #007aff;
  --utility-border: #d1d1d6;
  --utility-muted: #6d6d72;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body,
button,
input,
select {
  font-family: "Montserrat", sans-serif;
}

body {
  color: #1c1c1e;
  background: #f2f2f7;
  font-size: 14px;
}

button,
select {
  color: inherit;
}

button {
  cursor: pointer;
}

.ionicon {
  font-family: "Ionicons", sans-serif;
  font-style: normal;
  font-weight: normal;
}

.login-gate {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
  background: #f2f2f7;
}

.login-card {
  width: min(100%, 360px);
  padding: 30px;
  border: 1px solid #e5e5ea;
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 8px 35px rgba(0, 0, 0, 0.08);
}

.login-card > img {
  width: 56px;
  height: 56px;
  border-radius: 13px;
}

.login-card h1 {
  margin: 20px 0 6px;
  font-size: 22px;
  line-height: 28px;
}

.login-card > p {
  margin: 0 0 24px;
  color: #6d6d72;
  font-size: 13px;
  line-height: 19px;
}

.login-card label,
.utility-label {
  display: block;
  margin-bottom: 7px;
  color: #6d6d72;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.45px;
  text-transform: uppercase;
}

.password-field {
  display: flex;
  height: 48px;
  overflow: hidden;
  border: 1px solid #c6c6c8;
  border-radius: 11px;
  background: #ffffff;
}

.password-field:focus-within {
  border-color: #007aff;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.password-field input {
  min-width: 0;
  padding: 0 14px;
  border: 0;
  outline: 0;
  flex: 1;
  font-size: 15px;
}

.password-field button {
  width: 46px;
  border: 0;
  color: #8e8e93;
  background: transparent;
  font-size: 20px;
}

.login-error {
  min-height: 18px;
  margin: 7px 0 4px !important;
  color: #ff3b30 !important;
  font-size: 11px !important;
}

.primary-button {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 11px;
  color: #ffffff;
  background: #007aff;
  font-size: 14px;
  font-weight: 700;
}

.utility-header {
  position: relative;
  z-index: 10;
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--utility-border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

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

.utility-brand img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.utility-brand strong,
.utility-brand span {
  display: block;
}

.utility-brand strong {
  font-size: 13px;
}

.utility-brand span {
  margin-top: 2px;
  color: var(--utility-muted);
  font-size: 10px;
}

.utility-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.utility-button {
  display: flex;
  height: 34px;
  align-items: center;
  padding: 0 11px;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  gap: 6px;
  background: #ffffff;
  font-size: 11px;
  font-weight: 600;
}

.utility-button .ionicon {
  font-size: 15px;
}

.api-status {
  display: flex;
  align-items: center;
  margin-right: 4px;
  gap: 6px;
  color: #6d6d72;
  font-size: 10px;
  font-weight: 600;
}

.api-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34c759;
}

.api-status.loading i {
  background: #ff9500;
}

.api-status.error i {
  background: #ff3b30;
}

.workspace {
  display: grid;
  height: calc(100vh - 64px);
  grid-template-columns: 280px minmax(430px, 1fr) minmax(330px, 420px);
}

.configuration-panel {
  overflow-y: auto;
}

.configuration-panel,
.side-panel {
  min-width: 0;
  background: #ffffff;
}

.configuration-panel {
  border-right: 1px solid var(--utility-border);
}

.utility-section {
  padding: 18px;
  border-bottom: 1px solid #e5e5ea;
}

.utility-section select {
  width: 100%;
  height: 40px;
  padding: 0 34px 0 11px;
  border: 1px solid #c6c6c8;
  border-radius: 8px;
  outline: 0;
  background: #ffffff;
  font-size: 12px;
}

.tenant-description {
  min-height: 44px;
  padding-top: 10px;
  color: #6d6d72;
  font-size: 10px;
  line-height: 15px;
}

.tenant-description code {
  display: block;
  overflow: hidden;
  color: #3c3c43;
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title-row h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
}

.link-button {
  padding: 0;
  border: 0;
  color: #007aff;
  background: transparent;
  font-size: 10px;
  font-weight: 600;
}

.screen-selector {
  display: grid;
  padding: 2px;
  border-radius: 8px;
  background: #e5e5ea;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.screen-selector button {
  min-height: 31px;
  border: 0;
  border-radius: 6px;
  color: #6d6d72;
  background: transparent;
  font-size: 9px;
  font-weight: 600;
}

.screen-selector button.active {
  color: #1c1c1e;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.palette-section {
  overflow-y: auto;
}

.color-control {
  display: grid;
  min-height: 37px;
  align-items: center;
  border-top: 1px solid #f2f2f7;
  grid-template-columns: 26px minmax(0, 1fr) 62px;
  gap: 8px;
}

.color-control:first-child {
  border-top: 0;
}

.color-control input[type="color"] {
  width: 24px;
  height: 24px;
  padding: 0;
  overflow: hidden;
  appearance: none;
  border: 1px solid #d1d1d6;
  border-radius: 6px;
  background: transparent;
}

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

.color-control input[type="color"]::-webkit-color-swatch {
  border: 0;
}

.color-control label {
  overflow: hidden;
  font-size: 10px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-value {
  color: #8e8e93;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  text-align: right;
  text-transform: uppercase;
}

.preview-stage {
  display: flex;
  min-width: 0;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #e5e5ea;
}

.device-scaler {
  flex: none;
  transform-origin: center center;
}

.device {
  padding: 12px;
  border-radius: calc(var(--device-radius, 55px) + 12px);
  background: #0c0c0d;
  box-shadow:
    inset 0 0 0 2px #3a3a3d,
    0 24px 70px rgba(0, 0, 0, 0.28);
}

.device-screen {
  position: relative;
  width: var(--device-width, 393px);
  height: var(--device-height, 852px);
  overflow: hidden;
  border-radius: var(--device-radius, 55px);
  background: #ffffff;
}

.device-screen iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.device-screen .app-loader,
.device-screen .preview-error {
  position: absolute;
  inset: 0;
}

.screen-status {
  margin: 10px 0 0;
  color: #6d6d72;
  font-size: 10px;
  line-height: 15px;
}

.screen-status code {
  color: #1c1c1e;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.option-row {
  display: flex;
  align-items: center;
  margin-top: 12px;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
}

.option-row + .utility-label {
  margin-top: 18px;
}

.option-row input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: #007aff;
}

.action-row {
  display: grid;
  margin-top: 12px;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-row .utility-button {
  justify-content: center;
}

.app-loader {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: #8e8e93;
  flex-direction: column;
  gap: 10px;
  font-size: 11px;
}

.app-loader span {
  width: 24px;
  height: 24px;
  border: 2px solid #d1d1d6;
  border-top-color: var(--app-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.preview-error {
  display: grid;
  height: 100%;
  padding: 28px;
  color: #6d6d72;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  place-items: center;
}

.preview-error strong {
  display: block;
  margin-bottom: 8px;
  color: #1c1c1e;
  font-size: 16px;
}

.side-panel {
  display: grid;
  min-height: 0;
  border-left: 1px solid var(--utility-border);
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-tabs {
  display: grid;
  margin: 10px 12px;
  padding: 2px;
  border-radius: 8px;
  background: #e5e5ea;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.panel-tabs button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  color: #6d6d72;
  background: transparent;
  font-size: 10px;
  font-weight: 600;
}

.panel-tabs button[aria-selected="true"] {
  color: #1c1c1e;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.debug-panel {
  display: grid;
  min-height: 0;
  border-top: 1px solid #e5e5ea;
  grid-template-rows: auto auto minmax(0, 1fr);
}

/* --- Marketing ------------------------------------------------------------------------------ */

.marketing-panel {
  min-height: 0;
  overflow-y: auto;
  border-top: 1px solid #e5e5ea;
  background: #f2f2f7;
}

.marketing-controls {
  position: sticky;
  z-index: 2;
  top: 0;
  padding: 14px;
  border-bottom: 1px solid #e5e5ea;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.marketing-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}

.marketing-heading h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
}

.marketing-heading span {
  color: #6d6d72;
  font-size: 9px;
  font-weight: 600;
  text-align: right;
}

.segmented {
  display: grid;
  margin-bottom: 12px;
  padding: 2px;
  border-radius: 8px;
  background: #e5e5ea;
  grid-template-columns: 1fr 1.25fr 0.7fr;
  gap: 2px;
}

.segmented button {
  min-height: 29px;
  border: 0;
  border-radius: 6px;
  color: #6d6d72;
  background: transparent;
  font-size: 9px;
  font-weight: 600;
}

.segmented button[aria-checked="true"] {
  color: #1c1c1e;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.marketing-controls select {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid #c6c6c8;
  border-radius: 8px;
  outline: 0;
  background: #ffffff;
  font-size: 11px;
}

.creative-library {
  margin: 12px;
  padding: 12px;
  border: 1px solid #e5e5ea;
  border-radius: 12px;
  background: #ffffff;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.creative-library .section-title-row {
  margin-bottom: 10px;
}

.upload-button {
  cursor: pointer;
}

.creative-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.creative-empty {
  margin: 0;
  color: #8e8e93;
  font-size: 10px;
}

.creative-tile {
  position: relative;
  margin: 0;
  overflow: hidden;
  border: 1px solid #e5e5ea;
  border-radius: 9px;
  background: #ffffff;
  cursor: grab;
}

.creative-tile img {
  display: block;
  width: 100%;
  height: 64px;
  object-fit: contain;
  background: repeating-conic-gradient(#f2f2f7 0% 25%, #ffffff 0% 50%) 50% / 12px 12px;
}

.creative-tile figcaption {
  padding: 5px 6px 6px;
}

.creative-tile strong,
.creative-tile span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.creative-tile strong {
  font-size: 9px;
}

.creative-tile span {
  margin-top: 1px;
  color: #8e8e93;
  font-size: 8px;
}

.creative-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  opacity: 0;
  color: #ffffff;
  background: rgba(28, 28, 30, 0.72);
  font-size: 12px;
  place-items: center;
  transition: opacity 120ms ease;
}

.creative-tile:hover .creative-delete,
.creative-delete:focus-visible {
  opacity: 1;
}

.marketing-hint {
  margin: 10px 0 0;
  color: #8e8e93;
  font-size: 9px;
  line-height: 13px;
}

.placement-list {
  padding: 0 12px 24px;
}

.marketing-filter {
  display: flex;
  height: 34px;
  align-items: center;
  margin-top: 10px;
  padding: 0 10px;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  gap: 7px;
  color: #8e8e93;
  background: #ffffff;
}

.marketing-filter input {
  min-width: 0;
  border: 0;
  outline: 0;
  flex: 1;
  font-size: 11px;
}

.placement-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 4px 8px;
  color: #6d6d72;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.45px;
  list-style: none;
  text-transform: uppercase;
  cursor: pointer;
}

.placement-group summary::-webkit-details-marker {
  display: none;
}

.placement-group summary::before {
  content: "›";
  margin-right: 6px;
  font-size: 14px;
  line-height: 10px;
  transition: transform 120ms ease;
}

.placement-group[open] summary::before {
  transform: rotate(90deg);
}

.placement-group summary > span:first-child {
  flex: 1;
}

.placement-group-count {
  padding: 2px 7px;
  border-radius: 999px;
  color: #8e8e93;
  background: #e5e5ea;
  font-size: 9px;
  letter-spacing: 0;
}

.placement-group-count.has-filled {
  color: #ffffff;
  background: #007aff;
}

.placement-empty {
  padding: 18px 4px;
}

.placement-card {
  display: grid;
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid #e5e5ea;
  border-radius: 12px;
  background: #ffffff;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.placement-card[data-status="filled"] {
  border-color: rgba(0, 122, 255, 0.35);
}

.is-drop-target {
  border-color: #007aff !important;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.16);
}

.placement-thumb {
  position: relative;
  display: grid;
  height: 64px;
  overflow: hidden;
  border: 1px dashed transparent;
  border-radius: 8px;
  background: #f2f2f7;
  cursor: pointer;
  place-items: center;
}

.placement-thumb:hover,
.placement-thumb:focus-within,
.placement-card.is-drop-target .placement-thumb {
  border-color: #007aff;
}

.placement-upload {
  position: absolute;
  inset: auto 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 0;
  gap: 3px;
  color: #ffffff;
  background: rgba(0, 122, 255, 0.88);
  font-size: 8px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 120ms ease;
}

.placement-upload .ionicon {
  font-size: 10px;
}

.placement-thumb:hover .placement-upload,
.placement-thumb:focus-within .placement-upload,
.placement-card[data-status="empty"] .placement-upload,
.placement-card.is-drop-target .placement-upload {
  opacity: 1;
}

.placement-thumb img {
  display: block;
  max-width: 100%;
  max-height: 64px;
  object-fit: contain;
}

.placement-thumb img.is-placeholder {
  opacity: 0.85;
}

.placement-body header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.placement-body strong {
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.placement-badge {
  flex: none;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.placement-badge.live {
  color: #1d7a3a;
  background: #e3f6e8;
}

.placement-badge.slot {
  color: #8a5300;
  background: #fff1db;
}

.placement-where,
.placement-meta,
.placement-warning,
.placement-origin {
  font-size: 9px;
  line-height: 13px;
}

.placement-where {
  margin: 4px 0 0;
  color: #3c3c43;
}

.placement-meta {
  margin: 3px 0 0;
  color: #8e8e93;
}

.placement-fields {
  display: grid;
  margin-top: 8px;
  gap: 6px;
}

.placement-fields select,
.placement-fields input {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border: 1px solid #d1d1d6;
  border-radius: 7px;
  outline: 0;
  background: #ffffff;
  font-size: 10px;
}

.placement-fields input:disabled {
  color: #aeaeb2;
  background: #f7f7f9;
}

.placement-fields select:focus,
.placement-fields input:focus {
  border-color: #007aff;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.placement-position {
  display: grid;
  align-items: center;
  color: #6d6d72;
  font-size: 9px;
  font-weight: 600;
  grid-template-columns: 1fr 64px;
  gap: 8px;
}

.placement-warning {
  margin: 6px 0 0;
  padding: 6px 8px;
  border-radius: 6px;
  color: #8a5300;
  background: #fff6e8;
}

.placement-body footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  gap: 8px;
}

.placement-origin {
  color: #8e8e93;
}

.debug-header {
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #e5e5ea;
}

.debug-header h2 {
  margin: 0;
  font-size: 12px;
}

.debug-header span {
  display: block;
  margin-top: 3px;
  color: #8e8e93;
  font-size: 9px;
}

.debug-icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  background: #ffffff;
  place-items: center;
}

.debug-icon-button .ionicon {
  margin: 0;
  color: #1c1c1e;
  font-size: 16px;
}

.debug-filter {
  display: flex;
  height: 44px;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid #e5e5ea;
  gap: 7px;
  color: #8e8e93;
}

.debug-filter input {
  min-width: 0;
  border: 0;
  outline: 0;
  flex: 1;
  font-size: 11px;
}

.debug-panel pre {
  min-height: 0;
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: #d4d4d4;
  background: #1c1c1e;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  line-height: 16px;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  padding: 10px 13px;
  border-radius: 9px;
  opacity: 0;
  color: #ffffff;
  background: rgba(28, 28, 30, 0.94);
  font-size: 10px;
  font-weight: 600;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1160px) {
  .workspace {
    grid-template-columns: 270px minmax(430px, 1fr);
  }

  .side-panel {
    min-height: 640px;
    border-top: 1px solid var(--utility-border);
    border-left: 0;
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .utility-header {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    padding: 10px 12px;
    gap: 10px;
  }

  .utility-brand span,
  .api-status,
  .utility-button {
    font-size: 0;
  }

  .utility-button {
    width: 34px;
    padding: 0;
    justify-content: center;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .configuration-panel {
    border-right: 0;
  }

  .workspace {
    height: auto;
  }

  .preview-stage {
    height: 90vh;
    border-top: 1px solid var(--utility-border);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
