:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e2e4e9;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(var(--tabbar-h) + 12px);
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, select, .selectable { -webkit-user-select: text; user-select: text; }

a { color: var(--primary); text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.topbar .actions { display: flex; gap: 8px; }

.container { padding: 14px; max-width: 900px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  min-height: 44px;
  touch-action: manipulation;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-d); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn-icon { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 18px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text); font-family: inherit;
}
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar a.active { color: var(--primary); }
.tabbar .ic { font-size: 21px; }

.grid-photos {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px;
}
.photo-thumb {
  position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden;
  background: #eee; border: 2px solid transparent;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .dot {
  position: absolute; top: 6px; right: 6px; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}
.dot-unused { background: var(--ok); }
.dot-used { background: var(--muted); }
.dot-rework { background: var(--warn); }
.photo-thumb.selected { border-color: var(--primary); }
.photo-thumb .check {
  position: absolute; bottom: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.45); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}

.list-row {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: #eee; flex-shrink: 0; }
.list-row .info { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-row .price { font-weight: 700; font-size: 15px; white-space: nowrap; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 700;
}
.badge-draft { background: #e5e7eb; color: #374151; }
.badge-listed { background: #dbeafe; color: #1d4ed8; }
.badge-sold { background: #dcfce7; color: #15803d; }
.badge-archived { background: #f3f4f6; color: #9ca3af; }

.profit-pos { color: var(--ok); font-weight: 700; }
.profit-neg { color: var(--danger); font-weight: 700; }

.search-box { position: sticky; top: 57px; z-index: 15; background: var(--bg); padding: 10px 14px 4px; }
.search-box input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  font-size: 16px; background: #fff;
}

.filters-row { display: flex; gap: 8px; overflow-x: auto; padding: 6px 14px 10px; -webkit-overflow-scrolling: touch; }
.filters-row select { flex-shrink: 0; padding: 8px 10px; border-radius: 20px; border: 1px solid var(--border); background: #fff; font-size: 13px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }

.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 14px); left: 50%; transform: translateX(-50%);
  background: #1a1d23; color: #fff; padding: 10px 18px; border-radius: 30px; font-size: 14px;
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
  background: var(--card); width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.modal-sheet .modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-sheet .modal-head h2 { font-size: 17px; margin: 0; }

@media (min-width: 700px) {
  .modal-overlay { align-items: center; }
  .modal-sheet { border-radius: 16px; }
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-card .val { font-size: 22px; font-weight: 800; }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chip { display: inline-block; background: var(--border); border-radius: 20px; padding: 4px 10px; font-size: 12px; margin: 2px; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box { background: var(--card); border-radius: 16px; padding: 24px; width: 100%; max-width: 360px; }
.login-box h1 { text-align: center; font-size: 20px; margin-bottom: 20px; }
.err-msg { color: var(--danger); font-size: 14px; margin-bottom: 10px; text-align: center; }

.editor-wrap { background: #000; }
.editor-canvas-holder { position: relative; width: 100%; aspect-ratio: 3/4; background: #111; overflow: hidden; touch-action: none; }
.editor-canvas-holder canvas { position: absolute; top: 0; left: 0; }
.editor-controls { background: var(--card); padding: 14px; }
.slider-row { margin-bottom: 14px; }
.slider-row .lbl-row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.slider-row input[type=range] { width: 100%; }
.tool-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; }
.tool-tabs button { flex-shrink: 0; padding: 8px 14px; border-radius: 20px; border: 1px solid var(--border); background: #fff; font-size: 13px; font-weight: 600; }
.tool-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted);
  font-size: 14px;
}
.drop-zone.drag { border-color: var(--primary); color: var(--primary); background: #eff6ff; }

.spinner {
  width: 20px; height: 20px; border: 3px solid rgba(0,0,0,.15); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
