/* Mockup Studio - app components on top of styles.css (CI). Tokens only, no raw colors. */

[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.grow { flex: 1; }
.small { font-size: 13px; }
input[type="number"], textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; min-width: 0; max-width: 100%;
}
textarea { resize: vertical; }
input[type="color"] {
  width: 38px; height: 30px; padding: 2px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel-2); cursor: pointer;
}
input[type="color"]:disabled { opacity: .35; cursor: default; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.btn.sm { padding: 4px 10px; font-size: 13.5px; }
.btn.danger, .btn.primary.danger { background: var(--danger); border-color: var(--danger); color: var(--panel); }
.danger-text { color: var(--danger); }
.btn.disabled { opacity: .45; pointer-events: none; }
a.btn { display: inline-block; text-decoration: none; text-align: center; }

/* ---------- Header ---------- */
.app-top { padding-bottom: 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 8px; display: block; }
.brand:hover .brand-name { text-decoration: none; }
.userbox { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }
.user-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.btn.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 7px 9px; align-self: stretch; }
.btn.icon-btn.sm { padding: 5px 7px; }

/* ---------- Pages ---------- */
.page { max-width: 1040px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 6px 0 4px; }
.page-head h1 { font-size: clamp(26px, 4vw, 34px); }

.mockup-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.m-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}
.m-card:hover { border-color: var(--tone); }
.m-thumb {
  aspect-ratio: 16 / 10; background: var(--panel-2); border-bottom: 1px solid var(--border);
  display: grid; place-items: center; overflow: hidden; padding: 10px; text-decoration: none;
}
.m-thumb img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .12)); }
.m-info { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px 4px; min-width: 0; }
.m-name { color: var(--text); font-weight: 700; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-name:hover { text-decoration: underline; }
.m-actions { display: flex; gap: 6px; padding: 6px 12px 12px; }
.empty-state { text-align: center; padding: 36px 18px; display: grid; gap: 6px; justify-items: center; }

/* Login */
.login-main { display: grid; place-items: center; min-height: calc(100vh - 140px); }
.login-card { max-width: 440px; width: 100%; text-align: center; display: grid; gap: 12px; justify-items: center; padding: 30px 26px; }
.login-mark { border-radius: 16px; }
.login-btn { width: 100%; padding: 10px 14px; }
.setup { text-align: left; width: 100%; }
.setup-list { margin: 6px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }

/* Users */
.add-user { align-items: flex-end; }
.add-user .field { flex: 1 1 260px; }
.add-user .check { padding-bottom: 8px; }
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.users th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); }
.users td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users tr:last-child td { border-bottom: 0; }
.u-email { word-break: break-all; }
.u-actions { white-space: nowrap; text-align: right; }
.u-actions .btn + .btn { margin-left: 6px; }

/* Dialogs + toast */
dialog.dlg { width: min(440px, calc(100vw - 32px)); color: var(--text); padding: 20px 22px; }
dialog.dlg::backdrop { background: rgba(0, 0, 0, .35); }
.dlg-form { display: grid; gap: 12px; }
.dlg-fields { display: grid; gap: 12px; }
.dlg .field input, .dlg .field select { width: 100%; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow);
  font-weight: 600; font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: var(--panel); }

/* ---------- Editor ---------- */
body.editor-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.ed-head { max-width: none; width: 100%; padding: 10px 16px; gap: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.ed-head .brand-name { font-size: 19px; }
.doc-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 240px; }
.doc-title input { font-weight: 700; font-size: 15px; width: min(340px, 100%); background: transparent; border-color: transparent; }
.doc-title input:hover, .doc-title input:focus { border-color: var(--border); background: var(--panel-2); }
.save-state { font-size: 13px; white-space: nowrap; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.ed-head .userbox { margin-left: 0; }

.menu-wrap { position: relative; }
.pop-menu {
  position: absolute; z-index: 40; margin: 0; padding: 6px; list-style: none; min-width: 210px; border-radius: 10px;
}
#export-menu { right: 0; top: calc(100% + 6px); }
.pop-menu.ctx { position: fixed; }
.pop-menu button {
  font: inherit; font-size: 14px; display: flex; justify-content: space-between; gap: 18px; width: 100%;
  border: 0; background: transparent; color: var(--text); padding: 6px 10px; border-radius: 7px; cursor: pointer; text-align: left;
}
.pop-menu button:hover:not(:disabled), .pop-menu button:focus-visible { background: var(--panel-2); }
.pop-menu button:disabled { opacity: .4; cursor: default; }
.pop-menu kbd { font: inherit; font-size: 12px; color: var(--muted); }
.pop-menu .sep { height: 1px; background: var(--border); margin: 4px 6px; }

.ed-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; padding: 6px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.tgroup { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.text-tools.off { opacity: .55; }
.view-tools { margin-left: auto; }
.tsep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tbtn {
  font: inherit; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 6px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--text); cursor: pointer;
}
.tbtn:hover:not(:disabled) { background: var(--panel-2); border-color: var(--border); }
.tbtn:disabled { opacity: .35; cursor: default; }
.tbtn[aria-pressed="true"] { background: var(--tone); color: var(--tone-ink); }
.tbtn.sm { min-width: 28px; height: 28px; }
.zoom-label { min-width: 54px; font-variant-numeric: tabular-nums; }
#tb-font { width: 150px; padding: 5px 8px; }
#tb-size { width: 64px; padding: 5px 8px; }
.tseg { padding: 2px; }
.tseg button { display: inline-flex; padding: 4px 6px; color: var(--text); }
.tseg button:disabled { opacity: .5; cursor: default; }
.tseg button.on { background: var(--tone); color: var(--tone-ink); }
.color-btn {
  position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 34px; height: 32px; border-radius: 8px; cursor: pointer;
}
.color-btn:hover { background: var(--panel-2); }
.color-glyph { font-weight: 800; font-size: 15px; line-height: 1; }
.color-btn input[type="color"] { width: 24px; height: 8px; padding: 0; border: 0; border-radius: 2px; }
.color-btn input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-btn input[type="color"]::-webkit-color-swatch { border: 1px solid var(--border); border-radius: 2px; }

.ed-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 248px minmax(0, 1fr) 300px; }
.ed-left, .ed-right { background: var(--panel); min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.ed-left { border-right: 1px solid var(--border); }
.ed-right { border-left: 1px solid var(--border); }
.side-head { padding: 12px 14px 8px; display: grid; gap: 8px; }
.side-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.side-head.row-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.side-head input { width: 100%; padding: 6px 10px; }
.side-hint { font-size: 12.5px; padding: 6px 14px 12px; }

.library { overflow-y: auto; flex: 1; padding: 0 10px 8px; }
.lib-cat-head {
  font: inherit; font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 4px; width: 100%;
  border: 0; background: transparent; color: var(--text); padding: 8px 4px 6px; cursor: pointer; border-radius: 6px;
}
.lib-cat-head svg { transition: transform .15s; }
.lib-cat-head[aria-expanded="true"] svg { transform: rotate(90deg); }
.lib-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding-bottom: 6px; }
.lib-item {
  font: inherit; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2);
  color: var(--text); cursor: grab; min-width: 0;
}
.lib-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item:hover { border-color: var(--tone); }
.lib-item svg { background: var(--paper); border-radius: 6px; box-shadow: 0 0 0 1px var(--border); }

.stage-wrap { overflow: auto; background: var(--bg); min-width: 0; min-height: 0; position: relative; }
.stage-pad { display: grid; place-items: center; width: max-content; min-width: 100%; min-height: 100%; padding: 32px; position: relative; }
.stage { display: block; box-shadow: var(--shadow), 0 0 0 1px var(--border); user-select: none; touch-action: none; overflow: hidden; }
.stage-grid { pointer-events: none; }
.overlay { pointer-events: none; }
.overlay .sel-handle { pointer-events: all; }
.sel-box { fill: none; stroke: var(--tone); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.sel-box.group { stroke-dasharray: 5 3; }
.sel-outer { fill: none; stroke: var(--tone); stroke-width: 1px; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.sel-handle { fill: var(--panel); stroke: var(--tone); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.h-nw, .h-se { cursor: nwse-resize; }
.h-ne, .h-sw { cursor: nesw-resize; }
.h-n, .h-s { cursor: ns-resize; }
.h-e, .h-w { cursor: ew-resize; }
.marquee { fill: color-mix(in srgb, var(--tone) 10%, transparent); stroke: var(--tone); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.text-edit {
  position: absolute; z-index: 5; margin: 0; padding: 4px 6px; resize: none; border-radius: 4px;
  border: 2px solid var(--tone); background: var(--panel); color: var(--text); line-height: 1.25;
  box-shadow: var(--shadow);
}

.side-sec { display: flex; flex-direction: column; min-height: 0; }
.layers-sec { flex: 1 1 42%; border-bottom: 1px solid var(--border); }
.props-sec { flex: 1 1 58%; }
.mini-tools { display: flex; gap: 2px; }
.layers { list-style: none; margin: 0; padding: 0 8px 8px; overflow-y: auto; flex: 1; }
.layers ul { list-style: none; margin: 0; padding: 0; }
.layer-row {
  display: flex; align-items: center; gap: 4px; height: 32px; padding-right: 4px; border-radius: 7px; cursor: pointer;
  border: 1px solid transparent; font-size: 13.5px; position: relative;
}
.layer-row:hover { background: var(--panel-2); }
.layer-row.on { background: color-mix(in srgb, var(--tone) 16%, transparent); border-color: color-mix(in srgb, var(--tone) 45%, transparent); }
.layer-row.is-hidden .layer-name, .layer-row.is-hidden .layer-kind { opacity: .45; }
.layer-row.is-locked .layer-name { font-style: italic; }
.layer-row[data-drop="above"]::before, .layer-row[data-drop="below"]::after {
  content: ""; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--tone); border-radius: 1px;
}
.layer-row[data-drop="above"]::before { top: -2px; }
.layer-row[data-drop="below"]::after { bottom: -2px; }
.layer-row[data-drop="inside"] { outline: 2px solid var(--tone); outline-offset: -2px; }
.caret, .caret-space { width: 20px; height: 20px; flex: none; }
.caret { display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 4px; }
.caret.open svg { transform: rotate(90deg); }
.layer-kind { width: 30px; height: 20px; flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.layer-kind svg { width: 30px; height: 20px; border-radius: 3px; background: var(--paper); }
.layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-rename { flex: 1; min-width: 0; padding: 3px 6px; font-size: 13.5px; }
.lbtn {
  width: 26px; height: 26px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer; opacity: .55;
}
.layer-row:hover .lbtn, .lbtn[aria-pressed="true"] { opacity: 1; }
.lbtn:hover { background: var(--panel); color: var(--text); }

.props { overflow-y: auto; flex: 1; padding: 2px 14px 16px; display: grid; gap: 12px; align-content: start; }
.props h3 { font-size: 13px; margin: 0; }
.psec { display: grid; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.pfield { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pfield input[type="text"], .pfield textarea, .pfield select, .pfield input[type="number"] { width: 100%; padding: 6px 8px; }
.pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pcheck { font-size: 14px; }
.color-row { display: flex; align-items: center; gap: 10px; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input { flex: 1; accent-color: var(--tone); }
.range-out { width: 32px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.align-row { display: flex; flex-wrap: wrap; gap: 2px; }
.help { color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); padding-top: 10px; }
.help ul { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 4px; }

/* Narrow screens: stack the editor so nothing scrolls sideways. */
@media (max-width: 900px) {
  body.editor-page { height: auto; overflow: auto; }
  .ed-body { grid-template-columns: minmax(0, 1fr); }
  .stage-wrap { height: 62vh; order: -1; }
  .ed-left, .ed-right { border: 0; border-top: 1px solid var(--border); max-height: 70vh; }
  .view-tools { margin-left: 0; }
  .doc-title { order: 5; flex-basis: 100%; }
}
@media (max-width: 600px) {
  .user-name { display: none; }
  .page-head { align-items: flex-start; }
}
