/* Paint by Numbers Studio — світла мінімалістична тема */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #475467;
  --muted: #8a94a6;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #eaf1ff;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .16);
  --panel-w: 300px;
  --font: Inter, "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; overflow: hidden; }
#app { height: 100%; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }

/* ---------- Кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s; }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: rgba(16, 24, 40, .05); }
.btn.icon-only { width: 36px; padding: 0; }
.btn.sm { height: 30px; font-size: 13px; }
.btn.icon-only.sm { width: 30px; }
.btn.big { height: 48px; font-size: 15px; font-weight: 600; padding: 0 20px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.active { background: var(--accent-soft); border-color: #bfd3ff; color: var(--accent-2); }
.btn.primary.active { background: var(--accent-2); color: #fff; }

/* ---------- Верхня панель ---------- */
.topbar { height: 60px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #2563eb, #7c3aed); flex: none; }
.brand-name { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

/* ---------- Робоча область ---------- */
.workspace { flex: 1; display: flex; min-height: 0; position: relative; }
.panel { width: var(--panel-w); flex: none; background: var(--surface); display: flex; flex-direction: column; min-height: 0; z-index: 10; }
.left-panel { border-right: 1px solid var(--border); }
.right-panel { border-left: 1px solid var(--border); width: 320px; }
.panel-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.panel-foot { padding: 12px 14px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.stale-note { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--warn); margin: 0 0 8px; }

.panel-section { border-bottom: 1px solid var(--border); }
.panel-section > summary { list-style: none; display: flex; align-items: center; gap: 9px; padding: 13px 16px; cursor: pointer; font-weight: 600; user-select: none; }
.panel-section > summary::-webkit-details-marker { display: none; }
.panel-section > summary > span { flex: 1; }
.panel-section > summary > svg:last-child { color: var(--muted); transition: transform .2s; }
.panel-section[open] > summary > svg:last-child { transform: rotate(180deg); }
.panel-section > summary > svg:first-child { color: var(--accent); }
.section-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.field.row { flex-direction: row; }
.field-head { display: flex; justify-content: space-between; font-weight: 500; color: var(--text-2); }
.slider-value { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
select, input[type=number] { height: 36px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 10px; background: var(--surface); min-width: 0; }
input[type=number] { width: 100%; }
select:focus, input[type=number]:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=color] { width: 40px; height: 30px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--border); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--border); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); margin-top: -7px; box-shadow: var(--shadow); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); }

.segmented { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-btn { flex: 1; border: 0; background: transparent; border-radius: 7px; padding: 7px 8px; cursor: pointer; font-weight: 500; font-size: 13px; color: var(--text-2); white-space: nowrap; transition: background .15s, color .15s, box-shadow .15s; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--accent-2); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.segmented.grid4 { display: grid; grid-template-columns: 1fr 1fr; }
.segmented.grid4 .seg-btn { padding: 10px 8px; }

/* ---------- Центр ---------- */
.center { flex: 1; position: relative; min-width: 0; background: radial-gradient(circle at 1px 1px, #dfe3ea 1px, transparent 0) 0 0/20px 20px, var(--bg); overflow: hidden; }
.canvas-wrap { position: absolute; inset: 0; }
.main-canvas { display: block; touch-action: none; cursor: default; }
.main-canvas[data-tool=pan] { cursor: grab; }
.main-canvas[data-tool=fill], .main-canvas[data-tool=merge], .main-canvas[data-tool=delete], .main-canvas[data-tool=select] { cursor: pointer; }
.main-canvas[data-tool=split], .main-canvas[data-tool=picker] { cursor: crosshair; }
.main-canvas[data-tool=brush] { cursor: none; }
.floating { position: absolute; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; display: flex; gap: 3px; align-items: center; z-index: 5; }
.view-switch { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 5; box-shadow: var(--shadow); background: var(--surface); }
.toolbar { left: 14px; top: 50%; transform: translateY(-50%); flex-direction: column; }
.toolbar .btn { border-color: transparent; }
.toolbar .btn.active { border-color: #bfd3ff; }
.brush-size { width: 120px; padding: 6px 4px 2px; position: absolute; left: 52px; bottom: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.zoombar { right: 14px; bottom: 14px; }
.zoombar .btn { border-color: transparent; height: 32px; }
.zoombar .btn.icon-only { width: 32px; }
.zoom-btn { min-width: 58px; font-variant-numeric: tabular-nums; font-size: 13px; padding: 0 6px; }
.cropbar { top: 14px; left: 50%; transform: translateX(-50%); padding: 6px 8px; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 28px); }
.ratio-in { width: 56px !important; }

.empty-state { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; z-index: 6; }
.drop-card { max-width: 520px; width: 100%; text-align: center; background: var(--surface); border: 2px dashed var(--border-strong); border-radius: 20px; padding: 40px 32px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.drop-card h1 { font-size: 22px; }
.drop-card p { margin: 0; color: var(--text-2); }
.drop-icon { width: 80px; height: 80px; border-radius: 20px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); }
.restore { width: 100%; margin-top: 8px; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.restore-text { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text-2); }
.drop-hint { position: absolute; inset: 12px; border: 3px dashed var(--accent); border-radius: 18px; background: rgba(37, 99, 235, .08); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--accent-2); font-weight: 600; font-size: 16px; z-index: 30; pointer-events: none; }

.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(244, 245, 247, .55); backdrop-filter: blur(2px); z-index: 25; }
.busy-card { width: min(360px, calc(100% - 32px)); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 26px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-stage { font-weight: 600; }
.progress { width: 100%; height: 6px; background: var(--accent-soft); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .25s ease; }
.progress-pct { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Права панель ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--border); flex: none; }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 6px 11px; border: 0; background: none; cursor: pointer; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--accent-2); border-bottom-color: var(--accent); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #fee2e2; color: var(--danger); font-size: 11px; display: inline-grid; place-items: center; }
.tab-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.empty-note { text-align: center; color: var(--muted); padding: 40px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pal-head { font-size: 13px; }
.palette-tools { display: flex; flex-wrap: wrap; gap: 4px; }
.palette-tools .btn { width: 34px; height: 34px; }
.pal-cols { display: grid; grid-template-columns: 48px 40px 1fr 40px; gap: 8px; font-size: 11px; padding: 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.pal-list { display: flex; flex-direction: column; gap: 2px; }
.pal-row { display: grid; grid-template-columns: 48px 40px 1fr 40px; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; transition: background .12s; }
.pal-row:hover { background: var(--surface-2); }
.pal-row.selected { background: var(--accent-soft); border-color: #bfd3ff; }
.pal-row.target { outline: 1px dashed var(--ok); }
.num-input { height: 28px !important; padding: 0 6px !important; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.swatch { width: 40px; height: 28px; border-radius: 6px; border: 1px solid rgba(16, 24, 40, .12); cursor: pointer; display: grid; place-items: center; padding: 0; }
.swatch svg { opacity: 0; transition: opacity .15s; }
.pal-row:hover .swatch svg { opacity: .8; }
.hidden-color { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
.hex { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-2); }
.count { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.inspector { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.mini-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 4px; max-height: 150px; overflow-y: auto; }
.mini { height: 28px; border-radius: 6px; border: 1px solid rgba(16, 24, 40, .12); cursor: pointer; font-size: 11px; font-weight: 700; padding: 0; }
.mini.active { outline: 2px solid var(--accent); outline-offset: 1px; }

.qc-summary { display: flex; gap: 8px; align-items: center; padding: 12px; border-radius: 10px; font-weight: 600; margin-bottom: 10px; }
.qc-summary.ok { background: #ecfdf5; color: var(--ok); }
.qc-summary.warn { background: #fffbeb; color: var(--warn); }
.qc-kinds { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.qc-kind { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 8px; border-radius: 6px; color: var(--muted); }
.qc-kind.has { color: var(--text); background: var(--surface-2); }
.qc-list { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.qc-item { display: flex; align-items: center; gap: 8px; text-align: left; border: 0; background: none; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.qc-item:hover { background: var(--surface-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }
.dot.double { background: #7c3aed; }

/* ---------- Діалоги, меню, сповіщення ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(16, 24, 40, .35); display: grid; place-items: center; z-index: 100; padding: 16px; opacity: 0; transition: opacity .2s; }
.modal-back.show { opacity: 1; }
.modal { width: min(760px, 100%); max-height: calc(100vh - 32px); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; transform: translateY(8px) scale(.98); transition: transform .2s; }
.modal-back.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 8px 18px 16px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.export-grid > div { display: flex; flex-direction: column; gap: 14px; }
.variant-list { display: flex; flex-direction: column; gap: 6px; }
.radio { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; color: var(--text); font-weight: 500; }
.radio.active { border-color: var(--accent); background: var(--accent-soft); }
.radio input { accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-2); cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.export-info { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 12px; color: var(--text-2); }
.export-info p { margin: 0 0 4px; }
.dropdown { position: fixed; min-width: 230px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 5px; z-index: 120; animation: fade .12s ease; }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.ico-space { width: 16px; display: inline-block; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; pointer-events: none; width: max-content; max-width: calc(100% - 24px); }
.toast { display: flex; align-items: center; gap: 9px; background: #101828; color: #fff; padding: 11px 15px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: none; }
.toast-error { background: #b42318; }
.toast-ok svg { color: #6ee7b7; }

.scrim { display: none; }
.mobile-nav { display: none; }

/* ---------- Адаптивність ---------- */
@media (max-width: 1280px) { :root { --panel-w: 280px; } .right-panel { width: 290px; } }
@media (max-width: 1100px) {
  .hide-sm-label .btn-label { display: none; }
  .hide-sm-label { width: 36px; padding: 0; }
}
@media (max-width: 920px) {
  .panel { position: fixed; top: 60px; bottom: 64px; width: min(360px, 88vw) !important; box-shadow: var(--shadow-lg); transition: transform .25s ease; z-index: 50; }
  .left-panel { left: 0; transform: translateX(-105%); }
  .right-panel { right: 0; transform: translateX(105%); }
  .panel.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 60px 0 64px; background: rgba(16, 24, 40, .3); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .mobile-nav { display: flex; height: 64px; flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 4px 4px env(safe-area-inset-bottom); z-index: 60; }
  .mobile-nav button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--text-2); cursor: pointer; border-radius: 10px; }
  .mobile-nav button.accent { color: var(--accent); font-weight: 600; }
  .mobile-nav button:active { background: var(--surface-2); }
  .brand-sub { display: none; }
  .export-grid { grid-template-columns: 1fr; }
  .toasts { bottom: 78px; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 10px; height: 56px; }
  .panel { top: 56px; }
  .brand-name { font-size: 14px; }
  .top-actions .sep, .top-actions > .btn:first-child { display: none; }
  .top-actions .btn.primary .btn-label { display: none; }
  .top-actions .btn.primary { width: 36px; padding: 0; }
  .brand > div:last-child { display: none; }
  .view-switch { top: 8px; width: calc(100% - 16px); }
  .seg-btn { font-size: 12px; padding: 7px 4px; }
  .toolbar { top: auto; bottom: 10px; left: 10px; transform: none; flex-direction: row; max-width: calc(100% - 150px); overflow-x: auto; }
  .brush-size { left: 0; bottom: 50px; }
  .zoombar { bottom: 10px; right: 10px; }
  .zoombar .btn:nth-child(1), .zoombar .btn:nth-child(3) { display: none; }
  .drop-card { padding: 28px 18px; }
  .drop-card h1 { font-size: 19px; }
}
