/* ==========================================================================
   style.css — Seamless Pattern Studio
   Hanya memakai font sistem: tidak ada permintaan ke Google Fonts atau CDN
   apa pun, supaya aplikasi benar-benar berjalan offline.
   ========================================================================== */

:root {
  --ink: #19191c;
  --panel: #212126;
  --panel-2: #292930;
  --panel-3: #313138;
  --surround: #131316;
  --line: #34343c;
  --line-soft: #2a2a31;
  --text: #eceae5;
  --text-dim: #96949e;
  --text-faint: #616169;
  --accent: #7c5cff;
  --accent-soft: rgba(124, 92, 255, .16);
  --accent-dim: #5b42c9;
  --teal: #2dd4bf;
  --coral: #ff6b6b;
  --brass: #c7a34f;

  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--ui);
  font-size: 13px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.mono { font-family: var(--mono); }
.warn-text { color: var(--coral); }

svg {
  width: 15px; height: 15px;
  stroke: currentColor; fill: none;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

/* ------------------------------- Header --------------------------------- */

header {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; height: 46px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: nowrap; overflow-x: auto;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13.5px; white-space: nowrap; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--teal)); flex-shrink: 0; }

.docdim {
  color: var(--text-dim); font-size: 11.5px; font-family: var(--mono);
  padding: 4px 9px; background: var(--panel-2); border-radius: 5px; white-space: nowrap;
}

.docname { font-size: 12px; color: var(--text-dim); white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.docname b { color: var(--text); font-weight: 600; }
.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brass); display: none; }

.modebar { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.modebar button { background: transparent; border: none; border-radius: 6px; font-size: 11.5px; padding: 6px 11px; color: var(--text-dim); white-space: nowrap; }
.modebar button.active { background: var(--accent); color: #fff; }

.toolgroup { display: flex; align-items: center; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.toolgroup button { width: 28px; height: 26px; padding: 0; display: flex; align-items: center; justify-content: center; background: transparent; border: none; }
.toolgroup button:hover:not(:disabled) { background: var(--panel-3); }
.toolgroup .zlabel { width: 46px; text-align: center; font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }
.spacer { margin-left: auto; }

/* ------------------------------ Kontrol --------------------------------- */

button {
  background: var(--panel-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
  font-family: var(--ui); transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #3a3a43; border-color: #4c4c57; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .35; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-dim); }
button.ghost-accent { border-color: var(--teal); color: var(--teal); background: transparent; }
button.ghost-accent:hover:not(:disabled) { background: rgba(45, 212, 191, .12); }

.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row button { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

label.field {
  display: block; font-size: 10.5px; color: var(--text-dim);
  margin: 9px 0 4px; text-transform: uppercase; letter-spacing: .4px;
}

select, input[type=number], input[type=text] {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font-size: 12px; font-family: var(--mono);
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 100%; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: none; padding: 2px; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; }

.chk { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-dim); margin: 6px 0; cursor: pointer; }

/* ------------------------------- Layout --------------------------------- */

.app {
  display: grid;
  grid-template-columns: 250px 1fr 300px;
  grid-template-rows: 1fr 214px;
  height: calc(100vh - 46px);
  height: calc(100dvh - 46px);
}

.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; }
.panel h2 { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-faint); margin: 0 0 8px; font-weight: 700; }
.panel-right { border-right: none; border-left: 1px solid var(--line); padding: 0; display: flex; flex-direction: column; }

section + section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
section.first { margin-top: 0; padding-top: 0; border-top: none; }

.note { font-size: 10.5px; color: var(--text-dim); line-height: 1.55; }
.note b { color: var(--brass); }
.empty-state { color: var(--text-faint); font-size: 11px; text-align: center; padding: 16px 6px; border: 1px dashed var(--line); border-radius: 8px; }

/* ------------------------------- Layers --------------------------------- */

.layer-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; margin-bottom: 3px; font-size: 12px;
}
.layer-item.selected { background: var(--accent-soft); border-color: var(--accent-dim); }
.layer-item:hover { background: var(--panel-2); }
.layer-item .eye { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-dim); display: flex; align-items: center; }
.layer-item .eye.off { color: var(--text-faint); }
.layer-item .eye:hover { color: var(--teal); }
.layer-item .swatch {
  width: 20px; height: 20px; border-radius: 4px; flex-shrink: 0;
  border: 1px solid var(--line); background-color: #1a1a1e; background-position: center; background-size: cover;
}
.layer-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item .del { color: var(--text-faint); font-size: 13px; padding: 0 3px; }
.layer-item .del:hover { color: var(--coral); }

/* ------------------------------- Stage ---------------------------------- */

/* Stage adalah bingkai viewport. Tidak ada scroll: navigasi sepenuhnya
   ditangani Camera Engine (pan & zoom). */
.stage {
  position: relative; overflow: hidden; padding: 0;
  background-color: var(--surround);
  background-image: radial-gradient(circle, #232328 1px, transparent 1px);
  background-size: 22px 22px;
  min-width: 0; min-height: 0;
}

/* Kanvas mengisi seluruh stage dan berperan sebagai viewport kamera. */
#editCanvas {
  display: block;
  width: 100%; height: 100%;
  cursor: default;
  touch-action: none;              /* wajib agar Pointer Events tidak direbut browser */
  -ms-touch-action: none;
  overscroll-behavior: contain;
}
#editCanvas.dragging  { cursor: grabbing; }
#editCanvas.panning   { cursor: grabbing; }
#editCanvas.pannable  { cursor: grab; }

.hint {
  position: absolute; top: 12px; left: 12px;
  font-size: 10.5px; color: var(--text-dim);
  background: rgba(20, 20, 24, .9); padding: 6px 10px;
  border-radius: 7px; border: 1px solid var(--line);
  max-width: 250px; line-height: 1.5; pointer-events: none;
}

/* ------------------------------ Bottom bar ------------------------------- */

.bottom {
  grid-column: 1 / 4; background: var(--panel);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; overflow-x: auto;
}

.preview-col { display: flex; flex-direction: column; height: 100%; flex-shrink: 0; }
.preview-frame {
  height: 100%; aspect-ratio: 1.3; min-width: 150px;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.preview-label { font-size: 10px; color: var(--text-faint); text-align: center; margin-top: 5px; text-transform: uppercase; letter-spacing: .5px; }

.divider-v { width: 1px; align-self: stretch; background: var(--line); flex-shrink: 0; }
.export-row { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; min-width: 170px; }

/* ------------------------------ Tab kanan -------------------------------- */

.tabbar { display: flex; border-bottom: 1px solid var(--line); background: var(--panel-2); flex-shrink: 0; }
.tabbar button {
  flex: 1; border: none; border-radius: 0; background: transparent;
  padding: 9px 2px; color: var(--text-faint);
  border-bottom: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar button svg { width: 16px; height: 16px; }
.tabbar button .tlabel { font-size: 8.5px; letter-spacing: .2px; }
.tabbar button.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--panel-3); }
.tabbar button:hover { color: var(--text); }

.tabpanel { display: none; padding: 14px; overflow-y: auto; flex: 1; }
.tabpanel.active { display: block; }

/* ------------------------------ Recolor ---------------------------------- */

.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { flex: 1; border: none; border-radius: 0; background: var(--panel-2); font-size: 11px; padding: 7px 2px; }
.seg button.active { background: var(--accent); color: #fff; }

.swatch-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.swatch-row .from { width: 26px; height: 26px; border-radius: 5px; border: 1px solid var(--line); flex-shrink: 0; }
.swatch-row .arrow { color: var(--text-faint); font-size: 12px; }

.preset-pal { display: flex; gap: 3px; padding: 6px 7px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; margin-bottom: 5px; align-items: center; }
.preset-pal:hover { border-color: var(--accent); }
.preset-pal .sw { width: 15px; height: 15px; border-radius: 3px; }
.preset-pal .lbl { font-size: 10.5px; color: var(--text-dim); margin-left: 6px; }

/* ---------------------------- Asset library ------------------------------ */

.asset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 7px; max-height: 190px; overflow-y: auto; }
.asset-card {
  border: 1px solid var(--line); border-radius: 7px; padding: 4px;
  cursor: pointer; background: var(--panel-2);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.asset-card:hover { border-color: var(--accent); }
.asset-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.asset-card img {
  width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: 4px;
  background-image:
    linear-gradient(45deg, #3a3a42 25%, transparent 25%),
    linear-gradient(-45deg, #3a3a42 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a3a42 75%),
    linear-gradient(-45deg, transparent 75%, #3a3a42 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}
.asset-missing { width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; color: var(--text-faint); }
.asset-card .acap { font-size: 9px; color: var(--text-dim); width: 100%; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-detail { margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); }

/* ------------------------------- History --------------------------------- */

.history-list { max-height: 130px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.history-item { display: flex; justify-content: space-between; gap: 6px; padding: 5px 7px; border-radius: 5px; font-size: 10.5px; color: var(--text-dim); cursor: pointer; }
.history-item:hover { background: var(--panel-2); }
.history-item.current { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.history-item .htime { color: var(--text-faint); flex-shrink: 0; font-family: var(--mono); }

/* --------------------------- Recent & backup ----------------------------- */

.recent-item, .backup-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px; border-radius: 7px; margin-bottom: 4px;
  background: var(--panel-2); border: 1px solid transparent; cursor: pointer;
}
.recent-item:hover, .backup-item:hover { border-color: var(--accent); }
.recent-item.current { border-color: var(--accent); background: var(--accent-soft); }
.rthumb, .bthumb {
  width: 40px; height: 40px; border-radius: 5px; flex-shrink: 0;
  background: #16161a center/cover no-repeat; border: 1px solid var(--line);
}
.rmeta { flex: 1; min-width: 0; }
.rname { font-size: 11.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rsub { font-size: 9.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rdel { background: transparent; border: none; color: var(--text-faint); padding: 2px 5px; font-size: 12px; }
.rdel:hover { color: var(--coral); background: transparent; }
.brestore { padding: 4px 8px; font-size: 10px; flex-shrink: 0; }

/* ---------------------------- Export queue ------------------------------- */

.queue-list { max-height: 58px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.queue-item { display: flex; justify-content: space-between; gap: 8px; font-size: 10.5px; color: var(--text-dim); padding: 2px 4px; }
.queue-item .qstatus { font-family: var(--mono); color: var(--brass); }
.queue-item .qstatus.done { color: var(--teal); }

/* ---------------------------- Quality score ------------------------------ */

.qscore-box { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.qring {
  width: 52px; height: 52px; border-radius: 50%;
  border: 4px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; font-family: var(--mono); flex-shrink: 0;
}
.qlabel-main { font-size: 12px; font-weight: 600; }
.qsub { font-size: 10.5px; color: var(--text-dim); margin-top: 2px; }

/* ------------------------------ Versi shuffle ---------------------------- */

.version-thumb {
  width: 52px; height: 52px; border-radius: 6px;
  border: 2px solid var(--line); cursor: pointer;
  background-size: cover; background-position: center; flex-shrink: 0;
}
.version-thumb:hover { border-color: var(--teal); }

/* -------------------------------- Dialog --------------------------------- */

.overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(10, 10, 12, .78);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.dialog {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px; max-width: 420px; width: 100%;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
.dialog h3 { margin: 0 0 8px; font-size: 16px; }
.dialog .dthumb {
  width: 100%; height: 150px; border-radius: 9px; margin: 12px 0;
  background: #16161a center/contain no-repeat; border: 1px solid var(--line);
}

/* --------------------------------- Toast --------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--panel-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 16px; font-size: 12.5px; z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 82vw; text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.warn { border-color: var(--coral); color: #ffd9d9; }

/* ------------------------------ Scrollbar -------------------------------- */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a42; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a55; }

/* ------------------------------ Responsif -------------------------------- */

@media (max-width: 1200px) {
  .app { grid-template-columns: 216px 1fr 268px; }
}

/* Tablet: panel kanan pindah ke bawah, kanvas tetap dominan */
@media (max-width: 940px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(240px, 1fr) auto auto;
  }
  .panel { border-right: none; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .panel-left { order: 3; }
  .stage { order: 1; min-height: 46vh; }
  .panel-right { order: 2; border-left: none; border-bottom: 1px solid var(--line); max-height: 46vh; }
  .bottom { grid-column: 1; order: 4; flex-wrap: wrap; height: auto; }
  .preview-frame { min-width: 120px; height: 96px; }
  .preview-col { height: auto; }
  header { gap: 8px; }
  .modebar button { padding: 6px 8px; font-size: 11px; }
}

@media (max-width: 600px) {
  .docdim, .docname { display: none; }
  .asset-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Layar sentuh: perbesar target sentuh */
@media (pointer: coarse) {
  button { padding: 8px 11px; }
  .tabbar button { padding: 11px 2px; }
  .layer-item { padding: 9px 6px; }
  input[type=checkbox] { width: 17px; height: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print { body { display: none; } }
