/* Download Control — hoja de estilos unica.
   Sin dependencias externas: la CSP prohibe cargar recursos de terceros. */

/* Paleta.
   Tres estados de tema: automatico (sigue al sistema), claro y oscuro.

   El claro se define en :root pelado, el oscuro se aplica por media query
   -para el modo automatico- y tambien por [data-theme="dark"], para que el
   selector manual gane sobre la preferencia del sistema en ambos sentidos. */

:root {
  --bg: #eef0f4;
  --surface: #fafbfc;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1a1d21;
  --text-dim: #666e79;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --sidebar-w: 250px;
}

/* Valores del tema oscuro, en un solo sitio para no repetirlos. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f38;
    --text: #e6e8eb;
    --text-dim: #9aa3ae;
    --accent: #3b82f6;
    --accent-text: #ffffff;
    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 20px rgba(0,0,0,.4);
  }
}

/* Oscuro forzado desde el selector, aunque el sistema pida claro. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1f232b;
  --border: #2a2f38;
  --text: #e6e8eb;
  --text-dim: #9aa3ae;
  --accent: #3b82f6;
  --accent-text: #ffffff;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 20px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }

/* El atributo hidden debe ocultar de verdad.
   Cualquier regla con `display` (flex, grid, block) lo pisa por especificidad,
   asi que un elemento con [hidden] seguiria visible. Le pasa a los overlays de
   abajo, que usan flex y grid: sin esto, la previsualizacion y el modal tapan
   la pagina entera nada mas cargar. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--text-dim); }
.small { font-size: .85rem; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .55rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.btn-block { width: 100%; }
.btn-sm { padding: .35rem .7rem; font-size: .875rem; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Formularios ---------- */

label {
  display: block;
  margin: .9rem 0 .3rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-dim);
}

select,
input[type=text], input[type=search], input:not([type]), input[type=password] {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* ---------- Tarjetas y paginas de acceso ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2rem;
}

.centered {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

/* Boton de tema de las paginas de acceso: fuera de la tarjeta, discreto. */
.theme-corner {
  position: fixed;
  top: .75rem;
  right: .75rem;
  z-index: 10;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.auth-card .logo { color: var(--accent); margin-bottom: .75rem; }
.auth-card h1 { font-size: 1.35rem; }
.auth-card .btn-primary { margin-top: 1.25rem; }
.auth-card form { text-align: left; }
.auth-card form .btn { margin-top: 1rem; }

.status { min-height: 1.4em; margin: .9rem 0 0; font-size: .9rem; }
.status-error { color: var(--danger); }
.status-ok { color: var(--ok); }

.recovery { margin-top: 1.75rem; text-align: left; border-top: 1px solid var(--border); padding-top: 1rem; }
.recovery summary { cursor: pointer; font-size: .875rem; color: var(--text-dim); }
.recovery summary:hover { color: var(--text); }

.warn-box {
  margin-top: 1.25rem;
  padding: .75rem;
  border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  border-radius: 0 6px 6px 0;
  text-align: left;
}

/* ---------- Estructura ---------- */

.layout { display: flex; height: 100%; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 600;
  color: var(--accent);
  padding: .25rem;
}
.brand span { color: var(--text); font-size: .95rem; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem .7rem;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: .925rem;
  text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 500; }

.storage { margin-top: auto; }
.storage-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: .5rem;
}
.storage-fill { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.storage-fill.full { background: var(--danger); }
.storage-fill.warn { background: var(--warn); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.menu-toggle { display: none; }

.search-wrap { position: relative; flex: 1; max-width: 520px; }
.search-icon {
  position: absolute;
  left: .7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}
#search { padding-left: 2.2rem; }

.topbar-actions { display: flex; gap: .25rem; margin-left: auto; }

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  padding: .7rem 1.25rem;
  font-size: .9rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.breadcrumb a { color: var(--text-dim); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { opacity: .5; }
.breadcrumb .current { color: var(--text); font-weight: 500; }

.content { flex: 1; overflow-y: auto; padding: 1rem 1.25rem 4rem; position: relative; }

/* ---------- Listado de ficheros ---------- */

.file-list { display: flex; flex-direction: column; gap: 1px; }

.file-row {
  display: grid;
  grid-template-columns: 32px 1fr auto auto auto auto;
  align-items: center;
  gap: .85rem;
  padding: .6rem .75rem;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.file-row:hover { background: var(--surface-2); }
.file-row.selected { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.file-row .icon { color: var(--text-dim); display: flex; }
.file-row .icon.folder { color: var(--accent); }
.file-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .meta { font-size: .85rem; color: var(--text-dim); white-space: nowrap; }
/* Los iconos de accion aparecen al pasar por encima, para que la lista no se
   vea recargada. */
.file-row .btn-icon { opacity: 0; transition: opacity .12s; }
.file-row:hover .btn-icon,
.file-row:focus-within .btn-icon { opacity: 1; }

/* En pantallas tactiles no hay hover: se dejan siempre a la vista. */
@media (hover: none) {
  .file-row .btn-icon { opacity: 1 !important; }
}

/* Acciones de la vista de cuadricula. */
.card-actions {
  display: flex;
  justify-content: center;
  gap: .25rem;
  margin-top: .5rem;
  opacity: 0;
  transition: opacity .12s;
}
.file-card:hover .card-actions,
.file-card:focus-within .card-actions { opacity: 1; }
@media (hover: none) {
  .card-actions { opacity: 1; }
}

/* Vista de cuadricula */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .85rem;
}
.file-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem .75rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
}
.file-card:hover { border-color: var(--accent); }
.file-card.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.file-card .icon { color: var(--text-dim); margin-bottom: .5rem; }
.file-card .icon.folder { color: var(--accent); }
.file-card .name {
  font-size: .875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-card .meta { font-size: .78rem; color: var(--text-dim); margin-top: .2rem; }

/* Barra de acciones propia de una vista, como el vaciar de la papelera. */
.view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0 .25rem .85rem;
  margin-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.view-bar p { margin: 0; }

.empty { text-align: center; padding: 4rem 1rem; }
.empty svg { color: var(--border); margin-bottom: 1rem; }

/* ---------- Zona de arrastre ---------- */

.dropzone-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  margin: 1rem;
  pointer-events: none;
  z-index: 20;
}
.dropzone-inner { text-align: center; color: var(--accent); font-weight: 500; }

/* ---------- Panel de subidas ---------- */

.uploads {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: min(360px, calc(100vw - 2rem));
  max-height: 55vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 40;
  overflow: hidden;
}
.uploads-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .75rem .6rem 1rem;
  border-bottom: 1px solid var(--border);
}
.uploads-list { list-style: none; margin: 0; padding: .5rem; overflow-y: auto; }
.upload-item { padding: .5rem; font-size: .875rem; }
.upload-item .row { display: flex; justify-content: space-between; gap: .5rem; }
.upload-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .pct { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.upload-bar { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: .35rem; overflow: hidden; }
.upload-fill { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.upload-item.done .upload-fill { background: var(--ok); }
.upload-item.error .upload-fill { background: var(--danger); }
.upload-item.error .pct { color: var(--danger); }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.5);
  padding: 1rem;
  z-index: 60;
}
.modal { width: 100%; max-width: 420px; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }

.code-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .4rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .9rem;
  margin: 1rem 0;
}
/* Boton de eleccion con titulo y explicacion, para decisiones donde la
   diferencia entre opciones no es evidente por el nombre. */
.btn.choice {
  flex-direction: column;
  align-items: flex-start;
  gap: .2rem;
  text-align: left;
  padding: .75rem .9rem;
  height: auto;
}
.btn.choice span { font-weight: 400; line-height: 1.35; }

.code-list li { list-style: none; padding: .4rem; background: var(--surface-2); border-radius: 6px; text-align: center; }

/* ---------- Previsualizacion ---------- */

.preview-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,.92);
  z-index: 70;
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  color: #fff;
}
.preview-head > div { display: flex; align-items: center; gap: .5rem; }
.preview-head .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }
.preview-head .btn-icon { color: #fff; }
.preview-head .btn-icon:hover { background: rgba(255,255,255,.15); }
.preview-body {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: auto;
  min-height: 0;
}
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.preview-body pre {
  width: 100%;
  max-width: 900px;
  max-height: 100%;
  overflow: auto;
  background: var(--surface);
  color: var(--text);
  padding: 1.25rem;
  border-radius: var(--radius);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Avisos ---------- */

.toasts {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 80;
  pointer-events: none;
}
.toast {
  padding: .65rem 1rem;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: .9rem;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
  max-width: min(90vw, 460px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Ajustes ---------- */

.settings-section {
  max-width: 640px;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: 0; }

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--border);
}
.item-row:last-child { border-bottom: 0; }
.item-row .info { min-width: 0; }
.item-row .info strong { display: block; }

.badge {
  display: inline-block;
  padding: .1rem .45rem;
  border-radius: 4px;
  font-size: .75rem;
  background: var(--surface-2);
  color: var(--text-dim);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

/* ---------- Movil ---------- */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content { padding: .75rem .75rem 5rem; }
  .breadcrumb { padding: .6rem .75rem; }
  .topbar { padding: .6rem .75rem; }

  /* En pantallas estrechas sobra todo menos el nombre. */
  .file-row { grid-template-columns: 28px 1fr auto auto; gap: .5rem; }
  .file-row .meta.modified { display: none; }

  .uploads { right: .5rem; left: .5rem; bottom: .5rem; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
