:root {
  --primary: #8e24aa;
  --primary-dark: #6a1b9a;
  --bg: #f6f4f8;
  --card: #fff;
  --text: #1f1a24;
  --muted: #7a7184;
  --border: #e7e1ec;
  --ok: #2e7d32;
  --danger: #c62828;
  --radius: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
a { color: var(--primary); }

/* ---------- Каркас ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.topbar { display: none; }
.sidebar { background: #2a1733; color: #f3e9f7; padding: 20px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { font-size: 20px; font-weight: 700; padding: 0 8px 8px; }
.logo.big { font-size: 30px; color: var(--primary); padding: 0; }
.role-tag { margin: 0 8px 16px; font-size: 12px; color: #d1b3df; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { color: #e6d5ee; text-decoration: none; padding: 10px 12px; border-radius: 10px; display: flex; align-items: center; gap: 8px; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; padding: 12px 8px 0; color: #d1b3df; font-size: 13px; }
main { padding: 28px 32px 60px; min-width: 0; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .value { font-size: 20px; }
  .card { padding: 14px; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 5; background: #2a1733; color: #fff; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar .logo { padding: 0; font-size: 18px; }
  .topbar .muted { color: #d1b3df; margin-left: auto; font-size: 13px; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .2s; height: auto; }
  .sidebar.open { transform: none; }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 15; }
  main { padding: 16px 14px 60px; }
  h1 { font-size: 21px; }
}
.icon-btn { background: none; border: none; color: inherit; font-size: 22px; padding: 4px 8px; cursor: pointer; }

/* ---------- Элементы ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.grid > * { min-width: 0; }
.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat.accent { background: linear-gradient(135deg, #8e24aa, #e91e63); color: #fff; border: none; }
.stat.accent .label { color: rgba(255,255,255,.85); }
.two { grid-template-columns: 1.4fr 1fr; }
@media (max-width: 1000px) { .two { grid-template-columns: 1fr; } }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
input, select, textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text); width: 100%; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; flex: 1 1 180px; max-width: 360px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #e1bee7; border-color: var(--primary); }
input[type=checkbox] { width: 18px; height: 18px; }
input[type=color] { padding: 2px; height: 42px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }

.btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 9px 16px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.25); }
.btn.small { padding: 5px 11px; font-size: 13px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #faf7fc; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }

.thumb { width: 44px; height: 44px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 22px; overflow: hidden; flex-shrink: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Карточки товаров — удобно и на телефоне */
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.pcard { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.pcard .img { aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; font-size: 56px; position: relative; }
.pcard .img img { width: 100%; height: 100%; object-fit: cover; }
.pcard .img .badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; flex-wrap: wrap; }
.pcard .body { padding: 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.pcard .name { font-weight: 600; }
.pcard .price { font-size: 18px; font-weight: 700; }
.pcard .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; }
.pcard.off { opacity: .55; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; background: #eee; white-space: nowrap; }
.st-new { background: #e3f2fd; color: #1565c0; }
.st-confirmed { background: #ede7f6; color: #4527a0; }
.st-shipped { background: #e0f7fa; color: #00838f; }
.st-delivered { background: #e8f5e9; color: #2e7d32; }
.st-cancelled { background: #ffebee; color: #c62828; }
.pill.ok { background: #e8f5e9; color: #2e7d32; }
.pill.bad { background: #ffebee; color: #c62828; }
.pill.violet { background: #f3e5f5; color: #8e24aa; }
.pill.dark { background: #2a1733; color: #fff; }
.pill.hot { background: #ff6f00; color: #fff; }
.pill.sale { background: #ff3b5c; color: #fff; font-weight: 700; }
.pill.new { background: #7a3cf0; color: #fff; font-weight: 700; }
.badge { background: #ff5252; color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; margin-left: auto; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; margin-bottom: 22px; }
.bar { flex: 1; background: linear-gradient(180deg, #ba68c8, #8e24aa); border-radius: 6px 6px 0 0; position: relative; min-height: 2px; }
.bar span { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.list-row:last-child { border-bottom: none; }

/* Тарифы */
.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.plan { display: flex; flex-direction: column; gap: 8px; }
.plan.current { border: 2px solid var(--primary); }
.plan .price { font-size: 28px; font-weight: 800; }
.plan ul { margin: 0; padding-left: 18px; color: var(--muted); }

/* Баннеры */
.banner-prev { border-radius: 16px; color: #fff; padding: 18px; display: flex; align-items: center; gap: 14px; min-height: 100px; background-size: cover; background-position: center; }
.banner-prev .e { font-size: 44px; }
.banner-prev .t { font-size: 20px; font-weight: 700; }

/* Раздел главной: плашка ниже, картинка выше неё — как в приложении */
.section-prev { text-align: center; }
.section-prev .pic { position: relative; height: 130px; display: flex; align-items: flex-end; justify-content: center; }
.section-prev .pic::before { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 74px; border-radius: 22px; background: #F3F0FA; }
.section-prev .pic img { position: relative; height: 124px; max-width: 100%; object-fit: contain; margin-bottom: 4px; }
.section-prev .pic span { position: relative; font-size: 72px; line-height: 1; margin-bottom: 4px; }
.section-prev .t { font-weight: 600; margin-top: 6px; }

/* Загрузка фото */
.uploader { display: flex; align-items: center; gap: 12px; }
.uploader .prev { width: 96px; height: 96px; border-radius: 12px; border: 1px dashed var(--border); display: flex; align-items: center; justify-content: center; font-size: 40px; overflow: hidden; background: #faf7fc; }
.uploader .prev img { width: 100%; height: 100%; object-fit: cover; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #f3e5f5, #fce4ec); padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }

.modal { position: fixed; inset: 0; background: rgba(20, 10, 25, .45); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.modal-box { width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } .modal { padding: 0; align-items: flex-end; } .modal-box { max-height: 96vh; border-radius: 18px 18px 0 0; } }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #2a1733; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 40; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: 92vw; }
.toast.err { background: var(--danger); }
.nowrap { white-space: nowrap; }

/* Группы в меню админки */
.nav-group { margin: 14px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #b99ac8; }
/* Вкладки разделов */
.seg { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.seg a { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--text); text-decoration: none; }
.seg a img { width: 26px; height: 26px; object-fit: contain; }
.seg a.on { border-color: var(--primary); background: #f6ecfa; font-weight: 600; }
/* Карточки категорий — как в приложении */
.sub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.sub-card { background: #fff; border: 1px solid var(--border); border-radius: 18px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.sub-card.off { opacity: .55; }
.sub-tile { position: relative; height: 170px; border-radius: 16px; overflow: hidden; }
.sub-tile b { position: absolute; left: 12px; top: 10px; right: 10px; font-size: 14px; line-height: 1.25; }
.sub-tile img { position: absolute; left: 6px; bottom: 4px; width: calc(100% - 12px); height: 105px; object-fit: contain; object-position: bottom; }
.sub-emoji { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; font-size: 46px; }
.sub-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.sub-move { display: flex; gap: 4px; }
.sub-move .btn { padding: 4px 10px; }
.btn:disabled { opacity: .4; cursor: default; }
.sub-add { align-items: center; justify-content: center; min-height: 250px; border-style: dashed; color: var(--muted); font: inherit; cursor: pointer; }
.sub-add span { font-size: 36px; color: var(--primary); }
.sub-add:hover { border-color: var(--primary); }

/* Кадрирование фото */
.cropper { position: fixed; inset: 0; z-index: 200; background: rgba(20, 12, 28, .72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.cropper-box { background: #fff; border-radius: 20px; padding: 20px; width: min(480px, 100%); }
.cropper-box h2 { margin: 0 0 12px; }
.cropper-stage { position: relative; width: 100%; border-radius: 16px; overflow: hidden; background: #2a2230; touch-action: none; }
.cropper-stage canvas { width: 100%; height: 100%; display: block; cursor: grab; }
.cropper-stage canvas:active { cursor: grabbing; }
.cropper-frame { position: absolute; inset: 0; pointer-events: none; border-radius: 16px; box-shadow: inset 0 0 0 2px #fff; }
.cropper-zoom { margin-top: 12px; padding: 0; accent-color: var(--primary); }
.uploader.crop-square .prev img { object-fit: contain; background: #fff; }
.uploader.crop-shop .prev { width: 192px; }
