/* NCODE — mobile-first. Terang/gelap mengikuti pengaturan perangkat. */
:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eceff3;
  --line: #e0e5ea;
  --text: #121820;
  --muted: #5f6c7b;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-ink: #ffffff;
  --accent-soft: #d8f1ed;
  --accent-text: #0f766e;
  --danger: #c62833;
  --danger-soft: #fde9eb;
  --warn: #9a5b06;
  --warn-soft: #fcefd6;
  --ok: #167a3e;
  --ok-soft: #dcf4e4;
  --overlay: rgba(10, 15, 22, .5);
  --shadow: 0 -1px 0 rgba(18, 24, 32, .04), 0 8px 24px rgba(18, 24, 32, .12);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --bar: 56px;
  --nav: 62px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --dock-bottom: calc(var(--nav) + var(--safe-b) + 10px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1016;
    --surface: #131a22;
    --surface-2: #1a232d;
    --line: #232f3c;
    --text: #e8eef5;
    --muted: #93a1b3;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-ink: #03201b;
    --accent-soft: rgba(45, 212, 191, .13);
    --accent-text: #5eead4;
    --danger: #ff8a93;
    --danger-soft: rgba(255, 138, 147, .12);
    --warn: #fbbf4a;
    --warn-soft: rgba(251, 191, 74, .12);
    --ok: #5bdc8b;
    --ok-soft: rgba(91, 220, 139, .12);
    --overlay: rgba(0, 0, 0, .65);
    --shadow: 0 -1px 0 rgba(255, 255, 255, .04), 0 8px 24px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: light dark; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: break-word;
  overscroll-behavior-y: none;
}
a { color: var(--accent-text); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4rem; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: .3rem 0 .6rem; }
img, video { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Kerangka ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: calc(var(--bar) + var(--safe-t)); padding: var(--safe-t) 1rem 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { font-family: var(--mono); font-weight: 800; letter-spacing: .06em; color: var(--text); font-size: 1.1rem; }
.logo-mark { color: var(--accent-text); margin-right: .4rem; }
.topnav { display: none; gap: .25rem; }
.topnav a { color: var(--muted); padding: .5rem .85rem; border-radius: 10px; font-weight: 600; font-size: .95rem; }
.topnav a:hover { color: var(--text); background: var(--surface-2); }
.topnav a.on { color: var(--accent-ink); background: var(--accent); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: calc(var(--nav) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent-text); }
.tabbar a.on svg { stroke-width: 2.4; }

.wrap { max-width: 980px; margin: 0 auto; padding: 1.1rem 1rem calc(var(--nav) + var(--safe-b) + 2.5rem); }
.wrap.narrow { max-width: 600px; }
.page-head { margin-bottom: 1.1rem; }
.page-head p { color: var(--muted); margin-bottom: 0; }
.row, .row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.back { display: inline-block; color: var(--muted); font-size: .9rem; padding: .25rem 0; margin-bottom: .4rem; }
.hide-mobile { display: none !important; }

/* Bagian halaman: datar, hanya dikelilingi garis tipis */
.group { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 1.1rem; }
.group > h2 { margin-bottom: .6rem; }
.empty { text-align: center; padding: 2.5rem 1rem; }
.notice {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .75rem;
  padding: .8rem 1rem; border-radius: 14px; margin-bottom: 1rem;
  background: var(--surface-2); font-size: .95rem;
}
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.danger { background: var(--danger-soft); color: var(--danger); margin-bottom: 0; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice .btn { margin-left: auto; }

/* Langkah */
.step-title { display: flex; align-items: center; gap: .6rem; margin-bottom: .85rem; }
.step-title h2 { margin: 0; }
.num {
  flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); font-weight: 800; font-size: .85rem;
}

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; }
.field label { font-weight: 600; font-size: .92rem; }
input[type=text], input[type=url], input[type=password], input[type=datetime-local], select, textarea, input:not([type]) {
  width: 100%; min-height: 48px; padding: .7rem .85rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit; font-size: 16px; /* 16px agar tidak ter-zoom di WebView */
  appearance: none; -webkit-appearance: none;
}
select {
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a97a8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .8rem center;
}
textarea { resize: vertical; min-height: 7rem; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.input-row { display: flex; gap: .5rem; }
.input-row input { flex: 1; min-width: 0; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0; margin-top: .6rem; }
.form-grid .wide { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; flex-wrap: wrap; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .2rem; text-align: center;
  padding: 1.4rem 1rem; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 16px; background: var(--bg); color: var(--muted);
  font-size: .9rem;
}
.dropzone svg { width: 28px; height: 28px; color: var(--accent-text); margin-bottom: .2rem; }
.dropzone strong { color: var(--text); font-size: 1rem; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.previews { display: flex; gap: .75rem; flex-wrap: wrap; }
.previews:not(:empty) { margin-top: .85rem; }
.thumb { position: relative; margin: 0; width: calc(50% - .375rem); max-width: 150px; }
.thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); display: block; }
.thumb figcaption { font-size: .8rem; color: var(--muted); text-align: center; margin-top: .25rem; }
.thumb-x {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .7); color: #fff; cursor: pointer; font-size: 20px; line-height: 1;
}

.radio-cards { display: flex; flex-direction: column; gap: .6rem; }
.rc { cursor: pointer; display: block; }
.rc input, .chip input { position: absolute; opacity: 0; pointer-events: none; }
.rc-body { display: flex; flex-direction: column; gap: .1rem; height: 100%; padding: .8rem .95rem; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.rc-body small { color: var(--muted); }
.rc input:checked + .rc-body { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.rc input:focus-visible + .rc-body, .chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip { cursor: pointer; }
.chip span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 1.1rem; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); font-weight: 600; }
.chip input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.hint { color: var(--muted); font-size: .9rem; margin: .8rem 0 0; }

/* Hasil penyempurnaan AI */
.enhanced { margin-top: 1rem; padding: 1rem; border-radius: 16px; background: var(--accent-soft); }
.enhanced-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .7rem; }
.enhanced .field:last-child { margin-bottom: 0; }
.enhanced input, .enhanced textarea { background: var(--surface); }
.state { font-size: .8rem; font-weight: 700; padding: .15rem .6rem; border-radius: 999px; }
.state.ok { background: var(--ok-soft); color: var(--ok); }
.state.stale { background: var(--warn-soft); color: var(--warn); }

/* ---------- Tombol ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 46px; padding: 0 1.1rem; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: transparent; }
.btn-sm { min-height: 40px; padding: 0 .85rem; font-size: .88rem; border-radius: 10px; }
.btn-lg { min-height: 52px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { display: flex; width: 100%; }
.ico { width: 18px; height: 18px; fill: currentColor; stroke: none; }

/* Panel aksi yang menempel di atas tab bawah */
.dock {
  position: sticky; bottom: var(--dock-bottom); z-index: 10;
  padding: .6rem; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.dock-hint { margin: .45rem .3rem 0; font-size: .82rem; color: var(--muted); text-align: center; }
.dock-hint:empty { display: none; }
.dock-save { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .6rem .6rem .6rem 1rem; }
.dock-save .muted { font-size: .9rem; min-width: 0; }

/* ---------- Loading ---------- */
.loading { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem; background: var(--overlay); }
.loading-box { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 1.6rem 1.8rem; background: var(--surface); border-radius: 20px; width: min(100%, 320px); text-align: center; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } .btn:active { transform: none; } }

/* ---------- Hasil ---------- */
.result { margin-top: 2rem; scroll-margin-top: calc(var(--bar) + var(--safe-t) + 8px); }
.result-head h2 { font-size: 1.3rem; }
.result-head span { color: var(--accent-text); }
.rblock { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 1rem; }
.rblock-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .6rem; }
.rblock-head h3 { margin: 0; }
.rblock .note { color: var(--muted); font-size: .85rem; margin: .5rem 0 0; }
pre, .prewrap { white-space: pre-wrap; word-break: break-word; margin: 0; }
pre {
  font-family: var(--mono); font-size: .85rem; line-height: 1.6;
  background: var(--bg); border-radius: 12px; padding: .8rem .9rem;
  max-height: 22rem; overflow: auto;
}
.plain { font: inherit; font-size: .95rem; background: none; border: 0; padding: 0; max-height: none; }

/* Meta TikTok */
.meta-grid { display: grid; grid-template-columns: 1fr; gap: .8rem; margin-top: .8rem; }
.meta-card { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: .85rem; display: flex; flex-direction: column; gap: .35rem; }
.meta-card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: var(--accent-soft); }
.meta-pick { display: flex; align-items: center; gap: .6rem; cursor: pointer; min-height: 44px; }
.meta-pick input { accent-color: var(--accent); width: 20px; height: 20px; flex: none; }
.copyrow { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; padding: .55rem 0; border-top: 1px solid var(--line); }
.copyrow:first-of-type { border-top: 0; }
.copytext { min-width: 0; }
.copytext b { font-size: .8rem; font-weight: 700; color: var(--muted); }
.copytext p { margin: .1rem 0 0; overflow-wrap: anywhere; font-size: .95rem; }
.copytext .tags { color: var(--accent-text); }
.copyrow .btn { flex: none; }

/* ---------- Daftar konten ---------- */
.tabs { display: flex; gap: .4rem; margin: 0 -1rem 1rem; padding: 0 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; display: inline-flex; align-items: center; min-height: 40px; padding: 0 .95rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.count { opacity: .75; margin-left: .35rem; }
.grid { display: grid; grid-template-columns: 1fr; gap: .8rem; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: .85rem; display: flex; flex-direction: column; gap: .75rem; }
.pcard-main { display: flex; gap: .85rem; align-items: center; color: inherit; min-width: 0; }
.cover { flex: none; width: 76px; height: 76px; border-radius: 14px; object-fit: cover; background: var(--surface-2); display: block; }
.cover-empty { display: grid; place-items: center; color: var(--muted); }
.cover-empty svg { width: 28px; height: 28px; }
.pcard-info { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.pcard-title { font-weight: 700; font-size: 1.02rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard-tags { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .6rem; }
.pcard-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.badge { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge.big { font-size: .85rem; padding: .25rem .8rem; }
.s-draft { color: var(--muted); background: var(--surface-2); }
.s-scheduled { color: var(--warn); background: var(--warn-soft); }
.s-posted { color: var(--ok); background: var(--ok-soft); }

/* ---------- Detail ---------- */
.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin-top: .8rem; }
.gallery figure { margin: 0; display: flex; flex-direction: column; gap: .4rem; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); display: block; }
.player { width: 100%; max-height: 460px; border-radius: 14px; background: #000; margin-top: .8rem; }
.progress { height: 8px; border-radius: 99px; background: var(--bg); margin-top: .8rem; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
details { border-top: 1px solid var(--line); padding: .35rem 0; }
details:first-of-type { margin-top: .5rem; }
summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.promptbox { display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; margin: .2rem 0 .6rem; }
.promptbox pre { width: 100%; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.danger-zone .btn { width: 100%; }

/* ---------- Toast & dialog ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + var(--bar) + 8px); transform: translate(-50%, -12px);
  max-width: calc(100% - 2rem); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: .92rem; text-align: center;
  padding: .6rem 1rem; border-radius: 12px; transition: opacity .2s, transform .2s; z-index: 70;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .toast.err { color: #2b0a0d; } }

.sheet-back { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center; background: var(--overlay); }
.sheet { width: 100%; max-width: 480px; background: var(--surface); border-radius: 24px 24px 0 0; padding: 1.25rem 1.1rem calc(1.1rem + var(--safe-b)); display: flex; flex-direction: column; gap: .6rem; }
.sheet p { margin: 0 0 .4rem; font-size: 1.02rem; }

/* ---------- Layar lebar ---------- */
@media (min-width: 761px) {
  body { font-size: 15.5px; }
  h1 { font-size: 1.8rem; }
  .topbar { padding-left: 1.5rem; padding-right: 1.5rem; }
  .topnav { display: flex; }
  .tabbar { display: none; }
  .hide-mobile { display: inline-flex !important; }
  .wrap { padding: 1.75rem 1.5rem 4rem; }
  .group { padding: 1.3rem 1.4rem; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 0 1rem; }
  .radio-cards { flex-direction: row; }
  .radio-cards .rc { flex: 1; }
  .meta-grid { grid-template-columns: repeat(3, 1fr); }
  .tabs { margin: 0 0 1rem; padding: 0; flex-wrap: wrap; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .thumb { width: 140px; }
  .dock { --dock-bottom: 1rem; }
  .danger-zone .btn { width: auto; }
  .toast { top: calc(var(--bar) + 12px); }
  .sheet-back { align-items: center; }
  .sheet { border-radius: 20px; padding-bottom: 1.1rem; }
}
