/* ============================================================
   STICKERBOOK ADMIN - STUDIO (admin-graphic.js, admin-graphic-catalog.js, admin-graphic-pack.js)
   Full screen over the portal. Catalog tiles reuse Content's ct-tile styles.
   ============================================================ */


body.gm-open { overflow: hidden; }
body.gm-open .toast { z-index: 2500; }

.gm-root {
  position: fixed; inset: 0; z-index: 950; background: var(--sb-bg); color: var(--sb-text);
  font-family: var(--font-primary);
  display: grid; grid-template-columns: 320px minmax(0, 1fr) 290px; grid-template-rows: 60px minmax(0, 1fr);
}
.gm-root *, .gm-root *::before, .gm-root *::after { box-sizing: border-box; }
.gm-root button { font-family: inherit; }

/* Top bar */
.gm-top { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 14px; background: var(--sb-surface); border-bottom: 1px solid var(--sb-border); min-width: 0; }
.gm-ttl { font-size: 14px; font-weight: 700; white-space: nowrap; margin-right: 8px; }
.gm-sp { flex: 1; }
.gm-ib { width: 36px; height: 36px; flex: none; display: inline-grid; place-items: center; border: 1px solid var(--sb-border); background: var(--sb-surface); color: var(--sb-text); border-radius: 10px; cursor: pointer; }
.gm-ib:hover { background: var(--sb-surface-2); }
.gm-ib:disabled { opacity: 0.35; cursor: default; background: var(--sb-surface); }
.gm-ib .sb-ico { width: 17px; height: 17px; }
.gm-ib-s { width: 28px; height: 28px; border-radius: 8px; }
.gm-ib-s .sb-ico { width: 14px; height: 14px; }
.gm-go { height: 36px; display: inline-flex; align-items: center; gap: 7px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--sb-accent); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.gm-go:hover { background: #5B21B6; }
.gm-go .sb-ico { width: 16px; height: 16px; }

.gm-shapepick { position: relative; }
.gm-shapebtn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px 0 12px; border: 1px solid var(--sb-border); background: var(--sb-surface); color: var(--sb-text); border-radius: 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.gm-shapebtn:hover { background: var(--sb-surface-2); }
.gm-shapebtn b { font-weight: 600; }
.gm-shapebtn span { color: var(--sb-muted); font-size: 12px; }
.gm-shapebtn .sb-ico { width: 14px; height: 14px; color: var(--sb-muted); }
.gm-shapepick i { display: inline-block; flex: none; border: 1.6px solid currentColor; border-radius: 2px; }
.gm-shapemenu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: 380px; max-height: min(560px, calc(100vh - 90px)); overflow-y: auto; background: var(--sb-surface); border: 1px solid var(--sb-border); border-radius: 14px; box-shadow: var(--shadow-xl); padding: 6px; }
.gm-shapemenu button { display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left; border: 0; background: transparent; color: var(--sb-text); border-radius: 10px; padding: 9px 10px; cursor: pointer; }
.gm-shapemenu button:hover { background: var(--sb-surface-2); }
.gm-shapemenu button.on { background: var(--sb-accent-soft); }
.gm-shapemenu b { font-size: 13px; font-weight: 600; }
.gm-shapemenu em { font-style: normal; font-size: 11.5px; color: var(--sb-muted); }
.gm-shapemenu small { display: block; font-size: 11.5px; color: var(--sb-text-2); line-height: 1.4; margin-top: 2px; }
.gm-smicon { width: 28px; height: 28px; flex: none; display: grid; place-items: center; color: var(--sb-text-2); }
.gm-shapemenu button.on .gm-smicon { color: var(--sb-accent); }

/* Sides */
.gm-side { background: var(--sb-surface); overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.gm-left { border-right: 1px solid var(--sb-border); }
.gm-right { border-left: 1px solid var(--sb-border); }
.gm-sec { padding: 14px; border-bottom: 1px solid var(--sb-border); }
.gm-sec-cat { border-bottom: 0; }
.gm-sec h3 { margin: 0 0 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sb-muted); display: flex; align-items: center; justify-content: space-between; }
.gm-count { text-transform: none; letter-spacing: 0; font-weight: 500; }
.gm-grab { display: none; }
.gm-grow { flex: 1; min-width: 0; }
.gm-note { font-size: 11.5px; color: var(--sb-muted); line-height: 1.45; margin-top: 8px; }
.gm-lbl { font-size: 11px; font-weight: 600; color: var(--sb-text-2); margin: 12px 0 6px; }
.gm-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.gm-row:first-child { margin-top: 0; }
.gm-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--sb-border); background: var(--sb-surface); color: var(--sb-text); border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer; }
.gm-chip:hover { background: var(--sb-surface-2); }
.gm-chip.on { background: var(--sb-text); border-color: var(--sb-text); color: #fff; }
.gm-chip .sb-ico { width: 14px; height: 14px; }
.gm-fonts .gm-chip { font-size: 13px; }

/* Catalog */
.gm-search { margin: 0; }
.gm-filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 10px; }
.gm-cgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.gm-cgrid .ct-tcap span { font-size: 9.5px; }
.gm-pickbar { margin-top: 0; bottom: 0; }
#gmc-bar { position: sticky; bottom: 0; padding: 8px 0 2px; background: linear-gradient(rgba(255,255,255,0), var(--sb-surface) 30%); }
.gm-hint { margin: 0; padding: 6px 0 0; }

/* Stage */
.gm-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; align-items: center; background-color: #ECECF0; background-image: radial-gradient(#D6D6DD 1px, transparent 1px); background-size: 16px 16px; }
.gm-canvas-wrap { position: relative; flex: none; box-shadow: 0 10px 40px rgba(24,24,27,0.18); touch-action: none; }
.gm-canvas-wrap.gm-see, .gm-prev.gm-see { background-color: #fff; background-image: linear-gradient(45deg, #E4E4E7 25%, transparent 25%), linear-gradient(-45deg, #E4E4E7 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #E4E4E7 75%), linear-gradient(-45deg, transparent 75%, #E4E4E7 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }
#gm-canvas { display: block; cursor: grab; touch-action: none; }
#gm-canvas:active { cursor: grabbing; }
.gm-selbox { position: absolute; pointer-events: none; border: 1.5px dashed #3B82F6; border-radius: 4px; }
.gm-handle { position: absolute; right: -14px; bottom: -14px; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid #3B82F6; display: grid; place-items: center; color: #3B82F6; pointer-events: auto; cursor: nwse-resize; touch-action: none; box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
.gm-handle .sb-ico { width: 12px; height: 12px; }
.gm-guide { position: absolute; background: #EC4899; pointer-events: none; }
.gm-keep { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.gm-keepbox { position: absolute; border: 1.5px dashed rgba(24,24,27,0.55); background: rgba(24,24,27,0.08); display: flex; align-items: flex-end; justify-content: center; padding: 6px; }
.gm-keepbox span { font-size: 10px; font-weight: 600; color: #fff; background: rgba(24,24,27,0.7); border-radius: 6px; padding: 2px 6px; text-align: center; line-height: 1.3; }
.gm-keepside { align-items: center; }
.gm-gx { top: 0; bottom: 0; left: 50%; width: 1px; }
.gm-gy { left: 0; right: 0; top: 50%; height: 1px; }
.gm-itools { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: 2px; padding: 4px; background: var(--sb-surface); border: 1px solid var(--sb-border); border-radius: 12px; box-shadow: var(--shadow-md); }
.gm-itools button { width: 36px; height: 34px; border: 0; background: transparent; color: var(--sb-text); border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.gm-itools button:hover { background: var(--sb-surface-2); }
.gm-itools .sb-ico { width: 17px; height: 17px; }
.gm-div { width: 1px; margin: 4px 2px; background: var(--sb-border); }
.gm-dims { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(24,24,27,0.7); color: #fff; font-size: 11px; font-weight: 500; padding: 3px 10px; border-radius: 999px; pointer-events: none; white-space: nowrap; }
.gm-adding { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); background: var(--sb-text); color: #fff; font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; z-index: 4; }
.gm-adding[hidden], .gm-itools[hidden], .gm-selbox[hidden], .gm-guide[hidden] { display: none; }

/* Background */
.gm-sw { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.gm-sw button { aspect-ratio: 1; border-radius: 50%; border: 1px solid rgba(0,0,0,0.1); padding: 0; cursor: pointer; }
.gm-sw button.on { outline: 2px solid var(--sb-text); outline-offset: 2px; }
.gm-sw-s { grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.gm-bgnow { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 8px; border: 1px solid var(--sb-border); border-radius: 10px; }
.gm-bgthumb { width: 34px; height: 48px; border-radius: 6px; background-size: cover; background-position: center; flex: none; }
.gm-bgnow b { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-bgnow small { display: block; font-size: 11px; color: var(--sb-muted); }

/* Add / edit */
.gm-edit { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--sb-border); }
.gm-tin { width: 100%; border: 1px solid var(--sb-border); border-radius: 10px; padding: 8px 10px; font: inherit; font-size: 13px; resize: vertical; outline: none; }
.gm-tin:focus { border-color: var(--sb-accent); box-shadow: 0 0 0 3px var(--sb-accent-soft); }

/* Layers */
.gm-ly { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.gm-ly:hover { background: var(--sb-surface-2); }
.gm-ly.on { border-color: var(--sb-accent); background: var(--sb-accent-soft); }
.gm-lyth { width: 32px; height: 32px; flex: none; border-radius: 8px; background: var(--sb-surface-2); display: grid; place-items: center; overflow: hidden; font-size: 11px; }
.gm-lyth img { width: 100%; height: 100%; object-fit: contain; }
.gm-lynm { display: block; font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gm-ly small { display: block; font-size: 10.5px; color: var(--sb-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gm-ly button { width: 26px; height: 26px; flex: none; border: 0; background: transparent; color: var(--sb-muted); border-radius: 6px; display: grid; place-items: center; cursor: pointer; }
.gm-ly button:hover { background: var(--sb-border); color: var(--sb-text); }
.gm-ly button .sb-ico { width: 14px; height: 14px; }

/* Phone tabs (hidden on desktop) */
.gm-tabs { display: none; }

/* Dialogs */
.gm-ov { position: absolute; inset: 0; z-index: 20; background: rgba(24,24,27,0.4); display: none; place-items: center; padding: 16px; }
.gm-ov.open { display: grid; }
.gm-modal { width: min(420px, 100%); max-height: 100%; overflow-y: auto; background: var(--sb-surface); border-radius: 16px; padding: 18px; box-shadow: var(--shadow-xl); }
.gm-modal h2 { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.gm-modal p { margin: 0 0 12px; font-size: 12.5px; color: var(--sb-muted); }
.gm-prev { border-radius: 10px; background: var(--sb-surface-2); display: grid; place-items: center; padding: 8px; margin-bottom: 12px; }
.gm-prev img { display: block; max-width: 100%; max-height: 300px; box-shadow: var(--shadow-sm); }
.gm-check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-top: 12px; cursor: pointer; }
.gm-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.gm-danger { background: var(--sb-red) !important; border-color: var(--sb-red) !important; color: #fff !important; }

/* Medium screens: narrower sides */
@media (max-width: 1100px) and (min-width: 769px) {
  .gm-root { grid-template-columns: 270px minmax(0, 1fr) 250px; }
  .gm-ttl { display: none; }
}

/* Phone */
@media (max-width: 768px) {
  .gm-root { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) calc(60px + env(safe-area-inset-bottom)); padding-top: env(safe-area-inset-top); }
  .gm-top { flex-wrap: wrap; row-gap: 8px; padding: 10px 12px; }
  .gm-ttl { font-size: 14px; }
  .gm-shapepick { order: 9; width: 100%; }
  .gm-shapebtn { width: 100%; justify-content: flex-start; }
  .gm-shapebtn .sb-ico { margin-left: auto; }
  .gm-shapemenu { position: fixed; left: 8px; right: 8px; top: auto; bottom: calc(68px + env(safe-area-inset-bottom)); width: auto; max-height: 70vh; }
  .gm-ttl { display: none; }
  .gm-keepbox span { display: none; }
  .gm-side { display: none; }
  .gm-side.open { display: block; position: absolute; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom)); max-height: 62%; z-index: 10; border: 0; border-top: 1px solid var(--sb-border); border-radius: 18px 18px 0 0; box-shadow: 0 -12px 30px rgba(24,24,27,0.14); }
  .gm-side.open .gm-sec { display: none; border-bottom: 0; }
  .gm-side.open .gm-sec.show { display: block; }
  .gm-side.open .gm-grab { display: block; width: 38px; height: 5px; border-radius: 9px; background: var(--sb-border); margin: 8px auto 0; }
  .gm-filters { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-right: -14px; padding-right: 14px; }
  .gm-cgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .gm-cgrid .ct-tcap { display: none; }
  .gm-search input, .gm-tin { font-size: 16px; }
  .gm-itools { top: 8px; }
  .gm-itools button { width: 40px; height: 36px; }
  .gm-tabs { display: flex; background: var(--sb-surface); border-top: 1px solid var(--sb-border); padding-bottom: env(safe-area-inset-bottom); z-index: 11; }
  .gm-tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: transparent; color: var(--sb-muted); font-size: 10.5px; font-weight: 600; cursor: pointer; }
  .gm-tabs button .sb-ico { width: 20px; height: 20px; }
  .gm-tabs button.on { color: var(--sb-accent); }
}
