/* ============================================================
   Almacén RBAC · sistema visual
   Registro: product · estrategia de color: contenida
   bg blanco puro; la identidad la lleva el índigo (sello) y la tinta.
   ============================================================ */

:root {
  /* Superficies */
  --bg: oklch(1 0 0);
  --surface-2: oklch(0.972 0.004 268);      /* rail lateral, cabeceras de tabla */
  --surface-3: oklch(0.955 0.006 268);      /* hover en superficies-2 */

  /* Tinta */
  --ink: oklch(0.24 0.02 268);
  --ink-2: oklch(0.42 0.022 268);           /* texto secundario, ≥4.5:1 sobre blanco */
  --ink-3: oklch(0.52 0.02 268);            /* metadatos grandes / iconos */

  /* Marca */
  --primary: oklch(0.53 0.13 268);
  --primary-hover: oklch(0.46 0.14 268);
  --primary-ink: oklch(1 0 0);
  --primary-tint: oklch(0.955 0.022 268);   /* selección */
  --primary-tint-2: oklch(0.925 0.035 268); /* selección hover */

  /* Semánticos */
  --danger: oklch(0.5 0.17 27);
  --danger-tint: oklch(0.962 0.018 27);
  --success: oklch(0.5 0.12 152);
  --success-tint: oklch(0.96 0.025 152);
  --warn-tint: oklch(0.965 0.03 85);

  /* Líneas y foco */
  --line: oklch(0.905 0.006 268);
  --line-strong: oklch(0.83 0.01 268);
  --focus-ring: oklch(0.62 0.12 268);

  /* Elevación */
  --shadow-1: 0 1px 2px oklch(0.24 0.02 268 / 0.06);
  --shadow-2: 0 4px 16px oklch(0.24 0.02 268 / 0.10);
  --shadow-3: 0 12px 40px oklch(0.24 0.02 268 / 0.16);

  /* Z-scale semántica */
  --z-sticky: 10;
  --z-drawer: 20;
  --z-dialog: 30;
  --z-toast: 40;

  /* Ritmo */
  --r-s: 6px;
  --r-m: 8px;
  --r-l: 12px;

  --font: system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;

  /* Escala fija (product): 12 / 13 / 14 / 16 / 19 / 22 */
  --fs-xs: 0.75rem;
  --fs-s: 0.8125rem;
  --fs-m: 0.875rem;
  --fs-l: 1rem;
  --fs-xl: 1.1875rem;
  --fs-2xl: 1.375rem;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: var(--fs-m);
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
}
h1, h2, h3 { text-wrap: balance; margin: 0; font-weight: 650; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-l); }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 0.1em 0.4em; border-radius: 4px; }
.muted { color: var(--ink-2); font-size: var(--fs-s); }
.grow { flex: 1; }
.spacer { flex: 1; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.t-right { text-align: right; }
[hidden] { display: none !important; }

/* Foco visible en todo control */
:where(button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-s);
}

/* ============ Controles base ============ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
  border-radius: var(--r-m);
  padding: 0.42rem 0.85rem;
  font: inherit;
  font-size: var(--fs-s);
  font-weight: 550;
  cursor: pointer;
  transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out;
}
.btn:hover { background: var(--surface-2); }
.btn:active { background: var(--surface-3); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in oklch, var(--danger) 45%, white); }
.btn.danger:hover { background: var(--danger-tint); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.icon-btn { padding: 0.35rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex: none; }

input[type="text"], input[type="search"], input[type="email"],
input[type="password"], select, textarea {
  font: inherit;
  font-size: var(--fs-s);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-m);
  padding: 0.42rem 0.6rem;
  transition: border-color 160ms ease-out;
}
input::placeholder, textarea::placeholder { color: var(--ink-2); }
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
textarea { resize: vertical; }
label { font-size: var(--fs-s); color: var(--ink-2); font-weight: 550; }
.check { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--ink-2); font-size: var(--fs-s); cursor: pointer; }

.form-error {
  margin: 0.4rem 0 0;
  font-size: var(--fs-s);
  color: var(--danger);
  background: var(--danger-tint);
  border: 1px solid color-mix(in oklch, var(--danger) 30%, white);
  border-radius: var(--r-m);
  padding: 0.45rem 0.7rem;
}

/* ============ Logo ============ */

.logo {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--primary);
  position: relative;
  flex: none;
}
.logo::after {
  content: "";
  position: absolute;
  inset: 5px 5px 5px 5px;
  border-radius: 2px;
  background:
    linear-gradient(to bottom, var(--primary-ink) 2px, transparent 2px) 0 0 / 100% 5px repeat-y;
  opacity: 0.9;
}

/* ============ Aviso sin servidor ============ */

.offline-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--surface-2);
}
.offline-card {
  max-width: 460px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-2);
  padding: 2rem;
}
.offline-badge {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--danger);
  background: var(--danger-tint);
  border: 1px solid color-mix(in oklch, var(--danger) 30%, white);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.8rem;
}
.offline-card h1 { margin-bottom: 0.5rem; }
.offline-card p { color: var(--ink-2); margin: 0 0 0.8rem; }
.offline-card ol { color: var(--ink-2); margin: 0 0 1.2rem; padding-left: 1.2rem; }
.offline-card li { margin: 0.3rem 0; }

/* ============ Login ============ */

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(1200px 500px at 80% -10%, var(--primary-tint), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(400px, 94vw);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-2);
  padding: 1.8rem;
}
.login-brand { display: flex; gap: 0.7rem; align-items: center; margin-bottom: 1.4rem; }
.login-brand .logo { width: 34px; height: 34px; border-radius: 9px; }
.login-brand p { margin: 0.1rem 0 0; }
.login-card form { display: grid; gap: 0.35rem; }
.login-card form .btn { margin-top: 0.7rem; }
.login-card label { margin-top: 0.5rem; }
.quick-login { margin-top: 1.4rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.quick-title { font-size: var(--fs-xs); font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.quick-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; margin-top: 0.6rem; }
.quick-user {
  display: grid;
  gap: 0.05rem;
  text-align: left;
  font: inherit;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 160ms ease-out, background-color 160ms ease-out;
}
.quick-user:hover { border-color: var(--primary); background: var(--primary-tint); }
.quick-user strong { font-size: var(--fs-s); }
.quick-user span { font-size: var(--fs-xs); color: var(--ink-2); }

/* ============ Shell ============ */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 52px;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}
.brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: var(--fs-l); }
.obra-picker { display: flex; gap: 0.35rem; align-items: center; }
#obra-select { max-width: 280px; font-weight: 550; }
.whoami { font-size: var(--fs-s); color: var(--ink-2); }
.whoami strong { color: var(--ink); }

.shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: calc(100vh - 52px);
}
.sidenav {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  padding: 0.8rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--fs-s);
  font-weight: 550;
  padding: 0.5rem 0.7rem;
  border-radius: var(--r-m);
  cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item.active { background: var(--primary-tint); color: var(--primary); }
.nav-ico svg { width: 16px; height: 16px; display: block; }

.content { min-width: 0; padding: 1.1rem 1.3rem; }
.tab-panel { max-width: 1280px; }
.page-head { margin-bottom: 0.9rem; display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head p { margin: 0.15rem 0 0; max-width: 70ch; }
.page-head.sub { margin-top: 2rem; }

/* ============ Estados ============ */

.state-block {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-l);
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--ink-2);
  margin-top: 0.8rem;
}
.state-block h2, .state-block h3 { color: var(--ink); margin-bottom: 0.3rem; }
.state-block p { margin: 0 auto; max-width: 46ch; font-size: var(--fs-s); }
.state-block .btn { margin-top: 0.9rem; }

.skeleton-row {
  height: 52px;
  border-radius: var(--r-m);
  margin-bottom: 6px;
  background: linear-gradient(100deg, var(--surface-2) 40%, var(--surface-3) 50%, var(--surface-2) 60%) 0 0 / 300% 100%;
  animation: shimmer 1.1s linear infinite;
}
@keyframes shimmer { to { background-position: -300% 0; } }

/* ============ Archivos: 3 paneles ============ */

.files-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 1.1rem;
  align-items: start;
}
.tree-pane { position: sticky; top: calc(52px + 1.1rem); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.7rem; min-height: 30px; }

.tree { list-style: none; margin: 0; padding: 0; font-size: var(--fs-s); }
.tree ul { list-style: none; padding-left: 0.9rem; margin: 0; border-left: 1px solid var(--line); margin-left: 0.55rem; }
.folder-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.34rem 0.5rem;
  border-radius: var(--r-m);
  cursor: pointer;
  color: var(--ink);
  border: none;
  background: transparent;
  width: 100%;
  font: inherit;
  font-size: var(--fs-s);
  text-align: left;
  transition: background-color 150ms ease-out;
}
.folder-row:hover { background: var(--surface-2); }
.folder-row.selected { background: var(--primary-tint); color: var(--primary); font-weight: 600; }
.folder-row.selected:hover { background: var(--primary-tint-2); }
.folder-row.no-access { color: var(--ink-3); cursor: default; }
.folder-row svg { width: 15px; height: 15px; flex: none; color: var(--ink-3); }
.folder-row.selected svg { color: var(--primary); }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cap-dots { display: inline-flex; gap: 3px; flex: none; }
.cap-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line-strong); }
.cap-dot.on { background: var(--primary); }

/* Listado */
.filters { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.search-box { position: relative; flex: 1; min-width: 180px; }
.search-box input { width: 100%; padding-left: 1.9rem; }
.search-ico { position: absolute; left: 0.55rem; top: 50%; translate: 0 -50%; color: var(--ink-3); pointer-events: none; }
.search-ico svg { width: 14px; height: 14px; display: block; }
.filters input[type="text"] { width: 110px; }

.file-list { list-style: none; margin: 0; padding: 0; }
.file-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid transparent;
  border-bottom-color: var(--line);
  cursor: pointer;
  transition: background-color 150ms ease-out;
}
.file-row:first-child { border-top-left-radius: var(--r-m); border-top-right-radius: var(--r-m); }
.file-row:hover { background: var(--surface-2); }
.file-row.selected { background: var(--primary-tint); border-radius: var(--r-m); border-color: color-mix(in oklch, var(--primary) 30%, white); }
.file-ico { color: var(--ink-3); flex: none; }
.file-ico svg { width: 17px; height: 17px; display: block; }
.file-main { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: var(--fs-s); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { color: var(--ink-2); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-tags { display: flex; gap: 0.3rem; flex: none; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--tag-ink, var(--primary));
  background: var(--tag-bg, var(--primary-tint));
  border: 1px solid color-mix(in oklch, var(--tag-ink, var(--primary)) 25%, white);
}
.tag-x { cursor: pointer; border: none; background: none; font: inherit; color: inherit; padding: 0 0.1rem; opacity: 0.7; }
.tag-x:hover { opacity: 1; }

/* Ficha (drawer) */
.detail-pane {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
  width: min(400px, 94vw);
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  padding: 1rem 1.2rem;
  overflow-y: auto;
  z-index: var(--z-drawer);
  animation: drawer-in 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }

.detail-title { font-size: var(--fs-l); font-weight: 650; word-break: break-word; margin-bottom: 0.2rem; }
.detail-facts { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.8rem; margin: 0.7rem 0; font-size: var(--fs-s); }
.detail-facts dt { color: var(--ink-2); }
.detail-facts dd { margin: 0; word-break: break-word; }
.detail-sec { font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); margin: 1.1rem 0 0.4rem; }
.detail-pane textarea { width: 100%; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.3rem; margin-bottom: 0.3rem; }
.meta-grid input { min-width: 0; }
.detail-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 1.1rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }

/* ============ Tablas ============ */

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  overflow: hidden;
  font-size: var(--fs-s);
}
.table th {
  background: var(--surface-2);
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color 150ms ease-out; }
.table tbody tr:hover { background: var(--surface-2); }
.table .cell-sub { color: var(--ink-2); font-size: var(--fs-xs); }
.table .t-right { text-align: right; white-space: nowrap; }

.pill {
  display: inline-block;
  padding: 0.08rem 0.55rem;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.pill.ok { color: var(--success); background: var(--success-tint); border-color: color-mix(in oklch, var(--success) 30%, white); }
.pill.warn { background: var(--warn-tint); color: oklch(0.45 0.1 75); border-color: oklch(0.85 0.06 85); }
.pill.bad { color: var(--danger); background: var(--danger-tint); border-color: color-mix(in oklch, var(--danger) 30%, white); }
.pill.brand { color: var(--primary); background: var(--primary-tint); border-color: color-mix(in oklch, var(--primary) 30%, white); }

.caps-list { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.cap-pill {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.06rem 0.4rem;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.cap-pill.grant { color: var(--primary); background: var(--primary-tint); border-color: color-mix(in oklch, var(--primary) 30%, white); }

/* ============ Formularios de barra ============ */

.toolbar-form {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  margin-bottom: 0.9rem;
}
.toolbar-form input[type="email"], .toolbar-form input[type="text"] { min-width: 200px; }
.toolbar-form input[type="color"] { inline-size: 34px; block-size: 34px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--bg); cursor: pointer; }

.role-form { margin-bottom: 0.9rem; display: grid; gap: 0.6rem; padding: 0.8rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-l); }
.caps-checks { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.tag-cloud { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ============ Toasts ============ */

.toasts {
  position: fixed;
  top: 60px;
  right: 1rem;
  display: grid;
  gap: 0.5rem;
  z-index: var(--z-toast);
  max-width: min(360px, 90vw);
}
.toast {
  background: var(--ink);
  color: var(--bg);
  font-size: var(--fs-s);
  padding: 0.6rem 0.9rem;
  border-radius: var(--r-m);
  box-shadow: var(--shadow-2);
  animation: toast-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
.toast.leaving { opacity: 0; transition: opacity 200ms ease-out; }
@keyframes toast-in { from { transform: translateY(-6px); opacity: 0; } }

/* ============ Diálogo ============ */

.dialog {
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-3);
  padding: 1.3rem 1.4rem;
  width: min(420px, 92vw);
  color: var(--ink);
}
.dialog::backdrop { background: oklch(0.24 0.02 268 / 0.35); }
.dialog h2 { margin-bottom: 0.3rem; font-size: var(--fs-l); }
.dialog .dialog-body { color: var(--ink-2); font-size: var(--fs-s); margin: 0 0 0.8rem; }
.dialog form { display: grid; gap: 0.4rem; }
.dialog label { margin-top: 0.4rem; }
.dialog .dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* ============ Responsive estructural ============ */

@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidenav {
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 0.4rem 0.6rem;
    position: sticky;
    top: 52px;
    z-index: var(--z-sticky);
  }
  .nav-item { width: auto; white-space: nowrap; }
  .tree-pane { position: static; }
}
@media (max-width: 760px) {
  .files-layout { grid-template-columns: 1fr; }
  .tree-pane { border: 1px solid var(--line); border-radius: var(--r-l); padding: 0.7rem; background: var(--surface-2); }
  .topbar { gap: 0.5rem; }
  .whoami { display: none; }
  .table { display: block; overflow-x: auto; }
}

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