:root {
  --bg: #0b0b0c;
  --surface: #161618;
  --surface-2: #212124;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f1ec;
  --muted: #9a968f;
  --accent: #e5b96b;
  --accent-ink: #1a1408;
  --danger: #e6594c;
  --ok: #7cc48a;
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
[hidden] { display: none !important; }

.wordmark { font-family: var(--serif); letter-spacing: 0.32em; font-size: 22px; display: flex; gap: 10px; }
.wordmark span { font-weight: 300; }
.wordmark em { font-style: normal; font-weight: 600; color: var(--accent); }
.wordmark.small { font-size: 15px; margin-bottom: 18px; }

.screen { min-height: 100vh; }
#auth { display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; }
.auth-card .wordmark { justify-content: center; margin-bottom: 4px; }
.auth-card > .muted { text-align: center; margin-bottom: 24px; }

label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
input:not([type="checkbox"]), textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; outline: none; letter-spacing: 0;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }

.btn {
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:hover { border-color: rgba(255,255,255,0.2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.block { width: 100%; display: block; margin-bottom: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.link:hover { text-decoration: underline; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 8px; }

.error { background: rgba(230, 89, 76, 0.12); color: #ff9a90; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.notice { background: var(--surface-2); border-radius: 10px; padding: 14px; margin-top: 16px; }

/* App layout */
#app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 16px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar input { margin: 0 0 10px; }
.project-list { flex: 1; overflow-y: auto; margin: 0 -8px; }
.project-item { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer; }
.project-item:hover { background: var(--surface-2); }
.project-item.active { background: var(--surface-2); outline: 1px solid var(--border); }
.project-item img, .project-item .ph { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; }
.project-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-item .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-item .badges { margin-left: auto; display: flex; gap: 4px; }
.badge { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; padding: 3px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.accent { color: var(--accent); border-color: rgba(229,185,107,0.4); }
.badge.off { color: var(--danger); }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }

#main { padding: 28px 36px; max-width: 1200px; }
.empty { display: grid; place-items: center; height: 70vh; text-align: center; }
.project-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 20px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); margin: 0; cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }

.codes { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.code-row { display: flex; align-items: center; gap: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.code-row code { font-size: 18px; letter-spacing: 0.14em; font-weight: 600; color: var(--accent); }
.code-row.inactive code { color: var(--muted); text-decoration: line-through; }
.code-row .uses { color: var(--muted); font-size: 12px; }
.code-row .actions { margin-left: auto; display: flex; gap: 6px; }
.members { margin-top: 12px; color: var(--muted); }
.members summary { cursor: pointer; }
.members ul { margin: 8px 0 0; padding-left: 18px; }

.dropzone { border: 1px dashed rgba(255,255,255,0.2); border-radius: var(--radius); padding: 28px; text-align: center; margin-top: 10px; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: rgba(229,185,107,0.06); }
.upload-queue { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.upload-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 12px; }
.upload-row .bar { grid-column: 1 / -1; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.upload-row .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.upload-row.done .bar i { background: var(--ok); }
.upload-row.error { color: var(--danger); }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 10px; }
.media-card { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.media-card .thumb { aspect-ratio: 1; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.media-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-card .info { padding: 8px 10px; font-size: 11px; }
.media-card .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.media-card .sub { color: var(--muted); }
.media-card .tools { display: flex; gap: 6px; padding: 0 8px 8px; flex-wrap: wrap; }
.media-card .tools button { font-size: 11px; padding: 4px 8px; }
.media-card .kind { position: absolute; top: 6px; left: 6px; }
.media-card .cover { position: absolute; top: 6px; right: 6px; }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: min(480px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog h3 { margin-bottom: 16px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); z-index: 50; }
.toast.error { border-color: var(--danger); }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  #main { padding: 20px; }
}
