/* ===== Neobrutalism, versi ramah mata ===== */
:root {
  --bg: #f4efe4;
  --surface: #fffcf5;
  --surface-2: #efe8da;
  --text: #1c1b19;
  --muted: #6b665c;
  --border: #1c1b19;
  --shadow: #1c1b19;
  --primary: #ffd23f;
  --primary-ink: #1c1b19;
  --accent: #a5d8ff;
  --success: #b8e6b8;
  --danger: #ff9b8f;
  --check-a: #eee7d8;
  --check-b: #f8f3e9;
  --bw: 2.5px;
  --sh: 4px;
  --radius: 10px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16171b;
  --surface: #1f2126;
  --surface-2: #2a2d33;
  --text: #e9e6df;
  --muted: #9d9a92;
  --border: #c8c4b9;
  --shadow: #55534c;
  --primary: #f0c745;
  --primary-ink: #16171b;
  --accent: #6fa8d6;
  --success: #6dbb7a;
  --danger: #e8786b;
  --check-a: #24262b;
  --check-b: #2c2f35;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Space Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
code, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; letter-spacing: -.01em; }
[hidden] { display: none !important; }

.when-dark { display: none; }
:root[data-theme="dark"] .when-dark { display: inline; }
:root[data-theme="dark"] .when-light { display: none; }

/* ===== Card & Button ===== */
.card {
  background: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--sh) var(--sh) 0 var(--shadow);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; color: var(--text); text-decoration: none;
  background: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  box-shadow: 3px 3px 0 var(--shadow);
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--shadow); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--shadow); }
.btn:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-danger { background: var(--danger); color: #1c1b19; }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); box-shadow: none; transform: none; }
.btn-ghost:active { transform: none; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 14px 22px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; }

.field { display: block; margin: 14px 0; }
.field > span { display: block; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search] {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: var(--bw) solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
input::placeholder { color: var(--muted); }

.alert { background: var(--danger); color: #1c1b19; border: var(--bw) solid var(--border); border-radius: 8px; padding: 8px 12px; font-weight: 600; margin: 10px 0; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border: 2px solid var(--border); border-radius: 99px; background: var(--surface-2); margin-left: 4px; }
.pill.on { background: var(--success); color: #1c1b19; }

/* ===== Login ===== */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; padding: 30px 26px; }
.login-card h1 { font-size: 28px; }
.login-card .theme-toggle { margin-top: 12px; width: 100%; }
.logo-badge {
  width: 54px; height: 54px; display: grid; place-items: center;
  background: var(--primary); color: #1c1b19;
  border: var(--bw) solid var(--border); border-radius: 10px;
  box-shadow: 3px 3px 0 var(--shadow); margin-bottom: 16px;
}
.logo-badge svg { width: 28px; height: 28px; }
.logo-badge.sm { width: 36px; height: 36px; margin: 0; box-shadow: 2px 2px 0 var(--shadow); }
.logo-badge.sm svg { width: 20px; height: 20px; }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--surface);
  border-right: var(--bw) solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 2px 6px 18px; }
.nav { display: flex; flex-direction: column; gap: 8px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 600;
  border: var(--bw) solid transparent;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary); color: var(--primary-ink); border-color: var(--border); box-shadow: 3px 3px 0 var(--shadow); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.stat-mini { font-size: 13px; color: var(--muted); padding: 8px 6px; border-top: 2px dashed var(--border); margin-bottom: 4px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  background: var(--bg);
  border-bottom: var(--bw) solid var(--border);
}
.page-title { font-size: 22px; margin: 0; margin-right: auto; }
.menu-btn { display: none; }
.search { position: relative; width: 260px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 36px; }
.content { padding: 24px; }

/* ===== Grid kotak gambar ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 20px; }
.tile {
  position: relative;
  background: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--sh) var(--sh) 0 var(--shadow);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .1s, box-shadow .1s;
}
.tile:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--shadow); }
.tile.selected { outline: 3px solid var(--accent); outline-offset: 2px; }
.thumb { aspect-ratio: 1 / 1; border-bottom: var(--bw) solid var(--border); position: relative; cursor: zoom-in; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.checker {
  background-color: var(--check-b);
  background-image: linear-gradient(45deg, var(--check-a) 25%, transparent 25%, transparent 75%, var(--check-a) 75%),
                    linear-gradient(45deg, var(--check-a) 25%, transparent 25%, transparent 75%, var(--check-a) 75%);
  background-size: 18px 18px; background-position: 0 0, 9px 9px;
}
.tile .sel {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  width: 26px; height: 26px; border: var(--bw) solid var(--border); border-radius: 6px;
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .sel, .tile.selected .sel, .selecting .tile .sel { opacity: 1; }
.tile.selected .sel { background: var(--accent); }
.tile .sel svg { width: 14px; height: 14px; stroke-width: 3; visibility: hidden; }
.tile.selected .sel svg { visibility: visible; }
.tile .ext {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  background: var(--primary); color: #1c1b19; border: 2px solid var(--border); border-radius: 5px; padding: 0 6px;
}
.meta { padding: 10px 12px 4px; min-width: 0; }
.meta .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .info { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 6px; padding: 8px 10px 12px; margin-top: auto; }
.actions .btn { flex: 1; padding: 6px; box-shadow: 2px 2px 0 var(--shadow); }
.actions .btn:hover { box-shadow: 3px 3px 0 var(--shadow); }
.actions .btn svg { width: 16px; height: 16px; }
.actions .btn.copy { background: var(--accent); color: #1c1b19; }
.actions .btn.del:hover { background: var(--danger); color: #1c1b19; }

.empty { max-width: 460px; margin: 40px auto; padding: 36px 24px; text-align: center; }
.empty-icon { font-size: 44px; }

.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px; padding: 10px 14px;
  background: var(--accent); color: #1c1b19;
  border: var(--bw) solid var(--border); border-radius: var(--radius);
  box-shadow: 3px 3px 0 var(--shadow);
}
.bulkbar span { margin-right: auto; }

/* ===== Progress upload ===== */
.uploads:empty { display: none; }
.uploads { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.up-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; font-size: 13px; }
.up-item .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.up-item .bar { width: 140px; height: 12px; border: 2px solid var(--border); border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.up-item .bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .15s; }
.up-item.done .bar i { background: var(--success); }
.up-item.fail { flex-wrap: wrap; }
.up-item.fail .st { width: 100%; text-align: left; white-space: normal; color: var(--text); font-weight: 600; }
.up-item.fail .bar i { background: var(--danger); width: 100% !important; }
.up-item .st { width: 120px; text-align: right; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dropzone { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; background: rgba(0,0,0,.35); pointer-events: none; }
.dropzone.on { display: grid; }
.dropzone .card { padding: 30px 40px; font-size: 22px; font-weight: 700; border-style: dashed; }

/* ===== Purge ===== */
.purge-card { max-width: 620px; padding: 28px; }
.checklist { padding: 0; list-style: none; margin: 14px 0 20px; }
.checklist li { padding: 6px 0 6px 30px; position: relative; }
.checklist li::before { content: "✓"; position: absolute; left: 0; top: 6px; width: 20px; height: 20px; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--success); color: #1c1b19; border: 2px solid var(--border); border-radius: 5px; }
.purge-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface-2); border: var(--bw) solid var(--border); border-radius: 8px; padding: 12px 14px; }
.stat .label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b { font-size: 20px; }
.hint { font-size: 13px; margin-top: 18px; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Modal / Lightbox / Toast ===== */
.modal, .lightbox { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(10,10,12,.55); }
.modal-box { width: 100%; max-width: 420px; padding: 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.rename-row { display: flex; align-items: stretch; }
.rename-row input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.rename-row .suffix { display: grid; place-items: center; padding: 0 12px; border: var(--bw) solid var(--border); border-left: 0; border-radius: 0 8px 8px 0; background: var(--surface-2); font-weight: 700; }
.lightbox-inner { width: 100%; max-width: 960px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.lightbox-head, .lightbox-foot { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.lightbox-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-img { flex: 1; min-height: 0; display: grid; place-items: center; border-top: var(--bw) solid var(--border); border-bottom: var(--bw) solid var(--border); overflow: auto; }
.lightbox-img img { max-width: 100%; max-height: calc(100vh - 180px); display: block; }
.lightbox-foot code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--surface-2); border: 2px solid var(--border); border-radius: 6px; padding: 6px 10px; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 70; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 32px); }
.toast { padding: 10px 14px; font-weight: 600; font-size: 14px; animation: pop .18s ease-out; }
.toast.ok { background: var(--success); color: #1c1b19; }
.toast.err { background: var(--danger); color: #1c1b19; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ===== Mobile ===== */
.scrim { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-105%); transition: transform .2s; box-shadow: 6px 0 0 var(--shadow); }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .search { order: 5; width: 100%; }
  .content { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
  .up-item .bar { width: 70px; }
  .up-item .st { width: 80px; }
}
@media (max-width: 420px) {
  #addBtn span { display: none; }
  .grid { grid-template-columns: 1fr 1fr; }
  .purge-stats { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
