* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1115;
  --bg-2: #161a22;
  --bg-3: #1d222c;
  --border: #2a303d;
  --text: #e7ebf3;
  --text-dim: #9aa3b2;
  --accent: #c72e29;
  --accent-2: #f25f5c;
  --primary: #2d7ef7;
  --primary-2: #4d94ff;
  --green: #2ea043;
  --red: #f04949;
  --yellow: #e3b341;
  --shadow: 0 8px 30px rgba(0,0,0,.4);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* SIDEBAR */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}
.logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  letter-spacing: 1px;
}
.brand-title { font-weight: 600; }
.brand-sub { font-size: 11px; color: var(--text-dim); }

.section {
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.conn-list, .bucket-list {
  list-style: none;
  max-height: 35vh;
  overflow-y: auto;
}
.conn-list li, .bucket-list li {
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 3px solid transparent;
}
.conn-list li:hover, .bucket-list li:hover { background: var(--bg-3); }
.conn-list li.active, .bucket-list li.active {
  background: var(--bg-3);
  border-left-color: var(--accent);
}
.conn-list li .name, .bucket-list li .name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conn-list li .menu, .bucket-list li .menu {
  visibility: hidden;
  color: var(--text-dim);
  font-size: 16px;
  padding: 0 4px;
}
.conn-list li:hover .menu, .bucket-list li:hover .menu { visibility: visible; }

.sidebar-foot {
  margin-top: auto;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status::before {
  content: '●'; color: var(--red); margin-right: 6px;
}
.status.online::before { color: var(--green); }

/* MAIN */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.toolbar {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  background: var(--bg-2);
}
.crumbs {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 14px;
}
.crumbs a {
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.crumbs a:hover { background: var(--bg-3); color: var(--text); }
.crumbs .sep { color: var(--text-dim); }
.crumbs .current { color: var(--text); font-weight: 500; }
.actions { display: flex; gap: 8px; align-items: center; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 240px;
}
.search-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  padding: 7px 32px 7px 32px;
  border-radius: 6px;
  outline: none;
}
.search-box input:focus { border-color: var(--primary); }
.search-box input:disabled { opacity: 0.4; cursor: not-allowed; }
.search-box::before {
  content: '🔍';
  position: absolute;
  left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: 0.6;
  pointer-events: none;
}
.search-box #btn-search-clear {
  position: absolute;
  right: 4px; top: 50%; transform: translateY(-50%);
  padding: 3px 8px; font-size: 12px;
  background: transparent; border: 0;
}
.search-banner {
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex; justify-content: space-between; align-items: center;
}
.search-banner .truncated { color: var(--yellow); }
.search-banner button { font-size: 12px; padding: 4px 10px; }
.path-cell {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.content {
  flex: 1;
  overflow: auto;
  padding: 20px;
  position: relative;
}
.empty-state {
  text-align: center;
  margin-top: 80px;
  color: var(--text-dim);
}
.empty-state h2 { color: var(--text); margin-bottom: 12px; }
.empty-state p { max-width: 480px; margin: 0 auto 20px; line-height: 1.5; }

.dropzone {
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--primary);
  background: rgba(45, 126, 247, 0.12);
  border-radius: 12px;
  display: none;
  pointer-events: none;
  z-index: 5;
}
.dropzone.show { display: block; }
.dropzone::after {
  content: 'Suelta los archivos para subirlos';
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600; color: var(--primary-2);
}

/* GRID */
.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-2);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.grid th, .grid td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.grid thead { background: var(--bg-3); }
.grid th { font-size: 11px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 1px; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--bg-3); }
.grid tbody tr.selected { background: rgba(45, 126, 247, 0.15); }
.grid tbody tr:last-child td { border-bottom: 0; }

.col-check { width: 36px; }
.col-size { width: 100px; }
.col-date { width: 180px; }
.col-act { width: 40px; text-align: right; }

.grid th.sortable {
  cursor: pointer;
  user-select: none;
}
.grid th.sortable:hover { color: var(--text); }
.grid th.sortable .sort-indicator {
  display: inline-block;
  width: 12px;
  opacity: 0.4;
  margin-left: 2px;
}
.grid th.sortable.active .sort-indicator { opacity: 1; color: var(--primary-2); }

.toggle-deleted {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 6px;
}
.toggle-deleted:hover { color: var(--text); }
.toggle-deleted input { cursor: pointer; }

tr.deleted .cell-name { color: var(--red); opacity: 0.75; text-decoration: line-through; }
tr.deleted .icon-file { background: rgba(240,73,73,0.15); color: var(--red); }
tr.deleted .badge-deleted {
  display: inline-block;
  background: var(--red);
  color: white;
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  text-decoration: none;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

.cell-name {
  display: flex; align-items: center; gap: 10px;
}
.icon-file {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--bg-3);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-dim);
  flex-shrink: 0;
}
.icon-folder { background: rgba(227,179,65,0.15); color: var(--yellow); }
.icon-img { background: rgba(46,160,67,0.15); color: var(--green); }
.icon-doc { background: rgba(45,126,247,0.15); color: var(--primary-2); }

.row-menu {
  position: relative;
}
.menu-btn {
  background: transparent; border: 0; color: var(--text-dim); padding: 4px 8px;
  cursor: pointer; border-radius: 4px; font-size: 16px;
}
.menu-btn:hover { background: var(--bg-3); color: var(--text); }
.dropdown {
  position: absolute;
  right: 0; top: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
  min-width: 160px;
  z-index: 50;
  box-shadow: var(--shadow);
}
.dropdown button {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--text);
  padding: 8px 14px; cursor: pointer; font-size: 13px;
}
.dropdown button:hover { background: var(--bg-2); }
.dropdown button.danger { color: var(--red); }

/* BATCH */
.batch-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  margin-top: 12px;
  display: flex; align-items: center; justify-content: space-between;
}

/* BUTTONS */
.btn, .btn-icon {
  font-family: inherit;
  font-size: 13px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
.btn:hover, .btn-icon:hover { background: var(--border); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-2); }
.btn-danger { background: var(--red); border-color: var(--red); color: white; }
.btn-danger:hover { background: #d63636; }
.btn-icon { padding: 6px 10px; font-size: 16px; line-height: 1; }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-lg { max-width: 900px; }
.modal header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal header h3 { font-size: 16px; font-weight: 600; }
.modal form { padding: 18px; overflow: auto; }
.modal form label {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.modal form input[type=text],
.modal form input[type=password],
.modal form input:not([type]) {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
}
.modal form input:focus { border-color: var(--primary); outline: 0; }
.modal .row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.import-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; margin-bottom: 14px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.import-row button { white-space: nowrap; }
.import-row.dragover { border-color: var(--primary); background: rgba(45,126,247,0.08); }
.modal label.check {
  display: flex; align-items: center; gap: 8px;
  text-transform: none; letter-spacing: normal; font-size: 13px;
  color: var(--text); padding-bottom: 10px;
}
.modal .hint { color: var(--text-dim); font-size: 12px; margin: -8px 0 14px; }
.modal footer {
  display: flex; justify-content: flex-end; gap: 10px; align-items: center;
  margin-top: 6px;
}
.test-result { flex: 1; font-size: 12px; }
.test-result.ok { color: var(--green); }
.test-result.err { color: var(--red); }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* PREVIEW */
.preview-body {
  padding: 0;
  background: var(--bg);
  flex: 1;
  min-height: 300px;
  max-height: 60vh;
  overflow: auto;
  display: flex; align-items: center; justify-content: center;
}
.preview-body img, .preview-body video {
  max-width: 100%;
  max-height: 60vh;
  display: block;
}
.preview-body iframe { width: 100%; height: 60vh; border: 0; background: white; }
.preview-body pre {
  width: 100%; height: 100%;
  padding: 16px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
  overflow: auto;
  align-self: stretch;
}
.preview-meta {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
  color: var(--text-dim);
}
.versions-panel {
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  max-height: 240px;
  overflow: auto;
}
.version-row {
  display: grid;
  grid-template-columns: 1fr 130px 100px auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  padding-left: 8px;
  margin-left: -8px;
  transition: background .15s, border-color .15s;
}
.version-row:last-child { border-bottom: 0; }
.version-row.viewing {
  background: rgba(45, 126, 247, 0.10);
  border-left-color: var(--primary);
}
.version-row.viewing .vid::before {
  content: '👁 ';
  color: var(--primary-2);
}
.version-row .vid {
  font-family: monospace; font-size: 11px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.version-row .latest { color: var(--green); font-weight: 600; font-size: 11px; }
.version-row .delete-marker { color: var(--red); font-weight: 600; font-size: 11px; }
.version-row .actions { display: flex; gap: 6px; }
.version-row button { font-size: 11px; padding: 4px 8px; }

/* TOAST */
#toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
  min-width: 240px;
  pointer-events: auto;
  animation: slide-in .25s ease-out;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--primary); }
@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* INFO PANEL */
.info-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  height: 100vh;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s ease-out;
  z-index: 80;
  box-shadow: -8px 0 24px rgba(0,0,0,.35);
}
.info-panel.open { transform: translateX(0); }
.info-panel header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 10px;
}
.info-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.info-title .icon-file { width: 36px; height: 36px; font-size: 13px; flex-shrink: 0; }
.info-name-wrap { min-width: 0; flex: 1; }
.info-name { font-weight: 600; word-break: break-all; line-height: 1.3; }
.info-path { font-size: 11px; color: var(--text-dim); margin-top: 2px; word-break: break-all; }
.info-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.info-actions .btn { padding: 8px; font-size: 12px; text-align: center; }
.info-actions .btn-primary { grid-column: 1 / -1; }
.info-section { padding: 12px 16px; border-bottom: 1px solid var(--border); overflow-y: auto; }
.info-section:last-child { border-bottom: 0; flex: 1; }
.info-section h4 {
  font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 10px; font-weight: 600;
}
.info-section dl { display: flex; flex-direction: column; gap: 8px; }
.info-section dl > div { display: flex; flex-direction: column; gap: 2px; }
.info-section dt { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.info-section dd { font-size: 13px; word-break: break-all; }
.info-section .mono { font-family: 'Consolas', 'Monaco', monospace; font-size: 11px; }

.main.with-info { padding-right: 360px; }
@media (max-width: 900px) {
  .info-panel { width: 100%; }
  .main.with-info { padding-right: 0; }
}

/* AUTH OVERLAY */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-brand {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.auth-form { display: flex; flex-direction: column; }
.auth-form label {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.auth-form label input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
}
.auth-form label input:focus { border-color: var(--primary); outline: 0; }
.auth-form .hint { margin-bottom: 16px; color: var(--text-dim); font-size: 13px; line-height: 1.4; }
.auth-submit { width: 100%; padding: 11px; font-size: 14px; margin-top: 4px; }
.auth-back { width: 100%; padding: 9px; font-size: 12px; margin-top: 8px; }
.enroll-qr {
  background: white;
  padding: 16px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}
.enroll-qr svg { display: block; max-width: 220px; height: auto; }
.enroll-secret {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  font-family: 'Consolas', monospace;
  font-size: 12px;
  border-radius: 4px;
  margin-left: 4px;
  word-break: break-all;
}
.recovery-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-family: 'Consolas', monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin: 12px 0;
}
.recovery-codes .code {
  padding: 6px 8px;
  background: var(--bg-3);
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  letter-spacing: 1px;
}
.recovery-codes .code.used {
  text-decoration: line-through;
  opacity: 0.5;
}
.check-confirm {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 12px 0 !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  font-size: 13px !important;
  color: var(--text) !important;
  cursor: pointer;
}
.check-confirm input { cursor: pointer; }

/* Sidebar user info */
.sidebar-user {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-user .user-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user .user-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-3);
  color: var(--text-dim);
}
.sidebar-user .user-role.admin {
  background: rgba(45,126,247,0.2);
  color: var(--primary-2);
}
.sidebar-user .user-actions { display: flex; gap: 2px; }
.sidebar-user .btn-icon { padding: 4px 8px; font-size: 14px; }

.account-section { margin-bottom: 24px; }
.account-section h4 {
  font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 12px;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4150; }
