/*
  Add new components via js/library.js and mirror any builder-specific tweaks here if needed.
  Extend logo shapes by defining preview tokens in css/site-preview.css and updating js/library.js.
  Add new section or navbar styles by pairing templates in /templates with editor controls in js/library.js.
*/

:root {
  color-scheme: dark light;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0f1116;
  --bg-panel: rgba(255, 255, 255, 0.04);
  --bg-panel-light: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #fbfbfc;
  --text-dim: rgba(255, 255, 255, 0.7);
  --accent: #ffd166;
  --accent-strong: #ff6f61;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: transparent;
}

#auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.85);
  backdrop-filter: blur(14px);
  display: grid;
  place-items: center;
  z-index: 1200;
  padding: 1.5rem;
}

#auth-overlay[hidden] {
  display: none;
}

.auth-card {
  background: rgba(21, 24, 34, 0.92);
  border: 1px solid rgba(94, 252, 232, 0.32);
  border-radius: 18px;
  width: min(360px, 90vw);
  padding: 2rem 2.25rem;
  display: grid;
  gap: 1rem;
  box-shadow: 0 30px 80px rgba(5, 9, 18, 0.55);
}

.auth-card h2 {
  margin: 0;
  font-size: 1.4rem;
  text-align: center;
}

.auth-card label {
  display: grid;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}

.auth-card input {
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
}

.auth-card .primary-button {
  width: 100%;
  margin-top: 0.5rem;
}

.auth-error {
  margin: 0;
  min-height: 1.2rem;
  font-size: 0.85rem;
  color: #ff6a6a;
  text-align: center;
}

body.preview-mode .panel--library,
body.preview-mode .panel--inspector {
  display: none;
}

body.preview-mode .app-main {
  grid-template-columns: 1fr;
}

body.preview-mode .canvas {
  border-color: rgba(94, 252, 232, 0.35);
  box-shadow: 0 25px 70px rgba(9, 13, 24, 0.45);
}

body,
button,
input,
select,
textarea {
  font-family: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background-color: rgba(15, 17, 22, 0.9);
  backdrop-filter: blur(12px);
}

.logo-title {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-title h1 {
  margin: 0;
  font-size: 1.3rem;
}

.logo-title p {
  margin: 0.15rem 0 0 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.app-emoji {
  font-size: 2rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.mode-toggle {
  display: inline-flex;
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.mode-toggle button {
  border-radius: 0;
}

.mode-toggle .is-active {
  background: rgba(94, 252, 232, 0.2);
  color: var(--accent);
}

button {
  border: none;
  border-radius: var(--radius);
  padding: 0.625rem 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-panel-light);
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

button:active {
  transform: translateY(1px);
}

.ghost-button {
  background: var(--bg-panel);
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #0f1116;
}

.app-main {
  display: grid;
  grid-template-columns: 280px minmax(400px, 1fr) 320px;
  gap: 1.25rem;
  padding: 1.5rem;
  overflow: hidden;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.25rem;
  overflow: hidden;
}

.panel--library {
  gap: 1rem;
  padding: 1rem;
}

.tool-switcher {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
  gap: 0.5rem;
}

.tool-button {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  border-radius: calc(var(--radius) - 4px);
  padding: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border 0.2s ease, transform 0.2s ease;
  color: var(--text);
}

.tool-button__icon {
  font-size: 1.25rem;
}

.tool-button__tooltip {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  background: rgba(15, 17, 22, 0.9);
  border-radius: 999px;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  top: calc(100% + 6px);
  white-space: nowrap;
  box-shadow: 0 12px 30px rgba(6, 10, 22, 0.35);
}

.tool-button:hover {
  border-color: rgba(255, 209, 102, 0.35);
  transform: translateY(-2px);
}

.tool-button:hover .tool-button__tooltip {
  opacity: 1;
  transform: translateY(0);
}

.tool-button:focus-visible .tool-button__tooltip {
  opacity: 1;
  transform: translateY(0);
}

.tool-button.is-active {
  border-color: rgba(94, 252, 232, 0.45);
  background: rgba(94, 252, 232, 0.12);
}

.tool-panels {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.tool-panel {
  display: none;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.25s ease;
  height: 100%;
  overflow-y: auto;
  padding: 0.25rem 0.25rem 0.5rem;
}

.tool-panel.is-active {
  display: flex;
}

.tool-panel:focus {
  outline: 2px solid rgba(94, 252, 232, 0.6);
  outline-offset: 2px;
}

.tool-panel__header {
  display: grid;
  gap: 0.35rem;
  position: sticky;
  top: 0;
  background: rgba(15, 17, 22, 0.85);
  backdrop-filter: blur(12px);
  padding: 0.25rem 0.35rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  z-index: 1;
}

.tool-panel__header h2 {
  margin: 0;
  font-size: 1rem;
}

.tool-panel__hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.panel-search {
  width: 100%;
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
}

.panel h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
}

.panel section {
  display: flex;
  flex-direction: column;
}

.component-list {
  display: grid;
  gap: 0.5rem;
}

.component-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
}

.component-card.is-lazy {
  opacity: 0;
  transform: translateY(12px);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.component-card.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.component-card button {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.component-card:hover {
  border-color: var(--border-strong);
}

.layout-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.layout-options button {
  justify-content: flex-start;
  width: 100%;
}

.layout-options button.is-active,
.component-card.is-active {
  background: rgba(255, 209, 102, 0.1);
  border-color: rgba(255, 209, 102, 0.4);
  color: var(--accent);
}

.theme-selector {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

.theme-chip {
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid var(--border);
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border 0.2s ease, transform 0.2s ease;
}

.theme-chip:hover {
  transform: translateY(-2px);
}

.theme-chip__swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.canvas {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 22, 0.8);
  backdrop-filter: blur(8px);
}

.device-toggle {
  display: inline-flex;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  padding: 0.25rem;
  gap: 0.25rem;
}

.device-toggle button {
  padding: 0.4rem 0.85rem;
  background: transparent;
}

.device-toggle button.is-active {
  background: rgba(15, 17, 22, 0.8);
}

#preview-frame {
  width: 100%;
  flex: 1;
  border: none;
  background: #f5f5f8;
}

.panel--inspector {
  position: relative;
}

.structure-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.structure-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.structure-item.is-active {
  border-color: rgba(255, 209, 102, 0.35);
  background: rgba(255, 209, 102, 0.08);
}

.structure-item__actions {
  display: inline-flex;
  gap: 0.35rem;
}

.structure-item__actions button {
  padding: 0.35rem;
  font-size: 0.8rem;
  background: transparent;
}

.structure-item__label {
  font-size: 0.9rem;
}

.properties-form {
  display: grid;
  gap: 1rem;
}

.properties-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.properties-form input,
.properties-form textarea,
.properties-form select {
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.65rem;
  font-size: 0.9rem;
  resize: vertical;
}

.properties-form textarea {
  min-height: 90px;
}

.properties-form .field-row {
  display: flex;
  gap: 0.5rem;
}

.properties-form .field-row > * {
  flex: 1;
}

.properties-form .form-help {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.list-field {
  display: grid;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: calc(var(--radius) - 4px);
  border: 1px dashed var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.list-field h3 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text);
}

.list-field__items {
  display: grid;
  gap: 0.75rem;
}

.list-field__row {
  display: grid;
  gap: 0.5rem;
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid var(--border);
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.1);
}

.list-field__row label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.list-field__row button {
  justify-self: flex-end;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
}

.list-field > button {
  justify-self: flex-start;
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
}

.list-field .form-help {
  margin: 0;
}

.text-replace-form {
  display: grid;
  gap: 0.75rem;
}

.text-replace-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.text-replace-form input[type="text"] {
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.6rem;
}

.text-replace-form button {
  justify-self: flex-start;
  padding: 0.5rem 1rem;
}

.text-replace-form__checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.asset-manager {
  display: grid;
  gap: 0.85rem;
}

.asset-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: calc(var(--radius) - 4px);
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 0.5rem;
}

.asset-card__fields {
  display: grid;
  gap: 0.5rem;
}

.asset-card__actions {
  display: flex;
  gap: 0.5rem;
}

.asset-card input[type="text"] {
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.6rem;
}

.metrics-panel {
  display: grid;
  gap: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: calc(var(--radius) - 4px);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.8rem;
}

.metrics-panel.is-loading {
  opacity: 0.6;
}

.metrics-panel__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  background: rgba(0, 0, 0, 0.12);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.55rem 0.75rem;
}

.metrics-panel__label {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.metrics-panel__value {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.theme-editor {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.theme-editor label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.theme-editor input[type="color"] {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: calc(var(--radius) - 6px);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.performance-report {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: calc(var(--radius) - 4px);
  background: rgba(255, 255, 255, 0.02);
  padding: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.performance-report__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.6rem 0.75rem;
}

.performance-report__item.is-ok {
  border: 1px solid rgba(98, 252, 232, 0.35);
}

.performance-report__item.is-warn {
  border: 1px solid rgba(255, 209, 102, 0.4);
}

.performance-report__item.is-error {
  border: 1px solid rgba(255, 120, 120, 0.4);
}

.media-field {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem;
  border-radius: calc(var(--radius) - 4px);
  border: 1px dashed var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.media-field__controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.media-field__controls input[type="file"] {
  color: var(--text);
}

.media-field__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.media-field__preview {
  width: 100%;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.media-field__preview img {
  width: 100%;
  height: auto;
  display: block;
  max-height: 160px;
  object-fit: contain;
}

.media-field__preview span {
  font-size: 0.85rem;
  color: var(--text-dim);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.global-settings {
  display: grid;
  gap: 0.75rem;
}

.global-settings button {
  width: fit-content;
}

.preset-list {
  display: grid;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.preset-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
}

.preset-item__meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.preset-item__meta small {
  color: var(--text-dim);
}

.preset-item button {
  padding: 0.4rem 0.75rem;
}

dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--bg-panel);
  color: var(--text);
  width: min(480px, 90vw);
}

dialog::backdrop {
  backdrop-filter: blur(8px);
  background: rgba(15, 17, 22, 0.65);
}

@media (max-width: 1280px) {
  .app-main {
    grid-template-columns: 260px 1fr;
    grid-template-rows: minmax(400px, 1fr) minmax(320px, auto);
    grid-template-areas:
      "library canvas"
      "inspector canvas";
  }

  .panel--library {
    grid-area: library;
  }

  .canvas {
    grid-area: canvas;
    min-height: 500px;
  }

  .panel--inspector {
    grid-area: inspector;
  }
}

@media (max-width: 960px) {
  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .panel,
  .canvas {
    min-height: auto;
  }

  .canvas {
    order: 2;
  }
}
