*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:      #111827;
  --bg2:     #1F2937;
  --bg3:     #374151;
  --card:    #1F2937;
  --card-h:  #263044;
  --border:  #374151;
  --text:    #F9FAFB;
  --muted:   #9CA3AF;
  --accent:  #3B82F6;
  --accent2: #2563EB;
  --green:   #10B981;
  --red:     #EF4444;
  --yellow:  #F59E0B;
  --sb-w:    260px;
  --font: -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
}
html,body { height: 100%; overflow: hidden; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: inherit; outline: none; }
.hidden { display: none !important; }

/* ═══ AUTH ═══ */
.auth-overlay {
  position: fixed; inset: 0; display: flex;
  align-items: center; justify-content: center;
  background: var(--bg); z-index: 999;
}
.auth-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px 48px;
  width: 340px; text-align: center;
  box-shadow: 0 25px 50px rgba(0,0,0,.5);
}
.auth-rain { font-size: 48px; margin-bottom: 12px; }
.auth-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: 13px; margin-bottom: 28px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card input {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px 14px;
  font-size: 14px; transition: border-color .15s;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-err { color: var(--red); font-size: 13px; }

/* ═══ LAYOUT ═══ */
.app { display: grid; grid-template-columns: var(--sb-w) 1fr; height: 100vh; }

/* ═══ SIDEBAR ═══ */
.sidebar {
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}
.sb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sb-logo { font-weight: 700; font-size: 15px; color: var(--text); }
.sb-user {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; cursor: default;
}
.sb-search-wrap { padding: 10px 12px 8px; flex-shrink: 0; }
#sb-search {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 7px 12px; font-size: 13px;
  transition: border-color .15s;
}
#sb-search:focus { border-color: var(--accent); }

/* ═══ NAV ═══ */
.sb-nav { flex: 1; overflow-y: auto; padding: 4px 0; }
.sb-nav::-webkit-scrollbar { width: 4px; }
.sb-nav::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

.nav-special { list-style: none; padding: 4px 8px 0; }
.ni {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; border-radius: 8px; cursor: pointer;
  transition: background .1s; user-select: none;
}
.ni:hover { background: var(--bg3); }
.ni.active { background: rgba(59,130,246,.15); color: var(--accent); }
.ni-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }
.ni-name { flex: 1; font-size: 13px; }
.ni-cnt {
  font-size: 11px; color: var(--muted); background: var(--bg3);
  border-radius: 10px; padding: 1px 6px; min-width: 18px; text-align: center;
}

.nav-sep {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px 4px; color: var(--muted); font-size: 11px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
}

/* ═══ COLLECTION TREE ═══ */
.col-tree { list-style: none; padding: 0 8px 8px; }
.ci {
  display: flex; align-items: center; gap: 4px; border-radius: 8px;
  cursor: pointer; user-select: none; position: relative;
  transition: background .1s; min-height: 30px;
}
.ci:hover { background: var(--bg3); }
.ci:hover .ci-acts { opacity: 1; }
.ci.active { background: rgba(59,130,246,.15); color: var(--accent); }
.ci-toggle {
  background: none; border: none; color: var(--muted); font-size: 9px;
  width: 18px; flex-shrink: 0; transition: transform .15s;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.ci-toggle.open { transform: rotate(90deg); }
.ci-toggle-ph { width: 18px; flex-shrink: 0; }
.ci-ico { font-size: 13px; flex-shrink: 0; }
.ci-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 6px 2px; }
.ci-cnt { font-size: 11px; color: var(--muted); padding-right: 4px; flex-shrink: 0; }
.ci-acts {
  display: flex; gap: 1px; opacity: 0; transition: opacity .1s;
  position: absolute; right: 4px; background: var(--card-h);
  border-radius: 6px; padding: 2px; flex-shrink: 0;
}
.ci-children { list-style: none; }

/* ═══ SIDEBAR FOOTER ═══ */
.sb-footer {
  padding: 10px 12px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.btn-logout {
  background: none; color: var(--muted); font-size: 12px; border-radius: 6px;
  padding: 6px 10px; transition: color .15s, background .15s; width: 100%; text-align: left;
}
.btn-logout:hover { color: var(--text); background: var(--bg3); }

/* ═══ MAIN ═══ */
.main { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ═══ TOOLBAR ═══ */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg); gap: 12px;
}
.tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-left h2 { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-cnt { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tb-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ═══ SEARCH BAR ═══ */
.search-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px; background: rgba(59,130,246,.08);
  border-bottom: 1px solid var(--border); font-size: 13px; flex-shrink: 0;
}

/* ═══ ITEMS AREA ═══ */
.items-area { flex: 1; overflow-y: auto; padding: 16px 20px; }
.items-area::-webkit-scrollbar { width: 6px; }
.items-area::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

/* GRID */
.items-area.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px; align-content: start;
}
/* LIST */
.items-area.list { display: flex; flex-direction: column; gap: 4px; }

/* ═══ CARD (grid) ═══ */
.card {
  background: var(--card); border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); cursor: pointer;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  position: relative;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.35); border-color: var(--accent); }
.card:hover .card-acts { opacity: 1; }
.card-thumb {
  width: 100%; aspect-ratio: 16/9; background: var(--bg3);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-thumb-ph {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--muted); font-size: 11px; text-align: center; padding: 8px;
}
.card-thumb-ph img { width: 24px; height: 24px; object-fit: contain; }
.card-body { padding: 10px 12px 8px; }
.card-title {
  font-size: 13px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; margin-bottom: 6px;
}
.card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-dom { font-size: 11px; color: var(--muted); }
.tag { font-size: 10px; background: rgba(59,130,246,.15); color: var(--accent); border-radius: 4px; padding: 1px 5px; }
.card-acts {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 3px;
  opacity: 0; transition: opacity .12s;
}

/* ═══ ROW (list) ═══ */
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  transition: background .1s; border: 1px solid transparent;
}
.row:hover { background: var(--card); border-color: var(--border); }
.row:hover .row-acts { opacity: 1; }
.row-fav { width: 20px; height: 20px; border-radius: 4px; object-fit: contain; flex-shrink: 0; }
.row-main { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.row-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-dom { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.row-tags { display: flex; gap: 4px; flex-shrink: 0; }
.row-acts { display: flex; gap: 3px; opacity: 0; transition: opacity .1s; flex-shrink: 0; }
.type-badge {
  position: absolute; top: 6px; left: 6px; font-size: 10px; font-weight: 700;
  background: rgba(16,185,129,.8); color: #fff; border-radius: 4px; padding: 1px 4px;
}

/* ═══ EMPTY / LOADING ═══ */
.empty, .loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 12px; color: var(--muted); text-align: center; padding: 40px;
}
.empty-ico { font-size: 56px; margin-bottom: 8px; }
.empty h3 { font-size: 18px; color: var(--text); }
.empty p { font-size: 14px; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ BUTTONS ═══ */
.btn-primary {
  background: var(--accent); color: #fff; border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 600;
  transition: background .15s; white-space: nowrap;
}
.btn-primary:hover { background: var(--accent2); }
.btn-secondary {
  background: var(--bg3); color: var(--text); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 500;
  transition: background .15s; white-space: nowrap;
}
.btn-secondary:hover { background: #4B5563; }
.bxi {
  background: none; color: var(--muted); border-radius: 6px;
  padding: 4px 7px; font-size: 13px; transition: color .12s, background .12s;
  display: flex; align-items: center; justify-content: center;
}
.bxi:hover { color: var(--text); background: var(--bg3); }
.bxi.active { color: var(--accent); }
.bxi-sm { font-size: 11px; padding: 2px 5px; }

/* ═══ VIEW BTNS ═══ */
.view-btns { display: flex; gap: 2px; background: var(--bg2); border-radius: 7px; padding: 2px; }
.sort-sel {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.upload-lbl { padding: 5px 9px; }

/* ═══ MODALS ═══ */
.moverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  width: 480px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-sm { width: 360px; }
.mhdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.mhdr h3 { font-size: 16px; font-weight: 700; }
.mbody { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.mbody::-webkit-scrollbar { width: 4px; }
.mbody::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }
.mftr {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.fg { display: flex; flex-direction: column; gap: 4px; }
.fg label { font-size: 12px; color: var(--muted); font-weight: 500; }
.fg input, .fg textarea, .fg select {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 12px; font-size: 13px;
  transition: border-color .15s; resize: vertical;
}
.fg input:focus, .fg textarea:focus, .fg select:focus { border-color: var(--accent); }
.url-row { flex-direction: row !important; gap: 8px; }
.url-row input { flex: 1; }

/* FETCH PREVIEW */
.fetch-prev {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg3); border-radius: 8px; padding: 8px 12px;
}
.fetch-prev img { width: 60px; height: 40px; object-fit: cover; border-radius: 5px; }
.prev-dom { font-size: 12px; color: var(--muted); }

/* MOVE MODAL SELECT */
.mv-sel {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 4px; font-size: 13px; width: 100%;
}
.mv-sel option { padding: 6px 10px; }
.mv-sel option:checked { background: var(--accent); color: #fff; }

/* ═══ CONTEXT MENU ═══ */
.ctx {
  position: fixed; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 200; min-width: 170px; padding: 4px;
  animation: fadeUp .1s ease;
}
@keyframes fadeUp { from { opacity:0; transform:translateY(4px); } }
.ctx button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 12px; border-radius: 7px;
  font-size: 13px; color: var(--text); background: none;
  transition: background .1s;
}
.ctx button:hover { background: var(--bg3); }
.ctx hr { border: none; border-top: 1px solid var(--border); margin: 3px 0; }
.ctx-del { color: var(--red) !important; }
.ctx-del:hover { background: rgba(239,68,68,.1) !important; }

/* ═══ DRAG OVERLAY ═══ */
.drag-ov {
  position: fixed; inset: 0; background: rgba(59,130,246,.15);
  border: 3px dashed var(--accent); z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.drag-inner { text-align: center; color: var(--accent); }
.drag-ico { font-size: 56px; margin-bottom: 12px; }

/* ═══ TOAST ═══ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 18px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 400; display: flex; align-items: center; gap: 10px;
  animation: fadeUp .2s ease; max-width: 400px;
}
.toast-undo {
  background: none; border: none; color: var(--accent);
  font-size: 12px; cursor: pointer; padding: 0;
}

/* ═══ SPECS MODAL ═══ */
.modal-specs {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  background: rgba(0,0,0,.7); padding: 24px 12px; overflow-y: auto;
}
.specs-panel {
  background: var(--bg2); border-radius: 12px;
  width: 100%; max-width: 680px;
  border: 1px solid var(--border); box-shadow: 0 24px 48px rgba(0,0,0,.5);
}
.specs-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg2); z-index: 1;
  border-radius: 12px 12px 0 0;
}
.specs-header h2 { font-size: 16px; font-weight: 600; flex: 1; }
.specs-header button {
  width: 32px; height: 32px; border-radius: 6px;
  background: var(--bg3); color: var(--text); font-size: 16px;
}
.specs-header button:hover { background: var(--border); }
.specs-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 16px; }
.specs-sec { display: flex; flex-direction: column; gap: 8px; }
.specs-sec h3 {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.specs-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.specs-grid.full { grid-template-columns: 1fr; }
.specs-field { display: flex; flex-direction: column; gap: 4px; }
.specs-field label { font-size: 11px; color: var(--muted); font-weight: 500; }
.specs-field input,
.specs-field select,
.specs-field textarea {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 8px 10px; font-size: 13px; width: 100%;
  transition: border-color .15s;
}
.specs-field input:focus,
.specs-field select:focus,
.specs-field textarea:focus { border-color: var(--accent); }
.specs-field textarea { min-height: 72px; resize: vertical; }
.specs-field select option { background: var(--bg2); }
.specs-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.specs-actions button {
  padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 600;
  min-height: 44px; transition: opacity .15s;
}
.specs-actions button:hover { opacity: .85; }
.btn-save-specs { background: var(--accent); color: #fff; }
.btn-share-specs { background: #25D366; color: #fff; }
.btn-dl-specs { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .25s; width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .btn-ham { display: flex !important; }
  .items-area.grid { grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); }
}
@media (max-width: 520px) {
  .specs-grid { grid-template-columns: 1fr; }
  .modal-specs { padding: 0; align-items: flex-end; }
  .specs-panel { border-radius: 16px 16px 0 0; max-width: 100%; }
}
@media (max-width: 480px) {
  .items-area.grid { grid-template-columns: 1fr 1fr; }
  .tb-right .sort-sel { display: none; }
}
