:root {
  --bg: #f4f6f9;
  --bg-grad: radial-gradient(1200px 500px at 10% -10%, #dff5f1 0%, transparent 60%), radial-gradient(900px 400px at 110% 0%, #e3edf8 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --line: #e3e8ef;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0d9488;
  --accent-2: #0e7490;
  --accent-soft: #e6f6f4;
  --accent-text: #0f766e;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, .18);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --bg-grad: radial-gradient(1200px 500px at 10% -10%, rgba(20, 184, 166, .10) 0%, transparent 60%), radial-gradient(900px 400px at 110% 0%, rgba(14, 116, 144, .12) 0%, transparent 55%);
    --surface: #111a2c;
    --surface-2: #0f1727;
    --line: #1f2b40;
    --text: #e6edf6;
    --muted: #8b9ab0;
    --accent: #14b8a6;
    --accent-2: #0891b2;
    --accent-soft: rgba(20, 184, 166, .12);
    --accent-text: #5eead4;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
.muted { color: var(--muted); }
.noscript { padding: 2rem; text-align: center; }

/* botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 1px solid transparent; border-radius: 10px; padding: .6rem 1rem; cursor: pointer;
  font-weight: 600; font-size: .92rem; transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.soft { background: var(--accent-soft); color: var(--accent-text); }
.btn.soft:hover:not(:disabled) { border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; padding: .8rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  text-decoration: none; list-style: none; transition: background .15s, color .15s;
}
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.icon-btn.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.icon-btn.on { background: var(--accent-soft); color: var(--accent-text); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.copy-btn {
  display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--accent-text); cursor: pointer;
  box-shadow: var(--shadow); transition: all .15s;
}
.copy-btn svg { width: 22px; height: 22px; }
.copy-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.copy-btn.done { background: var(--accent); border-color: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input {
  width: 100%; padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 80px; line-height: 1.45; }
.lbl { display: block; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .5rem; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 2rem 1.6rem; box-shadow: var(--shadow-lg); display: grid; gap: .8rem; text-align: center;
}
.login-card h1 { margin: .2rem 0 0; font-size: 1.5rem; letter-spacing: -.02em; }
.login-card p { margin: 0 0 .6rem; }
.login-logo svg { width: 56px; height: 56px; stroke: none; }
.login-err { color: var(--danger); min-height: 1.3em; font-size: .9rem; margin: 0 !important; }

/* cabecera */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.5rem; padding-top: max(.75rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 750; font-size: 1.08rem; letter-spacing: -.01em; white-space: nowrap; }
.logo svg { width: 32px; height: 32px; stroke: none; display: block; }
.search-wrap { position: relative; flex: 1; max-width: 560px; margin: 0 auto; }
.search-ico { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); display: flex; }
.search-ico svg { width: 18px; height: 18px; }
.search {
  width: 100%; padding: .62rem .9rem .62rem 2.4rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.top-actions { display: flex; gap: .25rem; align-items: center; }
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; padding: .4rem; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
  display: grid;
}
.menu-pop button, .menu-pop a {
  text-align: left; background: none; border: 0; padding: .6rem .75rem; border-radius: 8px; cursor: pointer;
  color: var(--text); text-decoration: none; font-size: .93rem;
}
.menu-pop button:hover, .menu-pop a:hover { background: var(--surface-2); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: .3rem 0; }
.danger-text { color: var(--danger) !important; }

/* distribución */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1.5rem; max-width: 1180px; margin: 0 auto; padding: 1.5rem; }
.tabs { display: flex; flex-direction: column; gap: .25rem; position: sticky; top: 84px; align-self: start; }
.tab {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem; text-align: left;
  border: 1px solid transparent; background: transparent; padding: .65rem .85rem; border-radius: 11px; cursor: pointer;
  font-weight: 600; color: var(--muted); transition: all .15s;
}
.tab:hover { background: var(--surface); color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); border-color: var(--line); box-shadow: var(--shadow); }
.tab.active .count { background: var(--accent-soft); color: var(--accent-text); }
.tab.add { justify-content: flex-start; color: var(--accent-text); margin-top: .4rem; border: 1px dashed var(--line); }
.tab.add svg { width: 18px; height: 18px; }
.count { font-size: .75rem; font-weight: 700; padding: .05rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }

.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.cat-title { margin: 0; font-size: 1.6rem; letter-spacing: -.025em; overflow-wrap: anywhere; }
.cat-actions { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.cat-actions .btn { margin-right: .35rem; }

.fields { display: grid; gap: .6rem; }
.field {
  display: flex; align-items: center; gap: .75rem; padding: .85rem .85rem .85rem 1.1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  transition: border-color .15s;
}
.field:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.field-body { flex: 1; min-width: 0; }
.field-label { display: flex; align-items: center; gap: .5rem; font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .15rem; }
.field-value { font-size: 1.02rem; font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; max-height: 16em; overflow: auto; }
.field-value.blank { color: var(--muted); font-style: italic; font-weight: 400; }
.field-tools { display: flex; gap: .1rem; flex: none; opacity: .75; transition: opacity .15s; }
.field:hover .field-tools { opacity: 1; }
.chip { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: .72rem; padding: .05rem .5rem; border-radius: 99px; background: var(--accent-soft); color: var(--accent-text); }

.field-form { display: grid; gap: .6rem; padding: 1rem 1.1rem; background: var(--surface); border: 1.5px solid var(--accent); border-radius: var(--r); box-shadow: 0 0 0 4px var(--accent-soft); }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.add-field { margin-top: .8rem; width: 100%; padding: .85rem; background: transparent; border: 1.5px dashed var(--line); color: var(--accent-text); border-radius: var(--r); }
.add-field:hover { border-color: var(--accent); background: var(--accent-soft); }
.field-form + .add-field, .fields + .field-form { margin-top: .8rem; }
.empty, .empty-cat { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty { display: grid; gap: 1rem; justify-items: center; }

/* diálogos */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(2, 6, 23, .45); display: grid; place-items: center; padding: 16px; animation: fade .12s; }
.modal { width: 100%; max-width: 460px; max-height: 88vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 1.4rem; box-shadow: var(--shadow-lg); display: grid; gap: .8rem; }
.modal h2 { margin: 0; font-size: 1.15rem; }
.modal p { margin: 0; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .4rem; }
.manage { display: grid; gap: .3rem; }
.manage-row { display: flex; align-items: center; gap: .2rem; padding: .3rem .3rem .3rem .7rem; border: 1px solid var(--line); border-radius: 10px; }
.manage-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.manage-row .count { margin-right: .3rem; }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: .55rem 1.1rem; border-radius: 99px; font-weight: 600; font-size: .9rem;
  pointer-events: none; transition: all .2s; z-index: 60; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }

/* móvil y tableta */
@media (max-width: 820px) {
  .top { padding: .6rem 16px; gap: .6rem; flex-wrap: wrap; }
  .brand-name { font-size: 1rem; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .top-actions { margin-left: auto; }
  .hide-sm { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px 2rem; gap: .8rem; }
  .tabs {
    flex-direction: row; overflow-x: auto; position: sticky; top: 112px; z-index: 10; margin: 0 -16px; padding: .7rem 16px;
    background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; padding: .5rem .8rem; border-radius: 99px; border-color: var(--line); background: var(--surface); }
  .tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
  .tab.active .count { background: rgba(255, 255, 255, .18); color: inherit; }
  .tab.add { margin-top: 0; }
  .tab.add span { display: none; }
  .cat-title { font-size: 1.35rem; }
  .cat-actions .btn span { display: none; }
  .cat-actions .btn { padding: .55rem; width: 38px; height: 38px; margin-right: 0; }
  .field { padding: .7rem .55rem .7rem .85rem; gap: .35rem; }
  .field-value { font-size: 1rem; }
  .field-tools { gap: 0; opacity: 1; }
  .field-tools .icon-btn { width: 32px; height: 36px; }
  .field-tools .icon-btn svg { width: 18px; height: 18px; }
  .copy-btn { width: 44px; height: 44px; }
}
@media (max-width: 820px) and (hover: hover) { .cat-actions .btn span { display: inline; } .cat-actions .btn { width: auto; padding: .55rem .9rem; } }
