/* Tilläggstavla widget. Scoped under .tt. Fonts come from the theme (the
   heading is a real <h3>, so it gets the theme's heading face); colours default
   to Skyltcentralen's Empire theme and can be overridden with --tt-accent
   (block setting) or from theme CSS. */
.tt {
  --tt-accent: #007bff;
  --tt-accent-soft: color-mix(in srgb, var(--tt-accent) 10%, #fff);
  --tt-ink: #2f3337;
  --tt-muted: #6b747c;
  --tt-line: #d9dee3;
  --tt-surface: #f4f6f8;
  --tt-error: #c62828;
  --tt-error-soft: #fdeeee;
  --tt-select: #ff2d87;
  --tt-radius: 3px;
  display: grid;
  gap: 16px;
  margin: 24px 0;
  padding-top: 24px;
  border-top: 1px solid var(--tt-line);
  color: var(--tt-ink);
  font: inherit;
}
.tt * { box-sizing: border-box; }
.tt [hidden] { display: none !important; }

.tt-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.tt-heading { margin: 0; font-size: 1.35em; line-height: 1.2; }

.tt-segs {
  display: inline-flex;
  border: 1px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: #fff;
  overflow: hidden;
}
.tt-seg {
  font: inherit;
  font-size: 14px;
  min-height: 36px;
  padding: 6px 16px;
  border: 0;
  background: none;
  color: var(--tt-muted);
  cursor: pointer;
}
.tt-seg + .tt-seg { border-left: 1px solid var(--tt-line); }
.tt-seg[aria-pressed="true"] { background: var(--tt-accent-soft); color: var(--tt-accent); font-weight: 700; }
.tt-seg:focus-visible { outline: 2px solid var(--tt-accent); outline-offset: -2px; }

/* ---- preview ---- */
.tt-stage {
  border: 1px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: var(--tt-surface);
  overflow: hidden;
}
.tt-scene { width: 100%; aspect-ratio: 5 / 3; }
.tt-svg { display: block; width: 100%; height: 100%; outline: none; }
.tt-svg text { font-family: inherit; }
.tt-svg .tt-placeholder svg g g { opacity: 0.35; }
.tt-scene { -webkit-user-select: none; user-select: none; }
.tt-scene.is-advanced .tt-svg { touch-action: none; }
.tt-scene.is-advanced .tt-hit { cursor: grab; }
.tt-scene.is-advanced .tt-hit:hover:not(.is-selected) { stroke: color-mix(in srgb, var(--tt-select) 55%, transparent); stroke-dasharray: none; }
.tt-svg:focus-visible { box-shadow: inset 0 0 0 2px var(--tt-accent); }

.tt-msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: -6px;
  padding: 10px 12px;
  border-radius: var(--tt-radius);
  font-size: 14px;
  line-height: 1.4;
}
.tt-msg:empty { display: none; }
.tt-msg svg { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.tt-msg[data-tone="info"] { background: var(--tt-accent-soft); color: color-mix(in srgb, var(--tt-accent) 70%, #000); }
.tt-msg[data-tone="info"] svg circle { fill: var(--tt-accent); }
.tt-msg[data-tone="error"] { background: var(--tt-error-soft); color: var(--tt-error); }
.tt-msg[data-tone="error"] svg circle { fill: var(--tt-error); }

/* ---- fields ---- */
.tt-panel { display: grid; gap: 16px; }
.tt-field { display: grid; gap: 6px; margin: 0; }
.tt-label { font-size: 15px; font-weight: 700; }
.tt-hint { margin: 0; font-size: 13px; color: var(--tt-muted); }
.tt-intro { margin-top: -6px; }
.tt-textarea, .tt-select {
  font: inherit;
  font-size: 16px; /* no zoom on iOS */
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: #fff;
  color: var(--tt-ink);
}
.tt-textarea { resize: vertical; line-height: 1.4; }
.tt-textarea::placeholder { color: #a2aab1; }
.tt-textarea:focus, .tt-select:focus, .tt-qty-input:focus {
  outline: none;
  border-color: var(--tt-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tt-accent) 22%, transparent);
}

.tt-link {
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  color: var(--tt-accent);
  text-decoration: underline;
  cursor: pointer;
}

/* text size stepper: A− 40 mm A+ */
.tt-stepper {
  display: inline-flex;
  align-items: stretch;
  justify-self: start;
  border: 1px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: #fff;
}
.tt-stepper .tt-icon-btn { border: 0; font-weight: 700; }
.tt-stepper .tt-icon-btn:first-child { font-size: 13px; }
.tt-stepper .tt-icon-btn:last-child { font-size: 17px; }
.tt-cap {
  display: grid;
  place-items: center;
  min-width: 72px;
  padding: 0 8px;
  border-left: 1px solid var(--tt-line);
  border-right: 1px solid var(--tt-line);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
/* advanced: the height is a field you can type in */
label.tt-cap { display: flex; align-items: center; gap: 3px; cursor: text; }
.tt-cap-input {
  width: 3.2ch;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  text-align: right;
  color: inherit;
  font-variant-numeric: tabular-nums;
}
.tt-cap-input:focus { outline: none; }
label.tt-cap:focus-within { box-shadow: inset 0 0 0 2px var(--tt-accent, #007bff); }
.tt-icon-btn {
  display: inline-grid;
  place-items: center;
  font: inherit;
  min-width: 40px;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: #fff;
  color: var(--tt-ink);
  cursor: pointer;
}
.tt-icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tt-icon-btn:disabled { color: #c3cbd2; cursor: default; }
.tt-icon-btn:focus-visible { outline: 2px solid var(--tt-accent); outline-offset: -2px; }
.tt-icon-btn[aria-pressed="true"] { background: var(--tt-accent-soft); border-color: var(--tt-accent); color: var(--tt-accent); }

/* standard sizes */
.tt-sizes { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
/* Four standard sizes (orange): one row, or two by two on phones — never 3 + 1. */
.tt-sizes:has(> :nth-child(4):last-child) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tt-size, .tt-cell {
  display: grid;
  gap: 1px;
  font: inherit;
  text-align: center;
  border: 1px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: #fff;
  color: var(--tt-ink);
  cursor: pointer;
}
.tt-size { padding: 9px 8px; }
.tt-size b { font-size: 15px; }
.tt-size span, .tt-cell span { font-size: 13px; color: var(--tt-muted); }
.tt-size[aria-pressed="true"], .tt-cell[aria-pressed="true"] {
  border-color: var(--tt-accent);
  box-shadow: inset 0 0 0 1px var(--tt-accent);
  background: var(--tt-accent-soft);
}
.tt-size[aria-pressed="true"] span, .tt-cell[aria-pressed="true"] span { color: var(--tt-accent); }
.tt-size:disabled, .tt-cell:disabled { opacity: 0.4; cursor: not-allowed; }
.tt-size:focus-visible, .tt-cell:focus-visible { outline: 2px solid var(--tt-accent); outline-offset: 1px; }
.tt-size:hover:not(:disabled):not([aria-pressed="true"]), .tt-cell:hover:not(:disabled):not([aria-pressed="true"]) { border-color: #aab4bd; }

/* all sizes: widths across, heights down */
.tt-grid { display: grid; grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr)); gap: 4px; }
.tt-cell { position: relative; padding: 7px 2px; }
.tt-cell b { font-size: 12px; font-weight: 700; letter-spacing: -0.01em; }
.tt-cell span { font-size: 11px; }
.tt-cell[data-standard="true"]::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tt-accent);
}

.tt-legend { display: flex; align-items: center; gap: 6px; }
.tt-legend i { width: 6px; height: 6px; border-radius: 50%; background: var(--tt-accent); }

/* text objects (advanced) */
.tt-objects { display: grid; gap: 10px; }
.tt-object {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  border: 1px solid var(--tt-line);
  border-left: 3px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: #fff;
}
.tt-object[aria-current="true"] { border-left-color: var(--tt-select); }
.tt-object-head { display: flex; align-items: center; justify-content: space-between; }
.tt-object-head .tt-icon-btn { min-width: 34px; min-height: 34px; border-color: transparent; }
.tt-object-head .tt-icon-btn:hover:not(:disabled) { color: var(--tt-error); }
.tt-object-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; justify-content: space-between; }
.tt-tools { display: flex; gap: 4px; }
.tt-add-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  min-height: 44px;
  border: 1px dashed #aab4bd;
  border-radius: var(--tt-radius);
  background: none;
  color: var(--tt-accent);
  cursor: pointer;
}
.tt-add-text svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tt-add-text:hover { border-color: var(--tt-accent); background: var(--tt-accent-soft); }
.tt-add-text:focus-visible { outline: 2px solid var(--tt-accent); outline-offset: 1px; }

/* ---- buy ---- */
.tt-buy { display: flex; gap: 10px; align-items: stretch; margin-top: 4px; }
.tt-qty {
  display: flex;
  flex: none;
  border: 1px solid var(--tt-line);
  border-radius: var(--tt-radius);
  background: #fff;
}
.tt-qty-btn {
  font: inherit;
  font-size: 20px;
  width: 40px;
  border: 0;
  background: none;
  color: var(--tt-ink);
  cursor: pointer;
}
.tt-qty-btn:disabled { color: #c3cbd2; cursor: default; }
.tt-qty-btn:focus-visible { outline: 2px solid var(--tt-accent); outline-offset: -2px; }
.tt-qty-input {
  font: inherit;
  font-size: 16px;
  width: 44px;
  border: 0;
  border-left: 1px solid var(--tt-line);
  border-right: 1px solid var(--tt-line);
  text-align: center;
  color: var(--tt-ink);
  -moz-appearance: textfield;
}
.tt-qty-input::-webkit-outer-spin-button, .tt-qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tt-add {
  flex: 1;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid var(--tt-accent);
  border-radius: var(--tt-radius);
  background: var(--tt-accent);
  color: #fff;
  cursor: pointer;
}
.tt-add:hover:not(:disabled) { filter: brightness(0.94); }
.tt-add:focus-visible { outline: 2px solid var(--tt-accent); outline-offset: 2px; }
.tt-add:disabled { opacity: 0.4; cursor: not-allowed; }

.tt-status { margin: -4px 0 0; font-size: 14px; }
.tt-status:empty { display: none; }
.tt-status[data-tone="ok"] { color: #1e7a3a; }
.tt-status[data-tone="error"] { color: var(--tt-error); }
.tt-status a { color: inherit; font-weight: 700; }

@media (max-width: 480px) {
  .tt-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tt-sizes { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
  .tt-sizes:has(> :nth-child(4):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
