/* PiNube — estilos (claro/oscuro) */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --hover: #e8edf4;
  --select: #dbe8fd;
  --border: #dfe4ec;
  --text: #1d2433;
  --muted: #5d6779;
  --primary: #2563eb;
  --primary-hover: #1d4fd7;
  --primary-soft: #dbe7fe;
  --danger: #d93a3a;
  --danger-soft: #fde4e4;
  --ok: #158a4d;
  --ok-soft: #dcf5e6;
  --warn: #c27a06;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.18);
  --radius: 14px;
  --k-folder: #5f7fa8; --k-image: #e0533d; --k-video: #d6336c; --k-audio: #8b5cf6;
  --k-pdf: #e03131; --k-archive: #8d6e63; --k-doc: #2f6fde; --k-sheet: #1f9d55;
  --k-slides: #ec8a12; --k-code: #475569; --k-text: #64748b; --k-file: #94a3b8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c; --surface: #171d27; --surface-2: #1f2733; --hover: #232c3a; --select: #1e3358;
    --border: #2a3342; --text: #e6eaf1; --muted: #98a2b3; --primary: #5b8ef8; --primary-hover: #7aa3fa;
    --primary-soft: #1d2d4f; --danger: #f06363; --danger-soft: #3b1f24; --ok: #3ccf7f; --ok-soft: #173326;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
    --k-folder: #8fa9cc; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c; --surface: #171d27; --surface-2: #1f2733; --hover: #232c3a; --select: #1e3358;
  --border: #2a3342; --text: #e6eaf1; --muted: #98a2b3; --primary: #5b8ef8; --primary-hover: #7aa3fa;
  --primary-soft: #1d2d4f; --danger: #f06363; --danger-soft: #3b1f24; --ok: #3ccf7f; --ok-soft: #173326;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
  --k-folder: #8fa9cc; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
.muted { color: var(--muted); }
.center { text-align: center; }
.flex1 { flex: 1; }
.ic { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; padding: 12px; }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn .ic { width: 18px; height: 18px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.light { color: #fff; }
.icon-btn.light:hover { background: rgba(255,255,255,.15); color: #fff; }
.only-mobile { display: none; }

/* ---------- formularios ---------- */
.form { display: grid; gap: 14px; }
.form label, .inline-form label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type="checkbox"] { width: 17px; height: 17px; padding: 0; accent-color: var(--primary); }
label.check { display: flex !important; align-items: center; gap: 8px; font-weight: 500 !important; }
.hint { margin: -4px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- flashes / toast ---------- */
.flashes { padding: 12px 24px 0; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 10px; font-size: 14px; background: var(--surface-2); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: #1d2433; color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow-lg);
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 100; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- login ---------- */
body.auth {
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, var(--primary-soft), transparent 60%), var(--bg);
}
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow-lg); display: grid; gap: 14px;
}
.auth-card h1 { font-size: 24px; margin: 6px 0 0; }
.auth-card .muted { margin: -6px 0 4px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 24px; }
.auth-brand b, .brand b { color: var(--primary); }
.brand-ic { width: 30px; height: 30px; color: var(--primary); }
.brand-ic.big { width: 40px; height: 40px; }
.secure-note { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.secure-note .ic { width: 16px; height: 16px; color: var(--ok); }

/* ---------- layout app ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 256px; flex: none; padding: 14px 12px; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; color: var(--text); padding: 6px 12px 10px; }
.brand:hover { text-decoration: none; }
.new-wrap { position: relative; padding: 4px 0 8px; }
.btn-new {
  display: inline-flex; align-items: center; gap: 12px; padding: 14px 22px 14px 18px; border-radius: 16px;
  border: 0; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow); transition: box-shadow .15s, background .15s;
}
.btn-new:hover { background: var(--hover); box-shadow: var(--shadow-lg); }
.btn-new .ic { width: 22px; height: 22px; color: var(--primary); }
.menu {
  position: absolute; top: 100%; left: 0; z-index: 30; min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px;
}
.menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0; background: none;
  color: var(--text); font: inherit; text-align: left; border-radius: 8px; cursor: pointer;
}
.menu button:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 14px; padding: 9px 16px; border-radius: 999px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.storage { margin-top: auto; padding: 14px 16px; }
.storage-label { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.storage-text { font-size: 13px; color: var(--muted); margin-top: 6px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter.sm { height: 5px; width: 120px; }
.meter-fill { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 99px; transition: width .6s ease; }
.meter-fill.warn { background: var(--warn); }
.meter-fill.danger { background: var(--danger); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px 10px 8px; min-height: 64px; }
.search {
  flex: 1; max-width: 720px; display: flex; align-items: center; gap: 10px; background: var(--surface-2);
  border-radius: 999px; padding: 0 8px 0 18px; height: 48px; transition: background .15s, box-shadow .15s;
}
.search:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.search .ic { color: var(--muted); }
.search input { border: 0; background: transparent; padding: 0; height: 100%; box-shadow: none !important; }
.search-clear { display: grid; place-items: center; color: var(--muted); width: 34px; height: 34px; border-radius: 50%; }
.search-clear:hover { background: var(--hover); }
.topbar > .flex1 { flex: 1; }
.search + .icon-btn { margin-left: auto; }
.userbox { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6); color: #fff; flex: none;
}
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.user-meta { display: grid; line-height: 1.15; }
.user-name { font-weight: 600; font-size: 14px; }
.user-role { font-size: 12px; color: var(--muted); }

.content {
  flex: 1; background: var(--surface); margin: 0 16px 16px 0; border-radius: 18px; padding: 18px 22px 40px;
  min-width: 0; border: 1px solid var(--border);
}
.page-title { font-size: 24px; font-weight: 600; margin: 4px 0 18px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 22px; min-width: 0; }
.crumb { color: var(--muted); padding: 4px 10px; border-radius: 10px; }
.crumb:hover { background: var(--hover); text-decoration: none; }
.crumb.current { color: var(--text); font-weight: 500; }
.crumb.drop-over { background: var(--primary-soft); outline: 2px dashed var(--primary); }
.sep { color: var(--muted); }
.view-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sort { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.sort select { width: auto; padding: 6px 10px; border-radius: 999px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.seg-btn { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; cursor: pointer; font-size: 16px; }
.seg-btn.active { background: var(--primary-soft); color: var(--primary); }
.selbar {
  display: flex; align-items: center; gap: 4px; background: var(--primary-soft); color: var(--primary);
  padding: 2px 6px 2px 14px; border-radius: 999px; font-weight: 600; font-size: 14px;
}
.selbar .icon-btn { color: var(--primary); width: 34px; height: 34px; }

/* ---------- lista de archivos ---------- */
.files.view-list .file-head, .files.view-list .file-row {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) 160px 100px 176px; align-items: center; gap: 8px;
}
.file-head { padding: 8px 10px; font-size: 13.5px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
.file-row { padding: 4px 10px; border-bottom: 1px solid var(--border); border-radius: 0; transition: background .1s; }
.file-row:hover { background: var(--hover); }
.file-row.selected { background: var(--select); }
.file-row.drop-over { background: var(--primary-soft); outline: 2px dashed var(--primary); outline-offset: -2px; }
.file-row.dragging { opacity: .45; }
.chk { display: grid; place-items: center; cursor: pointer; }
.fname { display: flex; align-items: center; gap: 14px; color: var(--text); min-width: 0; padding: 8px 0; }
.fname:hover { text-decoration: none; }
.ftext { display: grid; min-width: 0; }
.fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.fpath { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ficon { display: grid; place-items: center; }
.ficon .ic { width: 24px; height: 24px; }
.thumb { display: none; }
.col-date, .col-size { color: var(--muted); font-size: 14px; white-space: nowrap; }
.row-actions { display: flex; justify-content: flex-end; opacity: 0; transition: opacity .12s; }
.file-row:hover .row-actions, .file-row:focus-within .row-actions, .file-row.selected .row-actions { opacity: 1; }
.k-folder { color: var(--k-folder); } .k-image { color: var(--k-image); } .k-video { color: var(--k-video); }
.k-audio { color: var(--k-audio); } .k-pdf { color: var(--k-pdf); } .k-archive { color: var(--k-archive); }
.k-doc { color: var(--k-doc); } .k-sheet { color: var(--k-sheet); } .k-slides { color: var(--k-slides); }
.k-code { color: var(--k-code); } .k-text { color: var(--k-text); } .k-file { color: var(--k-file); }

/* vista cuadrícula */
.files.view-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.files.view-grid .file-head { display: none; }
.files.view-grid .file-row {
  position: relative; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px;
  padding: 8px; background: var(--surface-2);
}
.files.view-grid .file-row:hover { background: var(--hover); }
.files.view-grid .file-row.selected { background: var(--select); border-color: var(--primary); }
.files.view-grid .chk { position: absolute; top: 12px; left: 12px; z-index: 2; }
.files.view-grid .fname { flex-direction: column; align-items: stretch; gap: 10px; padding: 0; }
.files.view-grid .thumb, .files.view-grid .ficon {
  display: grid; place-items: center; height: 120px; border-radius: 10px; background: var(--surface); overflow: hidden;
}
.files.view-grid .thumb img { width: 100%; height: 100%; object-fit: cover; }
.files.view-grid .thumb + .ficon { display: none; }
.files.view-grid .ficon .ic { width: 52px; height: 52px; }
.files.view-grid .ftext { padding: 0 4px; }
.files.view-grid .col-date { display: none; }
.files.view-grid .col-size { font-size: 12px; padding: 0 4px; }
.files.view-grid .row-actions { justify-content: center; opacity: 1; margin-top: 2px; }
.files.view-grid .row-actions .icon-btn { width: 34px; height: 34px; }

/* vacío */
.empty { text-align: center; padding: 70px 20px; color: var(--muted); display: grid; justify-items: center; gap: 6px; }
.empty h2 { color: var(--text); font-weight: 600; margin: 8px 0 0; }
.empty p { margin: 0 0 12px; }
.empty-ic { width: 72px; height: 72px; color: var(--primary); opacity: .8; }

/* zona de arrastre */
.dropzone {
  position: fixed; inset: 0; z-index: 60; background: rgba(37, 99, 235, .12); backdrop-filter: blur(2px);
  display: grid; place-items: center; pointer-events: none;
}
.dropzone-inner {
  background: var(--surface); border: 3px dashed var(--primary); border-radius: 20px; padding: 40px 50px;
  text-align: center; box-shadow: var(--shadow-lg); font-size: 18px;
}

/* panel de subidas */
.uploads {
  position: fixed; right: 20px; bottom: 20px; width: 360px; max-width: calc(100% - 32px); z-index: 50;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--border);
}
.uploads-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 10px 10px 18px; background: #1d2433; color: #fff; font-weight: 600; }
.uploads-head .icon-btn { color: #fff; }
.uploads-head .icon-btn:hover { background: rgba(255,255,255,.15); }
.uploads-list { max-height: 260px; overflow: auto; }
.up-item { padding: 10px 16px; border-bottom: 1px solid var(--border); display: grid; gap: 6px; font-size: 14px; }
.up-top { display: flex; justify-content: space-between; gap: 10px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-pct { color: var(--muted); flex: none; }
.up-item.done .up-pct { color: var(--ok); }
.up-item.fail .up-pct { color: var(--danger); }
.up-item .meter-fill { transition: width .15s; }
.up-item.done .meter-fill { background: var(--ok); }
.up-item.fail .meter-fill { background: var(--danger); }

/* diálogos */
.dialog {
  border: 0; border-radius: 18px; padding: 24px; width: min(440px, calc(100% - 32px)); background: var(--surface);
  color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(10, 15, 25, .45); }
.dialog h3 { font-size: 20px; font-weight: 600; }
.dialog p { margin: 0 0 14px; }
.dialog select { padding: 4px; }
.dialog select option { padding: 6px 8px; border-radius: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.viewer {
  border: 0; padding: 0; width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; margin: 0;
  background: rgba(8, 10, 14, .94); color: #fff;
}
.viewer::backdrop { background: rgba(0,0,0,.6); }
.viewer[open] { display: flex; flex-direction: column; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; gap: 12px; }
.viewer-bar > span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar > div { display: flex; gap: 4px; }
.viewer-body { flex: 1; display: grid; place-items: center; padding: 0 16px 16px; min-height: 0; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: calc(100vh - 90px); border-radius: 8px; }
.viewer-body iframe { width: min(1000px, 100%); height: calc(100vh - 90px); border: 0; border-radius: 8px; background: #fff; }

/* ---------- tarjetas / admin ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h2 { font-size: 17px; font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 2px; }
.stat-n { font-size: 24px; font-weight: 700; }
.stat-l { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table.compact td { padding: 7px 10px; }
.ellipsis { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-user { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.usage-cell { display: grid; gap: 4px; }
.badge { background: var(--primary-soft); color: var(--primary); padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.tag { background: var(--surface-2); padding: 2px 8px; border-radius: 6px; font-size: 12px; font-family: ui-monospace, monospace; }
.tag.t-delete, .tag.t-admin_delete_user { background: var(--danger-soft); color: var(--danger); }
.tag.t-upload, .tag.t-login { background: var(--ok-soft); color: var(--ok); }
details.actions { position: relative; }
details.actions summary { list-style: none; }
details.actions summary::-webkit-details-marker { display: none; }
.actions-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 280px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 14px; display: grid; gap: 14px;
}
.inline-form { display: grid; gap: 8px; }
.inline-form + .inline-form { border-top: 1px solid var(--border); padding-top: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .files.view-list .file-head, .files.view-list .file-row { grid-template-columns: 32px minmax(0, 1fr) 80px 44px; }
  .files.view-list .col-date { display: none; }
  .files.view-list .row-actions { opacity: 1; }
  .files.view-list .row-actions > :not([data-act="delete"]) { display: none; }
  .user-meta { display: none; }
}
@media (max-width: 760px) {
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 70; background: var(--bg); transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 65; display: none; }
  .scrim.show { display: block; }
  .topbar { padding: 8px 12px; gap: 6px; }
  .search { height: 42px; padding-left: 12px; }
  .content { margin: 0; border-radius: 16px 16px 0 0; padding: 14px 16px 40px; border-left: 0; border-right: 0; }
  .crumbs { font-size: 18px; }
  .files.view-list .col-size { display: none; }
  .files.view-list .file-head, .files.view-list .file-row { grid-template-columns: 32px minmax(0, 1fr) 44px; }
  .files.view-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .uploads { right: 16px; bottom: 16px; }
  .flashes { padding: 8px 16px 0; }
}
