:root {
  --bg: #f7f6f4;
  --panel: #ffffff;
  --panel-soft: #fffaf6;
  --line: #ddd9d5;
  --line-soft: #ece8e4;
  --text: #2b2a29;
  --muted: #76706c;
  --orange: #f27632;
  --orange-deep: #e95a0a;
  --orange-soft: #fff0e5;
  --orange-soft-2: #ffe3cf;
  --brown: #694536;
  --brown-dark: #4a3028;
  --danger: #a93434;
  --success-bg: #eef7ea;
  --success-line: #c9dec1;
  --shadow: 0 8px 24px rgba(66, 45, 35, .08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin:0;
  font-family:"Segoe UI", Arial, Helvetica, sans-serif;
  color:var(--text);
  background:var(--bg);
  font-size:14px;
}
a { color:inherit; }
button, input, select { font:inherit; }

/* ---------- Cabecera / marca ---------- */
.topbar {
  height:64px;
  display:grid;
  grid-template-columns:1fr auto 1fr;
  align-items:center;
  padding:0 14px;
  background:rgba(255,255,255,.98);
  border-bottom:1px solid var(--line-soft);
  box-shadow:0 2px 9px rgba(50,35,28,.05);
  position:sticky;
  top:0;
  z-index:20;
}
.topbar-left { display:flex; align-items:center; gap:9px; justify-self:start; min-width:0; }
.app-mark {
  min-width:44px;
  height:34px;
  padding:0 9px;
  display:grid;
  place-items:center;
  border-radius:9px;
  background:linear-gradient(135deg,var(--orange-deep),var(--orange));
  color:#fff;
  font-weight:800;
  letter-spacing:.6px;
  box-shadow:0 4px 10px rgba(242,118,50,.18);
}
.app-mark.large { height:40px; min-width:52px; border-radius:10px; }
.app-labels { display:flex; flex-direction:column; min-width:0; line-height:1.1; }
.app-labels strong { font-size:13px; color:var(--brown-dark); }
.app-labels span { font-size:10.5px; color:var(--muted); margin-top:3px; }
.topbar-logo { justify-self:center; display:flex; align-items:center; height:58px; }
.topbar-logo img { display:block; width:min(340px,34vw); max-height:48px; object-fit:contain; }
.top-actions { justify-self:end; display:flex; align-items:center; gap:8px; }
.user-chip {
  display:flex;
  align-items:center;
  gap:6px;
  padding:4px 8px 4px 5px;
  border:1px solid var(--line-soft);
  border-radius:999px;
  background:#fff;
  color:var(--brown-dark);
  font-size:12px;
}
.user-dot {
  width:25px; height:25px; border-radius:50%;
  display:grid; place-items:center;
  background:var(--orange-soft); color:var(--orange-deep); font-weight:800;
}
.logout-form { margin:0; }

/* ---------- Botones ---------- */
.btn {
  border:1px solid var(--line);
  background:#fff;
  color:var(--brown-dark);
  border-radius:8px;
  padding:7px 11px;
  cursor:pointer;
  text-decoration:none;
  display:inline-flex;
  gap:6px;
  align-items:center;
  justify-content:center;
  font-weight:600;
  transition:.15s ease;
}
.btn:hover { border-color:#cfc6bf; background:#fbfaf9; transform:translateY(-1px); }
.btn-primary {
  background:linear-gradient(135deg,var(--orange-deep),var(--orange));
  color:#fff;
  border-color:var(--orange-deep);
  box-shadow:0 4px 10px rgba(242,118,50,.17);
}
.btn-primary:hover { background:linear-gradient(135deg,#dc5207,#ee6c27); border-color:#dc5207; }
.btn-soft { background:var(--panel-soft); border-color:#eaded5; color:var(--brown); }
.btn-danger { color:var(--danger); }

/* ---------- Disposición principal ---------- */
.layout { min-height:calc(100vh - 64px); display:grid; grid-template-columns:220px 1fr; }
.sidebar {
  background:#fff;
  border-right:1px solid var(--line-soft);
  padding:9px 7px;
  overflow:auto;
}
.compact-sidebar { padding-top:7px; }
.tree-root {
  height:36px;
  display:flex;
  align-items:center;
  gap:8px;
  padding:0 9px;
  color:var(--brown-dark);
  font-weight:800;
  font-size:12px;
  letter-spacing:.2px;
  border-bottom:1px solid var(--line-soft);
  margin-bottom:5px;
}
.tree { display:block; }
.category {
  display:flex;
  align-items:center;
  gap:8px;
  min-height:32px;
  padding:4px 9px 4px 12px;
  border-radius:7px;
  text-decoration:none;
  margin:1px 0;
  white-space:nowrap;
  transition:.12s ease;
}
.category:hover { background:#fff7f1; }
.category.active {
  background:var(--orange-soft);
  color:var(--brown-dark);
  font-weight:800;
  border:2px solid var(--orange);
  border-left-width:5px;
  padding-left:9px;
  box-shadow:0 2px 7px rgba(242,118,50,.10);
}
.admin-links { padding-top:9px; margin-top:9px; border-top:1px solid var(--line-soft); }
.compact-admin-links .category { padding-left:10px; }
.sidebar-caption { font-size:9.5px; letter-spacing:.9px; color:#9a918c; font-weight:800; padding:3px 10px 5px; }

/* ---------- Íconos CSS: todos en naranja ---------- */
.ui-icon { display:inline-block; width:17px; height:17px; flex:0 0 17px; position:relative; color:var(--orange); }
.icon-folder { height:12px; margin-top:2px; border:1.7px solid var(--orange); border-radius:2px; background:var(--orange); }
.icon-folder::before { content:""; position:absolute; left:1px; top:-5px; width:7px; height:4px; border-radius:2px 2px 0 0; background:var(--orange); }
.icon-folder-plus { height:12px; margin-top:2px; border:1.7px solid var(--orange); border-radius:2px; background:var(--orange); }
.icon-folder-plus::before { content:""; position:absolute; left:1px; top:-5px; width:7px; height:4px; border-radius:2px 2px 0 0; background:var(--orange); }
.icon-folder-plus::after { content:"+"; position:absolute; right:-5px; bottom:-7px; width:11px; height:11px; border-radius:50%; display:grid; place-items:center; background:var(--orange); color:white; font-size:10px; font-weight:800; line-height:1; }
.icon-key::before { content:""; position:absolute; left:1px; top:3px; width:6px; height:6px; border:2px solid var(--orange); border-radius:50%; }
.icon-key::after { content:""; position:absolute; left:8px; top:8px; width:9px; height:2px; background:var(--orange); box-shadow:4px 3px 0 -0.4px var(--orange); transform:rotate(-2deg); transform-origin:left center; }
.icon-search::before { content:""; position:absolute; left:2px; top:2px; width:8px; height:8px; border:2px solid var(--orange); border-radius:50%; }
.icon-search::after { content:""; position:absolute; left:11px; top:11px; width:6px; height:2px; background:var(--orange); transform:rotate(45deg); transform-origin:left center; border-radius:2px; }
.icon-vault::before { content:""; position:absolute; left:2px; top:6px; width:13px; height:9px; border:2px solid var(--orange); border-radius:3px; }
.icon-vault::after { content:""; position:absolute; left:5px; top:0; width:7px; height:8px; border:2px solid var(--orange); border-bottom:0; border-radius:7px 7px 0 0; }
.icon-users::before { content:"● ●"; position:absolute; left:0; top:-4px; font-size:12px; letter-spacing:-3px; color:var(--orange); }
.icon-users::after { content:""; position:absolute; left:1px; top:9px; width:14px; height:6px; border-radius:8px 8px 2px 2px; background:var(--orange-soft-2); border:1.5px solid var(--orange); }
.icon-history::before { content:"↶"; position:absolute; inset:-3px 0 0 0; font-size:22px; line-height:17px; color:var(--orange); font-weight:700; }
.icon-link::before { content:"↗"; position:absolute; inset:-2px 0 0 1px; font-size:20px; font-weight:700; color:var(--orange); }
.icon-user::before { content:"●"; position:absolute; left:5px; top:-4px; font-size:14px; color:var(--orange); }
.icon-user::after { content:""; position:absolute; left:3px; top:10px; width:11px; height:6px; border-radius:8px 8px 2px 2px; background:var(--orange-soft-2); border:1.5px solid var(--orange); }

.main { padding:12px; min-width:0; }
.compact-main { padding:9px 10px 12px; }
.compact-toolbar {
  min-height:40px;
  display:grid;
  grid-template-columns:minmax(150px, auto) minmax(220px, 440px) 36px;
  align-items:center;
  gap:9px;
  margin-bottom:7px;
}
.toolbar-title { display:flex; align-items:baseline; gap:8px; min-width:0; }
.toolbar-title strong { font-size:17px; color:var(--brown-dark); }
.record-count { color:var(--muted); font-size:11px; white-space:nowrap; }
.compact-search {
  height:33px;
  border:1px solid var(--line);
  background:#fff;
  border-radius:9px;
  display:flex;
  align-items:center;
  padding:0 7px;
  min-width:0;
  box-shadow:0 1px 3px rgba(70,50,40,.025);
}
.search-icon { padding:0 4px 0 2px; }
.compact-search input { border:0; outline:0; width:100%; min-width:0; padding:4px 3px; background:transparent; font-size:13px; }
.compact-search:focus-within { border-color:#f0a578; box-shadow:0 0 0 3px rgba(242,118,50,.08); }
.clear-search { text-decoration:none; color:var(--muted); padding:1px 5px; font-size:17px; line-height:1; }
.icon-btn {
  width:33px; height:33px; display:grid; place-items:center;
  border:1px solid #efcab1; border-radius:9px; background:var(--orange-soft);
  color:var(--orange-deep); text-decoration:none; cursor:pointer; font-size:20px; line-height:1; font-weight:700;
}
.icon-btn:hover { background:var(--orange-soft-2); border-color:#eaa77b; }
.add-btn { justify-self:end; }

/* ---------- Tabla compacta ---------- */
.table-wrap { background:#fff; border:1px solid var(--line); border-radius:9px; overflow:auto; box-shadow:0 2px 9px rgba(65,45,35,.035); }
.compact-table-wrap { border-radius:8px; }
table { border-collapse:collapse; width:100%; }
.credential-table { min-width:650px; table-layout:fixed; }
th, td { text-align:left; border-bottom:1px solid var(--line-soft); }
.credential-table th {
  height:29px; padding:3px 7px; color:#6d625c; font-size:11.5px;
  background:#fbf8f6; border-right:1px solid var(--line-soft); font-weight:700;
}
.credential-table th:last-child { border-right:0; }
.credential-table td {
  height:30px; padding:3px 7px; font-size:12.5px; overflow:hidden;
  text-overflow:ellipsis; white-space:nowrap; border-right:1px solid #f3efec;
}
.credential-table td:last-child { border-right:0; }
.credential-row { cursor:default; outline:none; transition:background .08s ease; }
.credential-row:hover { background:#fff8f3; }
.credential-row.selected { background:var(--orange-soft); }
.credential-row:focus-visible { box-shadow:inset 0 0 0 1px #f0a578; }
.key-col, .key-cell { width:31px; text-align:center !important; padding-left:3px !important; padding-right:3px !important; }
.client-cell { width:38%; font-weight:650; cursor:pointer; }
.user-cell { width:25%; font-variant-numeric:tabular-nums; }
.url-cell { width:31%; color:#6f6762; }
.menu-col, .menu-cell { width:31px; text-align:center !important; padding:0 !important; }
.row-menu-btn { width:28px; height:27px; border:0; background:transparent; cursor:pointer; border-radius:6px; line-height:1; font-size:18px; color:#7a706a; }
.row-menu-btn:hover { background:var(--orange-soft); color:var(--orange-deep); }
.interaction-hint { font-size:10.5px; color:#8a817c; margin:5px 2px 0; }
.compact-empty { padding:32px; font-size:12px; display:flex; flex-direction:column; gap:5px; align-items:center; }
.empty-icon { transform:scale(1.15); margin-bottom:5px; }

.context-menu {
  position:fixed; z-index:1000; min-width:180px; padding:4px; background:#fff;
  border:1px solid #d7d0cb; border-radius:9px; box-shadow:0 9px 24px rgba(56,39,31,.14);
}
.context-menu[hidden] { display:none; }
.context-menu button {
  width:100%; height:32px; display:flex; align-items:center; gap:9px; border:0;
  border-radius:6px; background:#fff; padding:4px 9px; text-align:left; cursor:pointer; font-size:12.5px; color:var(--brown-dark);
}
.context-menu button:hover { background:var(--orange-soft); }
.context-menu button:disabled { opacity:.55; cursor:wait; }

/* ---------- Formularios / fichas ---------- */
.main-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px; }
.main-head h1 { font-size:21px; margin:3px 0 0; color:var(--brown-dark); }
.page-subtitle { margin:4px 0 0; color:var(--muted); font-size:12px; }
.back-link, .main-head .small { color:var(--orange-deep); text-decoration:none; font-size:12px; font-weight:600; }
.back-link:hover, .main-head .small:hover { text-decoration:underline; }
.actions { display:flex; flex-wrap:wrap; gap:6px; }
.action-btn { padding:6px 9px; font-size:12px; }
.card { background:#fff; border:1px solid var(--line); border-radius:10px; padding:16px; max-width:720px; box-shadow:0 3px 12px rgba(65,45,35,.035); }
.field { margin-bottom:12px; }
.field label { display:block; font-size:12px; color:#6f6762; margin-bottom:5px; font-weight:600; }
.field input, .field select, .inline-admin-form input, .category-row-form input, .category-row-form select {
  width:100%; padding:8px 9px; border:1px solid var(--line); border-radius:8px; background:#fff; outline:none;
}
.field input:focus, .field select:focus, .inline-admin-form input:focus, .category-row-form input:focus, .category-row-form select:focus {
  border-color:#f0a578; box-shadow:0 0 0 3px rgba(242,118,50,.08);
}
.detail-row { padding:8px 0; border-bottom:1px solid var(--line-soft); }
.detail-row:last-child { border-bottom:0; }
.detail-label { display:block; font-size:10.5px; color:var(--muted); margin-bottom:3px; text-transform:uppercase; letter-spacing:.45px; font-weight:700; }
.error { background:#fff1f1; border:1px solid #e7c3c3; color:#8a1f1f; padding:9px 11px; border-radius:8px; margin-bottom:10px; }
.success { background:var(--success-bg); border:1px solid var(--success-line); color:#3c652d; padding:9px 11px; border-radius:8px; margin-bottom:10px; }
.empty { padding:25px; color:var(--muted); text-align:center; }
.small { font-size:12px; color:var(--muted); }

/* ---------- Login ---------- */
.login-page {
  min-height:100vh; display:grid; place-items:center; padding:24px;
  background:radial-gradient(circle at 50% 18%, #fff 0, #fffaf6 36%, #f5f2ef 100%);
}
.login-box { width:min(430px,100%); background:#fff; border:1px solid var(--line-soft); border-radius:16px; padding:28px; box-shadow:var(--shadow); }
.login-logo { display:block; width:min(330px,90%); height:auto; margin:0 auto 23px; }
.login-app-title { display:flex; align-items:center; gap:12px; margin-bottom:20px; }
.login-box h1 { margin:0 0 3px; font-size:22px; color:var(--brown-dark); }
.login-box p { margin:0; color:var(--muted); font-size:12.5px; }
.login-button { width:100%; margin-top:3px; min-height:40px; }

/* ---------- Claves / ojos ---------- */
.secret-field-wrap { display:grid; grid-template-columns:minmax(0,1fr) 40px; gap:6px; align-items:center; }
.secret-field-wrap .secret-input { width:100%; }
.secret-input { -webkit-text-security:disc; font-family:inherit; }
.secret-input.secret-revealed { -webkit-text-security:none; }
.secret-peek-btn, .admin-secret-peek-btn {
  height:36px; border:1px solid #efcab1; border-radius:8px; background:var(--orange-soft);
  color:var(--brown); cursor:pointer; font-size:17px; line-height:1; padding:0; user-select:none; touch-action:manipulation;
}
.secret-peek-btn:hover, .admin-secret-peek-btn:hover { background:var(--orange-soft-2); }
.secret-peek-btn:active, .secret-peek-btn.is-peeking,
.admin-secret-peek-btn:active, .admin-secret-peek-btn.is-peeking { background:#ffd6bb; border-color:#ef9b64; }
.admin-secret-peek-btn:disabled { opacity:.45; cursor:not-allowed; }
.password-status { margin-top:6px; color:#786f69; line-height:1.35; }
.owner-only-note { margin-bottom:12px; }

/* ---------- Administración ---------- */
.admin-page { padding-top:13px; }
.admin-width { max-width:1120px; }
.admin-section-title { margin:0 0 13px; font-size:16px; color:var(--brown-dark); }
.admin-help { display:block; margin:9px 0 0; line-height:1.45; }
.compact-form-grid { display:grid; grid-template-columns:1fr 1fr; gap:0 13px; }
.compact-form-grid .field { margin-bottom:10px; }
.form-actions-full { grid-column:1 / -1; }
.admin-table th { background:#fbf8f6; font-size:11.5px; padding:8px 10px; color:#6a605b; }
.admin-table td { font-size:12.5px; padding:8px 10px; vertical-align:middle; }
.admin-action-cell { width:104px; text-align:right; }
.status-pill { display:inline-block; border-radius:999px; padding:3px 8px; font-size:10.5px; white-space:nowrap; font-weight:700; }
.status-active { background:#edf5e8; color:#42642f; }
.status-blocked { background:#f8e9e9; color:#873232; }
.admin-split { display:grid; grid-template-columns:minmax(300px,380px) minmax(430px,1fr); gap:16px; align-items:start; }
.admin-card-wide { max-width:none; }
.admin-note { background:#fff8f2; border:1px solid #f0d2bd; padding:11px; border-radius:8px; font-size:12.5px; line-height:1.45; color:#654638; }
.permission-table-wrap { border:1px solid var(--line); border-radius:8px; overflow:hidden; }
.permission-table th { height:30px; padding:4px 9px; background:#fbf8f6; font-size:11.5px; }
.permission-table td { height:33px; padding:4px 9px; font-size:12.5px; }
.permission-table th:nth-child(2), .permission-table th:nth-child(3), .permission-table td:nth-child(2), .permission-table td:nth-child(3) { width:94px; text-align:center; }
.perm-checkbox { width:17px; height:17px; cursor:pointer; accent-color:var(--orange-deep); }
.inline-admin-form { display:flex; gap:7px; max-width:540px; }
.inline-admin-form input { flex:1; min-width:0; }
.category-row-form { display:grid; grid-template-columns:minmax(150px,1fr) 92px auto; gap:7px; align-items:center; }

@media (max-width: 900px) {
  .topbar { grid-template-columns:auto 1fr auto; height:58px; padding:0 8px; }
  .topbar-logo img { width:min(250px,38vw); }
  .app-labels { display:none; }
  .user-chip span:last-child { display:none; }
  .layout { min-height:calc(100vh - 58px); grid-template-columns:1fr; }
  .sidebar { border-right:0; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:3px; overflow-x:auto; padding:5px; }
  .tree-root { display:none; }
  .tree { display:flex; gap:3px; }
  .category { min-height:30px; padding:4px 9px; margin:0; }
  .admin-links { display:none; }
  .compact-main { padding:7px; }
  .compact-toolbar { grid-template-columns:1fr 34px; gap:6px; }
  .toolbar-title { grid-column:1 / -1; }
  .compact-search { grid-column:1; }
  .add-btn { grid-column:2; grid-row:2; }
  .credential-table { min-width:560px; }
  .user-cell { width:29%; }
  .url-cell { width:27%; }
  .interaction-hint { display:none; }
  .compact-form-grid { grid-template-columns:1fr; }
  .form-actions-full { grid-column:auto; }
  .admin-split { grid-template-columns:1fr; }
  .category-row-form { grid-template-columns:1fr; }
}

@media (max-width: 560px) {
  .topbar-logo { justify-self:start; margin-left:8px; }
  .topbar-logo img { width:170px; max-width:42vw; }
  .app-mark { min-width:40px; padding:0 7px; }
  .top-actions { gap:4px; }
  .btn-soft { padding:6px 8px; }
  .login-box { padding:22px 18px; }
}

.category.active .icon-folder { background:var(--orange-deep); border-color:var(--orange-deep); }
