/* ==========================================================
   IMPERIO STUDIO — files.css
   Página My Files con sidebar interno + grid + drag & drop
   ========================================================== */

/* La página reutiliza el layout general (sidebar principal + topbar),
   pero el contenido se divide en un nuevo sidebar interno + área principal. */

.files-page {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--sp-6);
  min-height: calc(100vh - var(--topbar-h) - var(--sp-8));
}

/* ============ SIDEBAR INTERNO ============ */
.files-aside {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5) 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: calc(var(--topbar-h) + var(--sp-5));
  height: fit-content;
  max-height: calc(100vh - var(--topbar-h) - var(--sp-8));
}

.files-aside__head {
  padding: 0 var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-3);
}

.files-aside__title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
}

.files-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-soft);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
  user-select: none;
}

.folder-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.folder-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.folder-item.is-drop-target {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.folder-item__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.folder-item__name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-item__chevron {
  width: 14px;
  height: 14px;
  transition: transform var(--t-fast);
  color: var(--text-muted);
}

.folder-item.is-expanded .folder-item__chevron {
  transform: rotate(180deg);
}

.folder-item__count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.folder-item__menu-btn {
  opacity: 0;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: var(--r-xs);
  color: var(--text-muted);
  transition: opacity var(--t-fast), background var(--t-fast);
}

.folder-item:hover .folder-item__menu-btn,
.folder-item.is-menu-open .folder-item__menu-btn {
  opacity: 1;
}

.folder-item__menu-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.folder-item__menu-btn svg { width: 14px; height: 14px; }

/* Subcarpetas */
.folder-children {
  display: none;
  padding-left: var(--sp-4);
  margin-top: 2px;
  gap: 2px;
  flex-direction: column;
}

.folder-item.is-expanded + .folder-children {
  display: flex;
}

/* Menú contextual de carpeta (Rename / Delete) */
.folder-menu {
  position: absolute;
  right: 8px;
  top: 100%;
  margin-top: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 10;
  min-width: 140px;
  display: none;
}

.folder-item.is-menu-open .folder-menu {
  display: block;
}

.folder-menu__item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-xs);
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast);
}

.folder-menu__item:hover { background: var(--surface-hover); }
.folder-menu__item svg { width: 14px; height: 14px; }
.folder-menu__item--danger { color: #c53030; }
[data-theme='dark'] .folder-menu__item--danger { color: #fc8181; }

/* Add New Folder button */
.add-folder-btn {
  margin: var(--sp-3) var(--sp-4) 0;
  padding: var(--sp-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text-soft);
  font-size: var(--fs-sm);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  transition: border-color var(--t-fast), color var(--t-fast);
}

.add-folder-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.add-folder-btn svg { width: 16px; height: 16px; }

/* Storage indicator (abajo del sidebar interno) */
.files-aside__storage {
  margin: var(--sp-4) var(--sp-4) 0;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-sunk);
  border-radius: var(--r-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.files-aside__storage-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-soft);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.files-aside__storage-head svg { width: 16px; height: 16px; color: var(--accent); }

.files-aside__storage-bar {
  height: 4px;
  background: var(--border);
  border-radius: var(--r-full);
  overflow: hidden;
}

.files-aside__storage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: inherit;
  transition: width var(--t-slow);
}

.files-aside__storage-info {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* ============ ÁREA PRINCIPAL ============ */
.files-main {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
}

/* Toolbar */
.files-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.view-toggle {
  display: flex;
  background: var(--bg-sunk);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px;
}

.view-toggle__btn {
  padding: var(--sp-2);
  border-radius: var(--r-xs);
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}

.view-toggle__btn svg { width: 16px; height: 16px; }

.view-toggle__btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.toolbar-select {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--t-fast);
}

.toolbar-select:hover { border-color: var(--border-strong); }
.toolbar-select:focus { border-color: var(--accent); outline: none; }
.toolbar-select label { color: var(--text-muted); font-weight: 400; }

.toolbar-search {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  height: 36px;
  background: var(--bg-sunk);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  transition: border-color var(--t-fast), background var(--t-fast);
}

.toolbar-search:focus-within {
  border-color: var(--accent);
  background: var(--surface);
}

.toolbar-search svg { width: 16px; height: 16px; color: var(--text-muted); }

.toolbar-search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--fs-sm);
  color: var(--text);
}

/* Breadcrumb + acciones arriba del grid */
.files-breadcrumb {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.breadcrumb-title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
  cursor: pointer;
  position: relative;
}

.breadcrumb-title.is-readonly {
  cursor: default;
}

.breadcrumb-title.is-readonly .breadcrumb-title__chev {
  display: none;
}

.breadcrumb-title__chev {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform var(--t-fast);
}

.breadcrumb-title.is-menu-open .breadcrumb-title__chev {
  transform: rotate(180deg);
}

.breadcrumb-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: var(--sp-2);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 10;
  min-width: 160px;
  display: none;
}

.breadcrumb-title.is-menu-open .breadcrumb-menu {
  display: block;
}

.breadcrumb-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.btn-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-soft);
  transition: border-color var(--t-fast), color var(--t-fast);
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-icon svg { width: 18px; height: 18px; }

/* Upload: botón + dropdown */
.upload-split {
  display: flex;
  position: relative;
}

.upload-split__main,
.upload-split__drop {
  background: var(--ink);
  color: var(--ink-contrast);
  border: 1px solid var(--ink);
  font-weight: 600;
  font-size: var(--fs-sm);
  transition: background var(--t-fast);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.upload-split__main {
  padding: 0 var(--sp-5);
  height: 40px;
  border-radius: var(--r-full) 0 0 var(--r-full);
  border-right: 1px solid rgba(255, 255, 255, 0.15);
}

.upload-split__drop {
  width: 36px;
  height: 40px;
  border-radius: 0 var(--r-full) var(--r-full) 0;
  display: grid;
  place-items: center;
}

.upload-split__main:hover,
.upload-split__drop:hover {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.upload-split__main svg, .upload-split__drop svg { width: 16px; height: 16px; }

.upload-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--sp-2);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 200px;
  z-index: 10;
  display: none;
}

.upload-split.is-menu-open .upload-menu { display: block; }

.upload-menu__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-xs);
  font-size: var(--fs-sm);
  color: var(--text);
  width: 100%;
  text-align: left;
  transition: background var(--t-fast);
}

.upload-menu__item:hover { background: var(--surface-hover); }

.upload-menu__item svg { width: 20px; height: 20px; }

.upload-menu__divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.upload-menu__item--connected {
  color: var(--text-muted);
  font-size: 11px;
  padding: var(--sp-2) var(--sp-3);
}

/* ============ GRID DE ARCHIVOS ============ */
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-4);
  min-height: 320px;
  position: relative;
}

.files-grid.is-list {
  grid-template-columns: 1fr;
  gap: var(--sp-2);
}

.file-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  cursor: pointer;
  transition: transform var(--t-fast);
  position: relative;
}

.file-card:hover { transform: translateY(-2px); }

.file-card__thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-sunk);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.file-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-card__thumb svg {
  width: 32px;
  height: 32px;
}

.file-card__badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  backdrop-filter: blur(6px);
}

.file-card__menu-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: var(--r-xs);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  opacity: 0;
  transition: opacity var(--t-fast);
  backdrop-filter: blur(6px);
}

.file-card:hover .file-card__menu-btn { opacity: 1; }
.file-card__menu-btn svg { width: 14px; height: 14px; }

.file-menu {
  position: absolute;
  right: 6px;
  top: 34px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 20;
  min-width: 160px;
  display: none;
}

.file-card.is-menu-open .file-menu { display: block; }

.file-menu__item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-xs);
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast);
  border: none;
  background: transparent;
}

.file-menu__item:hover { background: var(--surface-hover); }
.file-menu__item svg { width: 14px; height: 14px; }
.file-menu__item--danger { color: #c53030; }
[data-theme='dark'] .file-menu__item--danger { color: #fc8181; }

.file-card__name {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
}

.file-card__meta {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  padding: 0 2px;
  display: flex;
  justify-content: space-between;
}

/* Vista lista */
.files-grid.is-list .file-card {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.files-grid.is-list .file-card__thumb {
  width: 44px;
  height: 44px;
  aspect-ratio: 1;
  flex-shrink: 0;
}

.files-grid.is-list .file-card__thumb svg { width: 20px; height: 20px; }

.files-grid.is-list .file-card__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.files-grid.is-list .file-card__meta {
  display: flex;
  gap: var(--sp-4);
  padding: 0;
}

/* ============ EMPTY STATE ============ */
.files-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
}

.files-empty__illustration {
  width: 120px;
  height: 120px;
  display: grid;
  place-items: center;
  color: var(--accent);
  opacity: 0.8;
}

.files-empty__illustration svg { width: 100%; height: 100%; }

.files-empty__title {
  font-size: var(--fs-md);
  color: var(--text-soft);
  font-weight: 500;
}

.files-empty__dropzone {
  padding: var(--sp-7) var(--sp-8);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  transition: border-color var(--t-fast), background var(--t-fast);
  text-align: center;
  line-height: 1.8;
}

.files-empty__dropzone strong { color: var(--text); font-weight: 500; }

/* ============ DRAG & DROP overlay ============ */
.files-main.is-dragover .files-grid {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
  background: var(--accent-soft);
  border-radius: var(--r-md);
}

.drag-overlay {
  position: fixed;
  inset: 0;
  background: rgba(201, 163, 92, 0.08);
  backdrop-filter: blur(2px);
  display: none;
  place-items: center;
  pointer-events: none;
  z-index: 200;
}

.drag-overlay.is-active { display: grid; }

.drag-overlay__card {
  background: var(--bg-elev);
  border: 2px dashed var(--accent);
  border-radius: var(--r-lg);
  padding: var(--sp-8) var(--sp-9);
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 500;
  color: var(--accent);
}

/* ============ UPLOAD PROGRESS TOASTS ============ */
.upload-toasts {
  position: fixed;
  bottom: var(--sp-5);
  right: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 150;
  pointer-events: none;
}

.upload-toast {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
  min-width: 280px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(.2,.8,.2,1);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.upload-toast__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-2);
}

.upload-toast__name {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.upload-toast__percent {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.upload-toast__bar {
  height: 3px;
  background: var(--border);
  border-radius: var(--r-full);
  overflow: hidden;
}

.upload-toast__fill {
  height: 100%;
  background: var(--accent);
  transition: width 150ms linear;
}

.upload-toast.is-done .upload-toast__fill { background: #10b981; }
.upload-toast.is-error .upload-toast__fill { background: #ef4444; }

/* ============ MODAL GOOGLE DRIVE IMPORT ============ */
.gdrive-modal__panel {
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.gdrive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--sp-3);
  max-height: 420px;
  overflow-y: auto;
  padding: var(--sp-1);
}

.gdrive-item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}

.gdrive-item:hover { border-color: var(--accent); background: var(--surface-hover); }
.gdrive-item.is-importing { opacity: 0.6; pointer-events: none; }

.gdrive-item__thumb {
  aspect-ratio: 1;
  background: var(--bg-sunk);
  border-radius: var(--r-xs);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.gdrive-item__thumb img { width: 100%; height: 100%; object-fit: cover; }
.gdrive-item__thumb svg { width: 32px; height: 32px; color: var(--text-muted); }

.gdrive-item__name {
  font-size: 11px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .files-page { grid-template-columns: 1fr; }
  .files-aside { position: static; max-height: none; }
  .files-toolbar { gap: var(--sp-2); }
  .toolbar-search { min-width: 140px; }
}
