/* =========================================================
   Hostinger Downloadable Builder — App chrome (NOT printed)
   Left rail (blocks/outline/settings), stage, right rail (editor)
   ========================================================= */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #EEF0F3;
  font-family: "DM Sans", system-ui, sans-serif;
  color: #18181A;
  height: 100%;
}

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

/* App grid */
.app {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Rails ---------- */
.rail {
  background: #fff;
  border-right: 1px solid #E5E5EA;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.rail--right {
  border-right: 0;
  border-left: 1px solid #E5E5EA;
}
.rail__header {
  padding: 14px 16px;
  border-bottom: 1px solid #E5E5EA;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}
.rail__title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.005em;
}
.rail__close {
  background: transparent;
  border: 0;
  color: #58585E;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.rail__close:hover { background: #F0F0F0; }

.brand-mini {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.brand-mini__wordmark {
  height: 22px;
  width: auto;
  display: block;
  flex: 0 0 auto;
}
.brand-mini__divider {
  width: 1px;
  align-self: stretch;
  background: #E5E5EA;
  margin: 2px 0;
}
.brand-mini__name {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: var(--h-primary-500);
}

.rail__tabs {
  display: flex;
  padding: 8px;
  gap: 4px;
  border-bottom: 1px solid #E5E5EA;
}
.rail__tab {
  flex: 1;
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: #58585E;
}
.rail__tab.is-active {
  background: var(--h-primary-50);
  color: var(--h-primary-700);
}
.rail__tab:not(.is-active):hover { background: #F8F9FA; }

.rail__panel {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 24px;
}
.rail__panel.is-hidden { display: none; }
.rail__hint {
  font-size: 11.5px;
  color: #58585E;
  margin: 0 0 10px;
  line-height: 1.4;
}

/* ---------- Block library ---------- */
.block-library {
  display: grid;
  gap: 6px;
}
.block-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid #E5E5EA;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: all 0.12s ease;
}
.block-item:hover {
  border-color: var(--h-primary-400);
  background: var(--h-primary-50);
}
.block-item__icon {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--h-primary-50);
  border-radius: 5px;
  color: var(--h-primary-500);
}
.block-item__icon svg { width: 16px; height: 16px; }
.block-item__name {
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.2;
  color: #18181A;
}
.block-item__desc {
  font-size: 11px;
  color: #58585E;
  line-height: 1.3;
  margin-top: 2px;
}

/* ---------- Outline ---------- */
.outline { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.outline-item {
  display: grid;
  grid-template-columns: 18px 18px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: grab;
  border: 1px solid transparent;
  font-size: 12px;
}
.outline-item:hover { background: #F8F9FA; border-color: #E5E5EA; }
.outline-item.is-active { background: var(--h-primary-50); border-color: var(--h-primary-200); }
.outline-item.is-dragging { opacity: 0.4; }
.outline-item.is-drop-before { box-shadow: 0 -2px 0 var(--h-primary-500) inset; }
.outline-item.is-drop-after { box-shadow: 0 2px 0 var(--h-primary-500) inset; }
.outline-item__handle { color: #9D9EA4; font-size: 14px; cursor: grab; user-select: none; }
.outline-item__num {
  color: var(--h-primary-500);
  font-weight: 700;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.outline-item__label {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.outline-item__del {
  border: 0;
  background: transparent;
  color: #9D9EA4;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  visibility: hidden;
}
.outline-item:hover .outline-item__del { visibility: visible; }
.outline-item__del:hover { background: #FEE2E2; color: var(--h-danger-500); }

/* ---------- Settings ---------- */
.setting { display: grid; gap: 6px; margin-bottom: 14px; }
.setting label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.005em;
  color: #18181A;
}
.setting label .hint {
  font-weight: 400;
  color: #58585E;
}
.setting input[type="text"],
.setting input[type="url"],
.setting textarea {
  border: 1px solid #E5E5EA;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
.setting input:focus,
.setting textarea:focus,
.tagmgr__label:focus {
  border-color: var(--h-primary-400);
  box-shadow: 0 0 0 3px rgba(103,61,230,0.1);
}
.tagmgr__label:focus { background: #fff; }
.seg {
  display: flex;
  border: 1px solid #E5E5EA;
  border-radius: 6px;
  padding: 2px;
  background: #F8F9FA;
}
.seg button {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #58585E;
  border-radius: 4px;
  cursor: pointer;
}
.seg button.is-active {
  background: #fff;
  color: var(--h-primary-700);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.rule {
  border: 0;
  border-top: 1px solid #E5E5EA;
  margin: 18px 0;
}

/* ---------- Tag manager (in Settings) ---------- */
.tagmgr {
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}
.tagmgr__row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #E5E5EA;
  border-radius: 8px;
  background: #fff;
}
.tagmgr__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.01em;
  white-space: nowrap;
  min-width: 56px;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tagmgr__label {
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px 7px;
  font-size: 12.5px;
  outline: none;
  background: transparent;
  min-width: 0;
}
.tagmgr__label:hover { border-color: #E5E5EA; }
.tagmgr__del {
  width: 22px; height: 22px;
  border: 0;
  background: transparent;
  color: #58585E;
  font-size: 16px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.tagmgr__del:hover { background: #FEE2E2; color: var(--h-danger-500); }

.tagmgr__swatches {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  padding-top: 4px;
}
.tagmgr__sw {
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.08s ease;
}
.tagmgr__sw:hover { transform: scale(1.08); }
.tagmgr__sw.is-active {
  border-color: #18181A;
  box-shadow: 0 0 0 2px #fff inset;
}

/* ---------- Stage (preview) ---------- */
.stage {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: #EEF0F3;
}
.stage__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid #E5E5EA;
  background: #fff;
  min-height: 56px;
}
.stage__title {
  font-size: 13px;
  font-weight: 700;
  color: #18181A;
}
.stage__actions { display: flex; gap: 8px; }
.btn {
  border: 0;
  font-family: inherit;
  font-weight: 600;
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn--primary { background: var(--h-primary-500); color: #fff; }
.btn--primary:hover { background: var(--h-primary-700); }
.btn--ghost {
  background: transparent;
  color: #18181A;
  border: 1px solid #E5E5EA;
}
.btn--ghost:hover { background: #F8F9FA; }

/* ---------- Templates dropdown ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown__toggle .dropdown__caret {
  font-size: 10px;
  margin-left: 2px;
  color: #58585E;
}
.dropdown__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  min-width: 280px;
  background: #fff;
  border: 1px solid #E5E5EA;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(24,24,26,0.08);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.dropdown__menu[hidden] { display: none; }
.dropdown__section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8A8A8E;
  font-weight: 600;
  padding: 8px 10px 4px;
}
.dropdown__item {
  text-align: left;
  background: transparent;
  border: 0;
  font-family: inherit;
  font-size: 12.5px;
  color: #18181A;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.dropdown__item:hover { background: #F4F2FB; color: var(--h-primary-700); }
.dropdown__divider {
  height: 1px;
  background: #E5E5EA;
  margin: 6px 4px;
}

.tpl-actions {
  display: grid;
  gap: 6px;
  margin-top: 4px;
}
.tpl-actions .btn {
  width: 100%;
  justify-content: center;
}

/* Toast for template I/O feedback */
.hg-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #18181A;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 9999;
}
.hg-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.stage__scroll {
  flex: 1;
  overflow-y: auto;
}

/* ---------- Editor (right rail) ---------- */
.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: #58585E;
}
.empty-state__icon {
  width: 48px; height: 48px;
  margin: 0 auto 12px;
  border-radius: 8px;
  background: #F0F0F0;
  display: grid; place-items: center;
  color: #9D9EA4;
}
.empty-state__icon svg { width: 22px; height: 22px; }
.empty-state p { font-size: 12.5px; line-height: 1.5; margin: 0; }

.editor-field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
.editor-field > label {
  font-size: 11.5px;
  font-weight: 700;
  color: #18181A;
}
.editor-field > label .hint { font-weight: 400; color: #58585E; }
.editor-field input[type="text"],
.editor-field input[type="url"],
.editor-field textarea,
.editor-field select {
  border: 1px solid #E5E5EA;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
.editor-field input:focus,
.editor-field textarea:focus,
.editor-field select:focus {
  border-color: var(--h-primary-400);
  box-shadow: 0 0 0 3px rgba(103,61,230,0.1);
}
.editor-field textarea { min-height: 70px; resize: vertical; }
.editor-hint {
  margin: 0;
  padding: 10px 12px;
  background: #FAFAFB;
  border: 1px solid #E5E5EA;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: #58585E;
}

/* Hint text used as a sibling to inputs (not inside a label) */
.editor-field .hint {
  font-size: 11.5px;
  color: #58585E;
  line-height: 1.45;
}

/* Inline checkbox toggle inside an .editor-field (e.g. "Show row numbers") */
.editor-field .editor-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #18181A;
  cursor: pointer;
  user-select: none;
}
.editor-field .editor-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--h-primary-500);
  cursor: pointer;
}
.editor-field .editor-toggle code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: #F0EFFE;
  color: var(--h-primary-600, #4f3bcf);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Secondary "ghost" button — outlined, used inside editor for utility actions */
.ghost-btn {
  appearance: none;
  border: 1px solid #E5E5EA;
  background: #fff;
  color: #36344D;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
.ghost-btn:hover:not(:disabled) {
  border-color: var(--h-primary-400);
  color: var(--h-primary-600, #4f3bcf);
  background: #FAFAFB;
}
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.editor-section {
  border-top: 1px solid #E5E5EA;
  padding-top: 14px;
  margin-top: 14px;
}
.editor-section__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.editor-section__title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #58585E;
}
.editor-list {
  display: grid;
  gap: 10px;
}
.editor-list__item {
  border: 1px solid #E5E5EA;
  border-radius: 6px;
  padding: 10px;
  background: #FAFAFB;
  display: grid;
  gap: 6px;
  position: relative;
}
.editor-list__item .editor-field { margin-bottom: 0; }
.editor-list__del {
  position: absolute;
  top: 6px;
  right: 6px;
  background: transparent;
  border: 0;
  color: #9D9EA4;
  cursor: pointer;
  font-size: 14px;
  width: 22px; height: 22px;
  border-radius: 4px;
}
.editor-list__del:hover { background: #FEE2E2; color: var(--h-danger-500); }
.editor-mini {
  background: transparent;
  border: 1px dashed #DADCE0;
  color: var(--h-primary-700);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.editor-mini:hover { background: var(--h-primary-50); border-color: var(--h-primary-400); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 26, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal__sheet {
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  max-width: 440px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.25);
}
.modal__sheet h3 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.modal__sheet p {
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0 0 10px;
  color: #36344D;
}
.modal__sheet .hint {
  color: #58585E;
  font-size: 12.5px;
}
.modal__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* ---------- Print: only the document, nothing else ---------- */
@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff; }
  .app { display: block; height: auto; overflow: visible; }
  .rail, .stage__bar { display: none !important; }
  .stage, .stage__scroll { display: block; height: auto; overflow: visible; background: #fff; }
  .doc { padding: 0; gap: 0; }
  .page {
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    width: 210mm !important;
    height: 297mm !important;
  }
  .block-wrap[data-selectable="true"] { outline: none !important; cursor: default !important; }
  .block-wrap__tag, .block-wrap__remove, .block-wrap__dup { display: none !important; }
  .block-wrap.is-selected { outline: none !important; }
  /* Print-friendly inputs: white box, thin border */
  .b-form input[type="text"],
  .b-form textarea {
    background: #fff !important;
    border: 1px solid #DADCE0 !important;
    box-shadow: none !important;
  }
  .b-table__cell input { border-bottom: 0 !important; background: transparent !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
