:root {
  --bg: #0f172a; /* slate-900 */
  --card: #111827; /* gray-900 */
  --muted: #9ca3af; /* gray-400 */
  --text: #e5e7eb; /* gray-200 */
  --accent: #06b6d4; /* cyan-500 */
  --accent-2: #22d3ee; /* cyan-400 */
  --danger: #ef4444; /* red-500 */
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: radial-gradient(1200px 800px at 10% 0%, #0b1220, #0f172a);
  color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}
a { color: var(--accent-2); }
.header {
  display:flex; align-items:center; justify-content:space-between;
  padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,.08);
  position: sticky; top: 0; backdrop-filter: blur(8px);
}
.brand { display:flex; align-items:center; gap:10px; }
.brand img { width: 28px; height: 28px;}
.brand h1 { font-size: 18px; margin:0; font-weight:600; letter-spacing: .4px;}
.top-actions { display:flex; align-items:center; gap:8px; }
.btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #001015; border: none; padding: 8px 12px; border-radius: 12px;
  cursor: pointer; font-weight: 600;
}
.btn.secondary { background: #1f2937; color: var(--text); }
.btn.danger { background: var(--danger); color: white; }
.container { padding: 16px; max-width: 1200px; margin: 0 auto; }
.toolbar { display:flex; flex-wrap: wrap; gap:10px; align-items:center; margin-bottom: 12px;}
.path { color: var(--muted); font-size: 14px;}
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 16px; padding: 12px; display:flex; flex-direction:column; gap:10px;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.18); background: rgba(255,255,255,.06); }
.card .thumb { display:flex; align-items:center; justify-content:center; height: 96px; border-radius: 10px; background: #0b1220; border: 1px dashed rgba(255,255,255,.08); }
.card .thumb img { width: 64px; height: 64px; opacity: .9; }
.card .name { font-size: 14px; font-weight:600; white-space: nowrap; overflow:hidden; text-overflow:ellipsis;}
.card .meta { font-size: 12px; color: var(--muted); display:flex; justify-content:space-between;}
.footer { text-align:center; padding:24px; color: var(--muted); font-size: 12px;}
.input, input[type="text"], input[type="password"], input[type="number"] {
  background: #0b1220; border: 1px solid rgba(255,255,255,.10); color: var(--text);
  padding: 10px 12px; border-radius: 12px; outline:none;
}
input::placeholder { color: #6b7280; }
.row { display:flex; gap:10px; flex-wrap:wrap; }
.badge { background:#0b1220; border:1px solid rgba(255,255,255,.10); padding:4px 8px; border-radius:999px; font-size:12px; color: var(--muted);}
.table { width:100%; border-collapse: collapse; font-size:14px; }
.table th, .table td { padding: 10px 8px; border-bottom:1px solid rgba(255,255,255,.08); text-align:left; }
.table th { color: var(--muted); font-weight:600; }
.modal-backdrop { z-index: 10000; position: fixed; inset: 0; background: rgba(0,0,0,.65); display:none; align-items:center; justify-content:center; }
.modal { display:flex; flex-direction:column; max-height:92vh; background: #0b1220; border: 1px solid rgba(255,255,255,.10); border-radius: 16px; padding: 16px; width: min(720px, 92vw); }
.modal.open + .modal-backdrop, .modal-backdrop.open { display:flex; }
video, audio { width:100%; border-radius: 12px; background:#000; }

/* Desktop viewer: prevent top/bottom cropping */
#viewer { flex: 1 1 auto; overflow: auto; max-height: calc(92vh - 72px); }
#viewer img, #viewer video, #viewer iframe {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}
@media (max-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));}
  .header { padding: 10px; }
  .container { padding: 12px; }
  .card .thumb { height: 80px; }
}

/* Upload overlay */
#uploadOverlay{position:fixed;inset:0;background:rgba(0,0,0,0.45);display:none;align-items:center;justify-content:center;z-index:9999}
#uploadOverlay .box{background:#fff;max-width:480px;width:90%;border-radius:14px;padding:18px;box-shadow:0 10px 30px rgba(0,0,0,0.2);}
#uploadOverlay .row{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px}
#uploadOverlay .bar{height:10px;background:#eee;border-radius:999px;overflow:hidden}
#uploadOverlay .bar>span{display:block;height:100%;width:0%;background:#4f46e5;transition:width .15s ease}
#uploadOverlay .meta{font-size:14px;color:#333;margin-top:6px}
#uploadOverlay .title{font-weight:600}


/* --- Responsive header tweaks to keep topbar buttons visible on mobile --- */
.header { position: sticky; top: 0; z-index: 20; }
.header .brand { flex: 0 0 auto; }

.header .top-actions::-webkit-scrollbar { display: none; }
@media (max-width: 560px){
  .header { align-items: flex-start; }
  .top-actions { flex-wrap: wrap; row-gap: 6px; overflow-x: visible; }
  .top-actions .btn { padding: 6px 10px; border-radius: 10px; font-size: 14px; }
}


/* --- Desktop vs Mobile layout for top-actions --- */
/* Desktop (default): keep actions snug to the right */
.header .top-actions { display:flex; align-items:center; gap:8px; flex:0 0 auto; }
/* Mobile: allow wrapping/scrolling so buttons don't get cut */
@media (max-width: 560px){
  .header { align-items: flex-start; }
  .header .top-actions { flex: 1 1 auto; min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: wrap; row-gap: 6px; }
  .header .top-actions::-webkit-scrollbar { display: none; }
  .header .top-actions .btn { padding: 6px 10px; border-radius: 10px; font-size: 14px; }
}


/* Floating paste/move bar */
.movebar { position: fixed; right: 12px; bottom: 12px; background:#0f172a; border:1px solid #1f2a44; padding:10px 12px; border-radius:12px; box-shadow:0 10px 30px rgba(0,0,0,.35); display:flex; align-items:center; gap:12px; z-index: 50; }
.movebar.hidden { display:none; }
@media (max-width: 560px){
  .movebar { left: 12px; right: 12px; bottom: 12px; justify-content: space-between; }
}


/* Selection handle + states */
.card { position: relative; }
.sel-handle { position:absolute; top:6px; left:6px; width:18px; height:18px; border:1px solid rgba(255,255,255,.35); background:#0b1220; border-radius:6px; opacity:.9; }
.card.selected .sel-handle { background: var(--accent); border-color: transparent; }
.card.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,0,0,.2) inset; }
.drag-ghost { position:fixed; top:0; left:0; pointer-events:none; padding:6px 10px; border-radius:10px; background:#0b1220; border:1px solid rgba(255,255,255,.35); z-index:200; }


/* Mobile: keep modal above header and fully visible with safe-area insets */
@media (max-width: 600px){
  .modal { display:flex; flex-direction:column; max-height:92vh; 
    margin: 8px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
  }
  #viewer{
    flex: 1 1 auto;
    overflow: auto;
    max-height: calc(100dvh - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  #viewer img, #viewer video, #viewer iframe{
    max-width: 100%;
    max-height: 100%;
    height: auto;
    object-fit: contain;
    display: block;
  }
}
