/* =========================================================
   RESET & CUSTOM PROPERTIES
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #21242f;
  --border:      #2e3247;
  --accent:      #5b7fff;
  --accent-hover:#7b9fff;
  --text:        #e8eaf0;
  --text-muted:  #7880a0;
  --danger:      #e05c6e;
  --success:     #3fcf8e;
  --radius:      10px;
  --topbar-h:    56px;
  --sidebar-w:   300px;
  --transition:  0.18s ease;
}

html, body { height: 100%; font-family: system-ui, -apple-system, sans-serif; }
body { background: var(--bg); color: var(--text); overflow: hidden; }

.hidden { display: none !important; }
.muted  { color: var(--text-muted); }
.error  { color: var(--danger); font-size: 0.85rem; margin-top: 0.3rem; }

/* =========================================================
   AUTH OVERLAY
   ========================================================= */
.overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: min(420px, 92vw);
}

.auth-card h1 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.auth-subtitle { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 1.2rem; }

#auth-form label {
  display: flex; flex-direction: column; gap: 0.3rem;
  font-size: 0.85rem; color: var(--text-muted);
  margin-bottom: 1rem;
}

#auth-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition);
}
#auth-form input:focus { border-color: var(--accent); }

/* =========================================================
   BUTTONS
   ========================================================= */
button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
}

.icon-btn {
  display: flex; align-items: center; gap: 0.4rem;
  background: transparent;
  color: var(--text-muted);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn svg   { width: 18px; height: 18px; }

button[type="submit"],
.primary {
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 1.2rem;
  font-weight: 600;
  width: 100%;
  margin-top: 0.5rem;
}
button[type="submit"]:hover,
.primary:hover { background: var(--accent-hover); }

/* =========================================================
   TOP BAR
   ========================================================= */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.5rem;
  flex-shrink: 0;
}

#breadcrumb-wrap { flex: 1; min-width: 0; }

#breadcrumb {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 0.1rem;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
}

#breadcrumb .crumb {
  color: var(--text-muted);
  background: none;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
}
#breadcrumb .crumb:hover { color: var(--text); background: var(--surface2); }
#breadcrumb .crumb.active { color: var(--text); cursor: default; }
#breadcrumb .sep { color: var(--border); user-select: none; }

#topbar-actions { display: flex; align-items: center; gap: 0.25rem; flex-shrink: 0; }

/* =========================================================
   MAIN + SIDEBAR LAYOUT
   ========================================================= */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  position: relative;
}

#folder-stats {
  margin-bottom: 0.8rem;
  font-size: 0.85rem;
}

/* Drop overlay */
#drop-overlay {
  position: absolute; inset: 0;
  background: rgba(91, 127, 255, 0.12);
  border: 3px dashed var(--accent);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  font-size: 1.4rem;
  color: var(--accent);
  pointer-events: none;
}

/* When sidebar is open, shrink main content */
#app.sidebar-open #main-content { margin-right: var(--sidebar-w); }

/* =========================================================
   FILE GRID
   ========================================================= */
#file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
}

.file-item {
  display: flex; flex-direction: column; align-items: center;
  padding: 0.9rem 0.5rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition), border-color var(--transition);
  text-align: center;
  gap: 0.4rem;
  position: relative;
}
.file-item:hover { background: var(--surface); border-color: var(--border); }
.file-item.selected { background: var(--surface2); border-color: var(--accent); }

.file-item .icon {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
}
.file-item .icon svg { width: 100%; height: 100%; }

.file-item .name {
  font-size: 0.8rem;
  word-break: break-all;
  max-width: 100%;
  line-height: 1.3;
  color: var(--text);
}

/* =========================================================
   SIDEBAR
   ========================================================= */
#sidebar {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1.25rem;
  overflow-y: auto;
  z-index: 20;
  display: flex; flex-direction: column; gap: 0.75rem;
}

#sidebar-close {
  background: none; color: var(--text-muted);
  align-self: flex-end; font-size: 1.1rem; padding: 0.2rem 0.5rem;
}
#sidebar-close:hover { color: var(--text); }

#sidebar-icon { display: flex; justify-content: center; }
#sidebar-icon svg { width: 64px; height: 64px; }

#sidebar-name {
  font-size: 1rem;
  word-break: break-all;
  text-align: center;
}

#sidebar-meta { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.75rem; }
#sidebar-meta dt { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
#sidebar-meta dd { font-size: 0.8rem; word-break: break-all; }

#sidebar-actions {
  display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem;
}

#sidebar-actions button {
  background: var(--surface2); color: var(--text);
  padding: 0.5rem 0.8rem;
  text-align: left;
}
#sidebar-actions button:hover { background: var(--border); }
#sidebar-actions button.danger { color: var(--danger); }

/* =========================================================
   MODALS
   ========================================================= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: min(560px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal.small { width: min(340px, 94vw); }

.modal h2 { font-size: 1.3rem; margin-bottom: 1.25rem; }
.modal h3 { font-size: 1rem; color: var(--text-muted); margin: 1rem 0 0.5rem; }

.modal-close {
  position: absolute; top: 0.75rem; right: 0.75rem;
  background: none; color: var(--text-muted); font-size: 1.1rem; padding: 0.25rem 0.5rem;
}
.modal-close:hover { color: var(--text); }

/* Admin path list */
.path-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.path-row span { flex: 1; word-break: break-all; }
.path-row button { background: none; color: var(--danger); padding: 0.2rem 0.5rem; }

.path-add-row { display: flex; gap: 0.5rem; margin: 0.5rem 0; }
.path-add-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.45rem 0.7rem; color: var(--text);
  font-size: 0.9rem; outline: none;
}
.path-add-row input:focus { border-color: var(--accent); }
.path-add-row button {
  background: var(--surface2); color: var(--text); padding: 0.45rem 0.9rem;
}
.path-add-row button:hover { background: var(--border); }

/* User list */
.user-row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.user-row .user-name { flex: 1; font-weight: 600; font-size: 0.9rem; }
.user-row .user-admin-badge {
  font-size: 0.72rem; background: var(--accent); color: #fff;
  border-radius: 4px; padding: 0.1rem 0.4rem;
}
.user-row button { background: none; color: var(--text-muted); padding: 0.2rem 0.5rem; font-size: 0.85rem; }
.user-row button:hover { color: var(--text); }
.user-row button.danger { color: var(--danger); }

/* User form permissions */
#user-permissions { margin-top: 0.75rem; }
#user-permissions h4 { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.perm-row {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  font-size: 0.85rem; margin-bottom: 0.4rem;
}
.perm-row .perm-label { min-width: 130px; color: var(--text); }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; margin-bottom: 0.5rem; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

/* Form labels in modals */
.modal form label {
  display: flex; flex-direction: column; gap: 0.3rem;
  font-size: 0.85rem; color: var(--text-muted);
  margin-bottom: 0.9rem;
}
.modal form input[type="text"],
.modal form input[type="password"] {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.5rem 0.75rem;
  color: var(--text); font-size: 0.95rem; outline: none;
  transition: border-color var(--transition);
}
.modal form input:focus { border-color: var(--accent); }

/* =========================================================
   TOAST
   ========================================================= */
#toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  pointer-events: none;
}

.toast-msg {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
  animation: slideup 0.25s ease;
}
.toast-msg.err { border-color: var(--danger); color: var(--danger); }
.toast-msg.ok  { border-color: var(--success); color: var(--success); }

@keyframes slideup {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   UPLOAD PROGRESS
   ========================================================= */
.upload-bar-wrap {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.5rem 1rem;
  z-index: 80;
  font-size: 0.85rem;
}
.upload-bar-track {
  height: 6px; background: var(--border); border-radius: 3px; margin-top: 0.3rem;
}
.upload-bar-fill {
  height: 100%; background: var(--accent); border-radius: 3px;
  transition: width 0.2s linear;
}

/* =========================================================
   RESPONSIVE — narrow screens
   ========================================================= */
@media (max-width: 600px) {
  #topbar {
    height: auto;
    min-height: var(--topbar-h);
    padding: 0.5rem 0.6rem;
    align-items: flex-start;
    flex-direction: column;
  }

  #breadcrumb-wrap {
    width: 100%;
  }

  #topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.15rem;
  }

  .icon-btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.82rem;
  }

  #main-content {
    padding: 0.9rem;
  }

  #file-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }

  #app.sidebar-open #main-content { margin-right: 0; }

  #sidebar {
    top: auto;
    left: 0;
    height: 60vh;
    border-left: none;
    border-top: 1px solid var(--border);
    width: 100%;
  }

  .modal { padding: 1.25rem; }
}

/* =========================================================
   DIALOG MODALS (confirm / prompt / overwrite)
   ========================================================= */
.dialog-message {
  color: var(--text-muted);
  font-size: 0.93rem;
  margin: 0 0 1.5rem;
  line-height: 1.5;
  word-break: break-word;
}

.dialog-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.dialog-actions--overwrite {
  justify-content: space-between;
}

.dialog-actions button {
  min-width: 5rem;
}
