.card h2,
.card h3 {
  margin-top: 0;
  margin-bottom: 0.45rem;
}

.setup-tabs {
  gap: 0.9rem;
  border-bottom: 0;
  margin-bottom: 1rem;
}

.setup-tabs .nav-link {
  border: 1px solid var(--bs-primary);
  border-radius: 0.42rem;
  color: #fff;
  background-color: var(--bs-primary);
  font-weight: 700;
  margin-bottom: 0;
  padding: 0.65rem 1rem;
}

.setup-tabs .nav-link.active {
  background-color: var(--bs-primary-dark);
  color: #fff;
  border-color: var(--bs-primary-dark);
  box-shadow: 0 0.12rem 0.4rem rgba(var(--bs-primary-rgb), 0.22);
}

.setup-tabs .nav-link:hover {
  border-color: var(--bs-primary-dark);
  color: #fff;
  background: var(--bs-primary-dark);
}

.setup-tabs .nav-link.active:hover {
  color: #fff;
}

.setup-tab-content {
  margin-top: 0;
}

/* Local template overview: compact controls and separated actions. */
.local-templates-panel .local-templates-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .65rem 1rem;
  margin-bottom: 1rem;
}
.local-templates-panel .local-templates-note {
  margin: .3rem 0 0;
  color: var(--app-muted);
  font-size: .8rem;
  line-height: 1.5;
}
.local-templates-panel button,
.local-templates-panel a.btn {
  width: auto;
  min-height: 2rem;
  margin: 0;
  padding: .35rem .7rem;
  font-size: .8rem;
  line-height: 1.35;
  white-space: nowrap;
  flex-shrink: 0;
}
.local-generation-settings {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem 1.2rem;
  padding: .8rem 1rem;
  border: 1px solid var(--app-border);
  border-radius: .45rem;
  background: #f8fbff;
}
.local-generation-settings > div { min-width: 0; }
.local-generation-settings .checkbox-row { margin: 0; font-size: .85rem; }
.local-generation-settings .checkbox-row-plain:hover { background: transparent; }
.local-generation-settings input[type=checkbox] { flex: 0 0 auto; }
.local-template-entry-forms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 1rem 1.5rem;
  margin: 1.2rem 0;
}
.local-template-entry-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  justify-content: start;
  gap: .75rem;
  margin: 0;
}
.local-template-entry-form > div { min-width: 0; }
.local-template-entry-form label { font-size: .85rem; }
.local-template-entry-form input { width: 100%; font-size: .85rem; }
.local-template-entry-form button { min-height: 2.4rem; }
.local-template-entry-note { grid-column: 1 / -1; }
.local-templates-panel .local-template-entry-note { margin: 0; }
.local-template-import-error { color: var(--color-delete); font-size: .8rem; }
.local-templates-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin: 1.4rem 0 .65rem;
  padding-top: 1rem;
  border-top: 1px solid var(--app-border);
}
.local-templates-list-heading h3 { margin: 0; font-size: .95rem; }
.local-templates-list-heading .local-templates-note { margin: 0; }
.local-templates-table { table-layout: fixed; }
.local-templates-table th:first-child { width: auto; }
.local-templates-table th:nth-child(2) { width: 100px; }
.local-templates-table th:nth-child(3) { width: 110px; }
.local-templates-table th:last-child { width: 40%; }
.local-templates-table tbody td { vertical-align: middle; padding: .85rem .65rem; font-size: .85rem; }
.local-templates-table .local-template-title { font-weight: 600; overflow-wrap: anywhere; }
.local-templates-panel .status-pill { font-size: .75rem; white-space: nowrap; }
.local-template-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.local-template-actions form { display: flex; margin: 0; }
.local-templates-empty td { color: var(--app-muted); padding: 1.25rem .65rem; }

.setup-hero .actions form {
  margin: 0;
}

.setup-layout {
  display: grid;
  gap: 1rem;
}

.setup-layout ~ .setup-layout {
  margin-top: 1.5rem;
}

.setup-panel {
  border: 1px solid var(--app-border);
  border-radius: 0.55rem;
  background: #fff;
  box-shadow: var(--app-shadow-sm);
  padding: 1rem;
}

.setup-panel-secondary {
  background: #f8fbff;
}

.setup-run-panel {
  margin-top: 1rem;
}

.setup-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.setup-panel-head h2 {
  margin: 0;
}

.setup-toggle-grid,
.setup-provider-grid,
.setup-command-grid {
  display: grid;
  gap: 0.75rem;
}

.setup-toggle-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.setup-toggle-grid + .app-grid,
.app-grid ~ .app-grid {
  margin-top: 0.75rem;
}

.setup-grid-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--app-muted);
  margin: 0 0 0.4rem;
}

.app-grid ~ .setup-grid-label {
  margin-top: 1.1rem;
}

.setup-provider-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.setup-command-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
}

.setup-command-grid form,
.setup-action-bar {
  margin: 0;
}

.setup-action-bar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.setup-action-bar-split {
  justify-content: flex-start;
}

.setup-action-bar-split .save-button {
  margin-left: 0;
}

.setup-status-grid .kpi {
  min-height: 6rem;
}

.setup-webhook-card {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.setup-webhook-card div {
  display: grid;
  gap: 0.15rem;
}

.setup-webhook-card code {
  overflow-wrap: anywhere;
}

.branding-logo-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.25rem;
  align-items: start;
}

.branding-logo-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.branding-logo-preview {
  max-height: 80px;
  max-width: 180px;
  border: 1px solid var(--app-border);
  border-radius: 0.28rem;
  padding: 0.5rem;
  background: #fff;
  object-fit: contain;
}

.branding-logo-scale-row {
  margin-top: 1rem;
  max-width: 12rem;
}

.branding-login-background-row {
  display: grid;
  grid-template-columns: minmax(240px, 32rem) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.branding-login-logo-row {
  display: grid;
  grid-template-columns: minmax(180px, 18rem) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.branding-login-logo-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.branding-login-logo-preview,
.branding-login-logo-default {
  width: 100%;
  height: 88px;
  border: 1px solid var(--app-border);
  border-radius: 0.42rem;
  padding: 0.65rem;
  background: #fff;
  object-fit: contain;
}

.branding-login-logo-default {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
}

.branding-login-logo-default img:first-child {
  width: 3.75rem;
  max-height: 100%;
  object-fit: contain;
}

.branding-login-logo-default img:last-child {
  width: min(65%, 11rem);
  max-height: 100%;
  object-fit: contain;
}

.branding-login-background-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.branding-login-background-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--app-border);
  border-radius: 0.42rem;
  background: #101827;
  object-fit: cover;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Higher specificity (0,3,1) beats forms.css (0,3,1) via load order */
.setup-panel .color-picker-row input[type="color"] {
  width: 2.6rem;
  height: 2.6rem;
  padding: 0.15rem;
  border: 1px solid var(--app-border);
  border-radius: 0.28rem;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
  flex-grow: 0;
}

.setup-panel .color-picker-row input.color-hex-input {
  width: 7.5rem;
  flex-shrink: 1;
  min-width: 4rem;
  font-family: monospace;
  letter-spacing: 0.04em;
}

/* Local PDF studio: the ProfileGen workspace adapted to asset documents. */
.app-content:has(.template-studio) { padding: 1rem 1rem 4.5rem; }
.template-studio {
  display: flex; flex-direction: column; height: calc(100dvh - 6rem); min-height: 620px;
  margin: 0; overflow: hidden; border: 1px solid var(--app-border); border-radius: .55rem;
  background: #e9edf1; box-shadow: var(--app-shadow-sm); color: var(--app-text);
}
.template-studio [hidden] { display: none !important; }
.template-studio .studio-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem 1.2rem; padding: .7rem .9rem; background: #fff; border-bottom: 1px solid var(--app-border); }
.template-studio .studio-title { flex: 0 1 250px; min-width: 180px; }
.template-studio .studio-title label { display: block; margin: 0; font-size: .65rem; color: var(--app-muted); text-transform: uppercase; letter-spacing: .07em; }
.template-studio .studio-title input { width: 100%; border: 1px solid transparent; background: transparent; border-radius: .2rem; padding: .1rem 0; font-size: 1rem; font-weight: 700; color: var(--app-text); }
.template-studio .studio-title input:focus { border-color: var(--bs-primary); padding-left: .25rem; outline: none; }
.template-studio .studio-title small { display: block; font-size: .68rem; color: var(--app-muted); }
.template-studio .studio-toolbar-actions { display: flex; flex: 1 1 670px; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: .4rem; }
.template-studio .studio-command-group { display: flex; gap: .25rem; padding-right: .55rem; border-right: 1px solid var(--app-border); }
.template-studio button, .template-studio a.btn { font-size: .72rem; padding: .38rem .55rem; }
.template-studio .studio-zoom-label { display: flex; align-items: center; gap: .3rem; margin: 0 .3rem 0 0; font-size: .7rem; }
.template-studio .studio-zoom-label select { width: 88px; font-size: .7rem; padding: .3rem 1.2rem .3rem .3rem; }
.template-studio .studio-workspace { display: grid; grid-template-columns: 225px minmax(300px, 1.08fr) minmax(300px, .92fr); min-height: 0; flex: 1; }
.template-studio .studio-sidebar { min-width: 0; overflow-y: auto; padding: .8rem; background: #fff; border-right: 1px solid var(--app-border); }
.template-studio .studio-sidebar h2 { font-size: .85rem; margin: .8rem 0 .35rem; }
.template-studio .studio-hint { color: var(--app-muted); font-size: .72rem; line-height: 1.5; margin: .4rem 0 .65rem; }
.template-studio .studio-sidebar-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; }
.template-studio .studio-sidebar-tabs button { padding: .38rem .2rem; font-size: .7rem; }
.template-studio .studio-sidebar-tabs .active { box-shadow: inset 0 -3px var(--bs-primary); }
.template-studio .studio-palette-item { display: grid; grid-template-columns: 28px 1fr; gap: .45rem; width: 100%; text-align: left; align-items: center; margin-bottom: .4rem; cursor: grab; }
.template-studio .studio-palette-item span:first-child { display: grid; place-items: center; height: 26px; border-radius: .25rem; background: #ffffff26; font-size: 1rem; }
.template-studio .studio-palette-item small { display: block; font-size: .63rem; font-weight: 400; opacity: .9; }
.template-studio .studio-panel-section { border-top: 1px solid var(--app-border); margin-top: .9rem; padding-top: .65rem; }
.template-studio .studio-panel-section summary { font-size: .75rem; font-weight: 700; cursor: pointer; }
.template-studio .studio-field { display: flex; flex-direction: column; gap: .25rem; margin: .65rem 0; font-size: .72rem; font-weight: 600; }
.template-studio .studio-field input, .template-studio .studio-field textarea, .template-studio .studio-field select { width: 100%; min-width: 0; border: 1px solid var(--app-border-strong); border-radius: .3rem; padding: .38rem; font-size: .75rem; background: #fff; color: var(--app-text); }
.template-studio .studio-field textarea { min-height: 120px; resize: vertical; }
.template-studio #studio-sample-fields textarea { min-height: 56px; }
.template-studio #studio-sample-fields label { overflow-wrap: anywhere; }
.template-studio .studio-field input[type=color] { height: 34px; padding: .15rem; }
.template-studio .studio-field input[type=checkbox] { width: auto; }
.template-studio .studio-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.template-studio .studio-placeholder { margin: .15rem .15rem .15rem 0; max-width: 100%; word-break: break-word; }
.template-studio .studio-wide { width: 100%; margin-top: .45rem; text-align: left; }
.template-studio .studio-canvas-scroll { min-width: 0; overflow: auto; padding: 18px; text-align: center; background: #e9edf1; }
.template-studio .studio-canvas-heading { display: flex; justify-content: space-between; gap: .5rem; margin: 0 0 .8rem; color: var(--app-muted); font-size: .62rem; letter-spacing: .05em; }
.template-studio .studio-canvas-scale { display: inline-block; text-align: left; vertical-align: top; }
.template-studio .studio-a4 { position: relative; width: 794px; min-height: 1123px; padding: 68px; background: #fff; box-shadow: 0 3px 16px #26364c26; text-align: left; color: #202a36; font-family: Arial, sans-serif; }
.template-studio .studio-region { border: 1px dashed #bbc7d3; padding: 8px; margin: 0 0 12px; min-height: 72px; }
.template-studio .studio-body { min-height: 680px; margin-bottom: 0; }
.template-studio .studio-header, .template-studio .studio-footer { position: absolute; min-height: 0; padding: 4px; margin: 0; }
.template-studio .studio-header .studio-empty-zone, .template-studio .studio-footer .studio-empty-zone { min-height: 16px; }
.template-studio .studio-header h3, .template-studio .studio-footer h3 { font-size: 8px; margin-bottom: 2px; }
.template-studio .studio-region h3 { font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: #7b8795; margin: 0 0 6px; font-weight: 500; }
.template-studio .studio-block { position: relative; border: 1px solid transparent; border-radius: 4px; padding: 6px; cursor: pointer; }
.template-studio .studio-block:hover { border-color: #b6c6d9; }
.template-studio .studio-block.selected { outline: 2px solid var(--bs-primary); background: #f3f6ff; }
.template-studio .studio-block:focus-visible { outline: 2px solid var(--bs-primary); }
.template-studio .studio-block-label { display: flex; justify-content: space-between; align-items: center; color: #758195; font-size: 10px; line-height: 1.4; margin-bottom: 4px; }
.template-studio .studio-block-content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.template-studio .studio-block-content img { max-width: 100%; height: auto; }
.template-studio .studio-token { color: #3359ad; background: #e8efff; border-radius: 3px; padding: 0 2px; }
.template-studio .studio-insert { height: 12px; border: 1px dashed transparent; border-radius: 3px; }
.template-studio.studio-dragging .studio-insert { border-color: #94baaa; background: #f4fbf7; }
.template-studio .studio-insert.drag-over { background: #e0f4e9; border-color: #4b9870; }
.template-studio .studio-empty-zone { min-height: 44px; display: grid; place-items: center; font-size: 12px; color: #91a0b1; border: 1px dashed #d5dce4; border-radius: 3px; }
.template-studio .studio-pagination-note { color: var(--app-muted); font-size: .68rem; margin: .8rem auto; max-width: 420px; }
.template-studio .studio-live-preview { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #dce1e7; border-left: 1px solid var(--app-border); }
.template-studio .studio-preview-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .65rem .8rem; background: #fff; border-bottom: 1px solid var(--app-border); }
.template-studio .studio-preview-toolbar strong { font-size: .8rem; }
.template-studio .studio-preview-toolbar small { display: block; color: var(--app-muted); font-size: .65rem; }
.template-studio .studio-preview-actions { display: flex; align-items: center; gap: .5rem; }
.template-studio .studio-preview-actions label { font-size: .67rem; font-weight: 400; margin: 0; display: flex; align-items: center; gap: .3rem; }
.template-studio .studio-preview-body { flex: 1; min-height: 0; position: relative; }
.template-studio .studio-preview-body iframe { width: 100%; height: 100%; border: 0; display: block; }
.template-studio .studio-preview-empty { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: .7rem; padding: 2rem; text-align: center; color: var(--app-muted); }
.template-studio .studio-preview-empty strong { font-size: .9rem; color: var(--app-text-soft); }
.template-studio .studio-preview-empty > span:last-child { font-size: .75rem; max-width: 250px; }
.template-studio .studio-preview-icon { font-size: 3.5rem; color: #9ba8b8; }
.template-studio .studio-message { padding: .5rem .9rem; background: #fff0ee; color: #a32316; font-size: .8rem; border-bottom: 1px solid #f2c8c2; }
.template-studio .studio-image-thumbnail { display: block; width: 100%; max-height: 110px; object-fit: contain; margin: .5rem 0; border: 1px solid var(--app-border); background: #f6f8fb; }
.template-studio .studio-inspector-actions { display: flex; flex-wrap: wrap; gap: .3rem; margin: .8rem 0; }
.template-studio .studio-divider { border: 0; border-top: 1px solid; margin: 0; }
.template-studio .studio-row-columns { display: grid; align-items: start; }
.template-studio .studio-column { min-width: 0; min-height: 65px; border: 1px dashed #b9c8d7; padding: 4px; cursor: pointer; }
.template-studio .studio-column.selected { outline: 2px solid var(--bs-primary); background: #f3f6ff; }
.template-studio .studio-column-label { font-size: 9px; color: #7b8795; margin-bottom: 4px; }
.template-studio .studio-column .studio-empty-zone { font-size: 10px; }
