:root {
  --bg: #f6f6f4;
  --panel: #fff;
  --ink: #111;
  --muted: #6b6b6b;
  --line: #e4e4e0;
  --accent: #111;
  --danger: #b3261e;
  --warn: #9a6200;
  --ok: #1d7a3a;
  --radius: 8px;
  --sidebar: 220px;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img, video { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 32px; width: min(380px, 100%); }
.login h1 { font-size: 20px; margin: 0 0 6px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login .btn { width: 100%; margin-top: 8px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: #111; color: #eee; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.sidebar__brand { font-weight: 700; padding: 6px 10px 18px; letter-spacing: .02em; }
.sidebar__brand small { display: block; font-weight: 400; color: #999; font-size: 12px; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; text-decoration: none; color: #cfcfcf; }
.sidebar a:hover { background: #222; color: #fff; }
.sidebar a.is-active { background: #fff; color: #111; }
.sidebar svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.badge-count { margin-left: auto; background: #e8a33d; color: #111; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(246,246,244,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 12px 28px; min-height: 60px; }
.topbar h1 { font-size: 18px; margin: 0; }
.topbar__spacer { flex: 1; }
.save-state { font-size: 13px; color: var(--muted); }
.save-state.is-dirty { color: var(--warn); font-weight: 600; }
.content { padding: 24px 28px 80px; max-width: 1180px; }
.menu-toggle { display: none; }

/* ---------- Generic UI ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--ink); background: var(--ink); color: #fff; border-radius: 6px; padding: 8px 14px; font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap; }
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--ghost { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { border-color: #bbb; opacity: 1; }
.btn--danger { background: var(--panel); color: var(--danger); border-color: #f0c9c6; }
.btn--sm { padding: 5px 9px; font-size: 12px; }
.icon-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; width: 30px; height: 30px; display: inline-grid; place-items: center; padding: 0; }
.icon-btn:hover { border-color: #bbb; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card > h2 { font-size: 15px; margin: 0 0 4px; }
.card > .sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.card__head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card__head h2 { font-size: 15px; margin: 0; flex: 1; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; }
.field small { color: var(--muted); font-size: 12px; }
.input, .field input:not([type=checkbox]):not([type=color]):not([type=radio]), .field select, .field textarea {
  width: 100%; border: 1px solid #d6d6d1; border-radius: 6px; padding: 8px 10px; background: #fff; outline: none;
}
.field textarea { min-height: 80px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: #111; box-shadow: 0 0 0 2px rgba(0,0,0,.08); }
.field.is-invalid input { border-color: var(--danger); }
.inline { display: flex; align-items: center; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: #111; }
.hint { color: var(--muted); font-size: 12.5px; }
.muted { color: var(--muted); }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; border-radius: 20px; padding: 2px 9px; background: #eee; }
.pill--ok { background: #e3f3e8; color: var(--ok); }
.pill--warn { background: #fdf0d9; color: var(--warn); }
.pill--danger { background: #fbe4e2; color: var(--danger); }
.pill--draft { background: #ececec; color: #555; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafaf8; white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid #f0f0ec; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-clickable:hover td { background: #fafaf8; cursor: pointer; }
.thumb { width: 44px; height: 54px; border-radius: 4px; background: #f1f1ef; overflow: hidden; flex-shrink: 0; display: grid; place-items: center; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: contain; }
.thumb .ph-mini { font-size: 9px; color: #aaa; text-align: center; padding: 2px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .input { max-width: 280px; }

/* ---------- Product editor ---------- */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.variant { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: #fcfcfb; }
.variant__head { display: flex; gap: 10px; align-items: end; margin-bottom: 12px; }
.variant__head .field { margin: 0; flex: 1; }
.swatch-input { width: 44px; height: 36px; border: 1px solid #d6d6d1; border-radius: 6px; padding: 2px; background: #fff; }
.media-list { display: flex; flex-wrap: wrap; gap: 10px; }
.media-item { width: 116px; }
.media-item__box { width: 116px; height: 145px; border: 1px solid var(--line); border-radius: 6px; background: #f1f1ef; overflow: hidden; display: grid; place-items: center; position: relative; }
.media-item__box img, .media-item__box video { width: 100%; height: 100%; object-fit: contain; }
.media-item__box .ph-mini { font-size: 11px; color: #999; text-align: center; padding: 6px; }
.media-item__tag { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.7); color: #fff; font-size: 10px; border-radius: 3px; padding: 1px 5px; }
.media-item__pick { display: block; position: relative; padding: 0; border: 0; background: none; border-radius: 6px; }
.media-item__pick:hover .media-item__box { border-color: #111; }
.media-item__pick.is-placeholder .media-item__box { border: 1.5px dashed #c9c9c3; background: #fafaf8; }
.media-item__pick.is-placeholder .ph-mini b { display: block; color: #111; font-size: 12px; margin-bottom: 4px; }
.media-item__pick.is-placeholder:hover .media-item__box { border-color: #111; }
.media-item__replace { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); background: rgba(0,0,0,.75); color: #fff; font-size: 11px; border-radius: 4px; padding: 2px 8px; opacity: 0; transition: opacity .15s; }
.media-item__pick:hover .media-item__replace, .media-item__pick:focus-visible .media-item__replace { opacity: 1; }
.media-item__tools { display: flex; gap: 4px; justify-content: center; margin-top: 5px; }
.media-item__tools { gap: 3px !important; }
.media-item__tools .icon-btn { width: 21px; height: 24px; }
.media-item__tools .icon-btn svg { width: 13px; height: 13px; }
.media-add { width: 116px; height: 145px; border: 1.5px dashed #c9c9c3; border-radius: 6px; background: transparent; color: var(--muted); display: grid; place-items: center; text-align: center; font-size: 12px; padding: 8px; }
.media-add:hover { border-color: #111; color: #111; }
.stock-table { border-collapse: collapse; }
.stock-table th, .stock-table td { padding: 4px 6px; text-align: left; font-size: 12.5px; }
.stock-table input { width: 76px; border: 1px solid #d6d6d1; border-radius: 6px; padding: 6px 8px; }
.stock-table input.is-zero { border-color: #f0c9c6; background: #fff8f7; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid #d6d6d1; border-radius: 6px; padding: 6px; background: #fff; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #eee; border-radius: 4px; padding: 3px 4px 3px 8px; font-size: 12.5px; }
.chip button { border: 0; background: none; padding: 0 3px; color: #777; }
.chips input { border: 0 !important; outline: none; flex: 1; min-width: 80px; padding: 3px !important; box-shadow: none !important; }

/* Rich text */
.rte { border: 1px solid #d6d6d1; border-radius: 6px; background: #fff; }
.rte__bar { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 4px; }
.rte__bar button { border: 0; background: none; border-radius: 4px; min-width: 28px; height: 26px; font-size: 13px; }
.rte__bar button:hover { background: #f0f0ec; }
.rte__body { min-height: 110px; padding: 10px 12px; outline: none; font-size: 13.5px; }
.rte__body p { margin: 0 0 8px; }
.rte__body ul { margin: 0 0 8px; padding-left: 20px; }

/* ---------- Homepage sections ---------- */
.section-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 12px; }
.section-card__head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafaf8; border-radius: var(--radius) var(--radius) 0 0; }
.section-card__head strong { flex: 1; font-size: 13.5px; }
.section-card__body { padding: 14px; }
.media-field { display: flex; gap: 12px; align-items: center; }
.media-field .media-item__box { width: 120px; height: 90px; }

/* ---------- Media library + picker ---------- */
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.lib-item { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; text-align: left; padding: 0; }
.lib-item.is-selected { outline: 2px solid #111; outline-offset: 1px; }
.lib-item__img { height: 150px; background: #f1f1ef; display: grid; place-items: center; overflow: hidden; }
.lib-item__img img, .lib-item__img video { width: 100%; height: 100%; object-fit: contain; }
.lib-item__meta { padding: 8px; font-size: 11.5px; word-break: break-all; color: var(--muted); }
.lib-item__meta b { color: var(--ink); font-weight: 600; display: block; margin-bottom: 2px; }
.lib-item__actions { display: flex; gap: 6px; padding: 0 8px 8px; }
.dropzone { border: 1.5px dashed #c9c9c3; border-radius: var(--radius); padding: 22px; text-align: center; background: #fcfcfb; margin-bottom: 16px; }
.dropzone.is-over { border-color: #111; background: #f3f3ef; }
.dropzone p { margin: 0 0 10px; color: var(--muted); }

.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 24px; }
.dialog { background: var(--panel); border-radius: 12px; width: min(920px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden; }
.dialog__head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dialog__head h2 { margin: 0; font-size: 16px; flex: 1; }
.dialog__body { padding: 18px; overflow-y: auto; }
.dialog__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

/* ---------- Orders ---------- */
.order-detail { background: #fafaf8; }
.order-detail td { padding: 16px 18px; }
.order-detail dl { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.order-detail dt { color: var(--muted); }
.order-detail dd { margin: 0; }
.status-select { border: 1px solid #d6d6d1; border-radius: 6px; padding: 4px 6px; background: #fff; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 360px; }
.toast--error { background: var(--danger); }
.progress { height: 4px; background: #eee; border-radius: 2px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: #111; width: 0; transition: width .2s; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .editor-grid { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: 240px; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.is-open { transform: none; }
  .menu-toggle { display: inline-grid; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .content { padding: 16px 16px 80px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

/* ---------- Image editor ---------- */
.editor { width: min(1040px, 100%); }
.editor__body { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 20px; align-items: start; }
.editor__stage { position: relative; display: grid; place-items: center; min-height: 320px; overflow: hidden; border-radius: 6px; user-select: none; touch-action: none;
  background: repeating-conic-gradient(#e9e9e6 0% 25%, #f7f7f5 0% 50%) 50% / 18px 18px; }
.editor__stage canvas { display: block; max-width: 100%; }
.editor__crop { position: absolute; cursor: move; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .5); outline: 1px solid #fff;
  background-image: linear-gradient(rgba(255,255,255,.45) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.45) 1px, transparent 1px);
  background-size: 33.333% 33.333%; background-position: -1px -1px; }
.editor__h { position: absolute; width: 16px; height: 16px; background: #fff; border: 1px solid #111; border-radius: 2px; }
.editor__h[data-h="nw"] { left: -8px; top: -8px; cursor: nwse-resize; }
.editor__h[data-h="ne"] { right: -8px; top: -8px; cursor: nesw-resize; }
.editor__h[data-h="sw"] { left: -8px; bottom: -8px; cursor: nesw-resize; }
.editor__h[data-h="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.editor__ratios { display: flex; flex-wrap: wrap; gap: 6px; }
.editor__ratios .is-on, .editor__side .btn.is-on { background: #111; color: #fff; border-color: #111; }
.editor__side input[type=range] { width: 100%; accent-color: #111; }
@media (max-width: 760px) { .editor__body { grid-template-columns: 1fr; } }

/* ---------- Import from Google Drive links ---------- */
.link-import { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); text-align: left; }
.link-import p { margin: 0 0 8px; color: var(--muted); }
.link-import__row { display: flex; gap: 8px; align-items: stretch; }
.link-import__row textarea { flex: 1; resize: vertical; min-height: 44px; font-size: 13px; }
.progress--busy > div { width: 35% !important; animation: progress-busy 1.1s ease-in-out infinite; }
@keyframes progress-busy { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
