:root {
  color-scheme: light;
  --ink: #172321;
  --muted: #62706c;
  --paper: #f5f2eb;
  --surface: #fffdfa;
  --surface-2: #ebe8df;
  --line: #d9d6cc;
  --brand: #163f3b;
  --brand-2: #235e57;
  --accent: #c97b43;
  --danger: #9b3f3f;
  --warning: #9a671f;
  --success: #2f6b50;
  --shadow: 0 16px 40px rgba(19, 44, 43, .09);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.skip-link { position: fixed; left: 1rem; top: -4rem; z-index: 100; background: white; padding: .75rem 1rem; border-radius: 10px; }
.skip-link:focus { top: 1rem; }

.auth-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; }
.auth-hero { background: var(--brand); color: #fff; padding: clamp(2rem, 7vw, 7rem); display: flex; flex-direction: column; justify-content: space-between; }
.auth-hero h1 { font-family: Georgia, serif; font-size: clamp(3rem, 7vw, 6.5rem); line-height: .9; margin: 1rem 0; max-width: 10ch; }
.auth-hero p { max-width: 55ch; color: #dbe6e3; font-size: 1.08rem; }
.brand-mark { display: inline-flex; align-items: center; gap: .75rem; font-weight: 800; letter-spacing: .04em; }
.brand-icon { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.4); border-radius: 12px; }
.auth-panel { padding: clamp(2rem, 8vw, 7rem); display: grid; place-items: center; }
.auth-card { max-width: 460px; width: 100%; }
.auth-card h2 { font-size: 2rem; margin-bottom: .35rem; }

.field { display: grid; gap: .45rem; margin: 1rem 0; }
.field label { font-weight: 720; font-size: .9rem; }
.field input, .field select, .field textarea, .search-input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: .8rem .9rem; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus, .search-input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(35,94,87,.14); }
.field textarea { min-height: 100px; resize: vertical; }
.field textarea.document-editor { min-height: 46vh; line-height: 1.65; font-family: Georgia, "Times New Roman", serif; font-size: 1.03rem; }
.document-excerpt { white-space: pre-line; color: var(--muted); }
.hint, .muted { color: var(--muted); }
.tiny { font-size: .78rem; }
.error { color: var(--danger); min-height: 1.4em; }

.button { border: 0; border-radius: 12px; padding: .75rem 1rem; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; font-weight: 750; background: var(--brand); color: white; }
.button:hover { background: var(--brand-2); }
.button.secondary { background: var(--surface-2); color: var(--ink); }
.button.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.button.danger { background: var(--danger); }
.button.small { padding: .48rem .7rem; font-size: .85rem; }
.button.full { width: 100%; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1rem; background: var(--brand); color: white; display: flex; flex-direction: column; gap: 1rem; }
.sidebar nav { display: grid; gap: .15rem; }
.nav-button { width: 100%; border: 0; background: transparent; color: #cbdad7; text-align: left; padding: .58rem .7rem; border-radius: 11px; display: flex; gap: .7rem; align-items: center; }
.nav-button:hover, .nav-button.active { color: white; background: rgba(255,255,255,.12); }
.nav-icon { width: 1.4rem; text-align: center; }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgba(255,255,255,.15); padding-top: 1rem; }
.profile { display: flex; gap: .7rem; align-items: center; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: #d8b18e; color: #392418; font-weight: 800; }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: 1rem clamp(1rem, 3vw, 2.5rem); background: rgba(245,242,235,.91); backdrop-filter: blur(16px); border-bottom: 1px solid rgba(217,214,204,.8); }
.global-search { max-width: 620px; flex: 1; position: relative; }
.search-results { position: absolute; top: calc(100% + .5rem); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); max-height: 360px; overflow: auto; padding: .4rem; }
.search-result { display: block; width: 100%; border: 0; background: transparent; text-align: left; padding: .7rem; border-radius: 9px; }
.search-result:hover { background: var(--surface-2); }
.content { padding: clamp(1.2rem, 3vw, 2.5rem); max-width: 1500px; margin: auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.eyebrow { text-transform: uppercase; font-size: .72rem; letter-spacing: .12em; color: var(--accent); font-weight: 850; }
.page-head h1 { font-family: Georgia, serif; font-size: clamp(2.2rem, 5vw, 4.2rem); line-height: 1; margin: .25rem 0 .5rem; }

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem; box-shadow: 0 2px 0 rgba(19,44,43,.02); }
.card.hero-card { background: var(--brand); color: white; padding: clamp(1.25rem, 3vw, 2rem); }
.hero-card .muted { color: #d5e2df; }
.card h2, .card h3 { margin-top: 0; }
.client-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 1rem; margin-top: 1rem; }
.client-card { display: flex; gap: 1rem; align-items: center; min-height: 150px; padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); text-align: left; box-shadow: 0 2px 0 rgba(19,44,43,.02); }
.client-card:hover { border-color: var(--brand-2); transform: translateY(-2px); box-shadow: var(--shadow); }
.client-card-body { min-width: 0; display: grid; gap: .35rem; }
.client-card-body strong { font-family: Georgia, serif; font-size: 1.45rem; }
.client-next { color: var(--brand-2); font-weight: 780; margin-top: .35rem; }
.client-avatar { --avatar-hue: 160; width: 72px; height: 72px; flex: 0 0 72px; display: grid; place-items: center; overflow: hidden; border-radius: 24px; background: hsl(var(--avatar-hue) 34% 78%); color: hsl(var(--avatar-hue) 45% 22%); font-size: 1.35rem; font-weight: 850; }
.client-avatar.large { width: 104px; height: 104px; flex-basis: 104px; border-radius: 32px; font-size: 2rem; }
.client-avatar img { width: 100%; height: 100%; object-fit: cover; }
.client-hero { display: flex; align-items: center; gap: 1.25rem; margin: 1rem 0 1.25rem; padding: 1.4rem; border-radius: 24px; background: var(--brand); color: white; }
.client-hero h1 { font-family: Georgia, serif; font-size: clamp(2rem, 4vw, 3.4rem); margin: .15rem 0; }
.client-hero p { margin: 0; color: #d5e2df; }
.client-hero-actions { margin-left: auto; display: flex; gap: .6rem; flex-wrap: wrap; }
.client-hero .button.ghost { color: white; border-color: rgba(255,255,255,.4); }
.folder-tools { position: sticky; top: 74px; z-index: 8; display: flex; gap: .5rem; overflow-x: auto; padding: .6rem; margin-bottom: 1rem; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); }
.folder-tools a { white-space: nowrap; padding: .55rem .75rem; border-radius: 10px; color: var(--brand-2); text-decoration: none; font-weight: 760; }
.folder-tools a:hover { background: var(--surface-2); }
.portal-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .75rem; }
.portal-tile { display: grid; gap: .55rem; padding: .9rem; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.metric { font-size: 2rem; font-weight: 850; letter-spacing: -.04em; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 2rem 0 .8rem; }
.section-title h2 { margin: 0; }

.list { display: grid; gap: .65rem; }
.list-item { border: 1px solid var(--line); border-radius: 13px; padding: .85rem; display: grid; gap: .3rem; background: var(--surface); }
.list-item.compact { padding: .7rem; }
.item-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: .28rem .55rem; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 750; }
.badge.critica, .badge.alto, .badge.no_verificado { background: #f6dddd; color: #843333; }
.badge.alta, .badge.propuesto, .badge.PROTEGIDA { background: #f7e8cf; color: #805619; }
.badge.media, .badge.ASISTIDA { background: #e8e3f5; color: #51427d; }
.badge.verificado, .badge.confirmado, .badge.API { background: #dceee4; color: #286146; }
.badge.bloqueada { background: #efe2da; color: #75452e; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; display: inline-block; }

.tabs { display: flex; gap: .4rem; overflow-x: auto; margin-bottom: 1rem; padding-bottom: .2rem; }
.tab { white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; background: transparent; padding: .55rem .8rem; color: var(--muted); }
.tab.active { background: var(--brand); color: white; border-color: var(--brand); }
.timeline { border-left: 2px solid var(--line); margin-left: .65rem; padding-left: 1.2rem; display: grid; gap: 1rem; }
.timeline-item { position: relative; }
.timeline-item::before { content: ""; position: absolute; width: .75rem; height: .75rem; border-radius: 50%; background: var(--accent); left: -1.65rem; top: .25rem; box-shadow: 0 0 0 4px var(--paper); }
.reference { border-left: 3px solid var(--accent); padding: .55rem .75rem; background: #faf4ed; border-radius: 0 10px 10px 0; font-size: .88rem; }
.warning-box { padding: .85rem; background: #fff5df; border: 1px solid #ead3a5; border-radius: 12px; color: #68460d; }
.safe-box { padding: .85rem; background: #e9f4ee; border: 1px solid #bdd8c8; border-radius: 12px; color: #24563e; }
.empty { padding: 2rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.document-preview { display: block; max-width: 100%; max-height: 55vh; margin: auto; border-radius: 12px; }
.document-frame { width: 100%; height: 55vh; border: 1px solid var(--line); border-radius: 12px; background: white; }
.media-preview { padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-alt); }
.media-preview audio, .media-preview video { width: 100%; }
.relation-map { display: grid; gap: 1rem; }
.investigation-board { position: relative; display: grid; gap: 1rem; padding: 1.25rem; overflow: hidden; background: linear-gradient(145deg, color-mix(in srgb, var(--surface) 94%, #b68245), var(--surface)); border: 1px solid var(--line); border-radius: 18px; }
.investigation-thread { display: grid; grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr); align-items: center; gap: .75rem; }
.investigation-node { padding: .85rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); font-weight: 700; text-align: center; }
.thread-line { min-width: 90px; color: var(--accent); text-align: center; font-size: .78rem; font-weight: 800; }
.thread-line::after { content: ""; display: block; height: 2px; margin-top: .3rem; background: var(--accent); opacity: .7; }
@media (max-width: 640px) { .investigation-thread { grid-template-columns: 1fr; } .thread-line { min-width: 0; } }
.relation-row { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(100px, .6fr) minmax(140px, 1fr) minmax(220px, 1.2fr); align-items: center; gap: .75rem; padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.relation-node { padding: .8rem; border: 1px solid var(--line); border-radius: 999px; text-align: center; font-weight: 750; background: var(--surface-2); }
.relation-edge { text-align: center; color: var(--brand-2); font-size: 1.2rem; }
.relation-edge span { display: block; font-size: .72rem; color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10,22,21,.68); display: grid; place-items: center; padding: 1rem; }
.modal { width: min(680px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 20px; padding: 1.25rem; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.toast-region { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; display: grid; gap: .5rem; }
.toast { background: var(--brand); color: white; border-radius: 12px; padding: .8rem 1rem; box-shadow: var(--shadow); }
.mobile-nav { display: none; }

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --ink: #e9efed; --muted: #a7b3af; --paper: #101917; --surface: #172320; --surface-2: #22312d; --line: #34443f; --brand: #163f3b; }
  .topbar { background: rgba(16,25,23,.91); }
  .reference { background: #30271f; }
  .warning-box { background: #332a19; border-color: #62502c; color: #f1d79d; }
  .safe-box { background: #193126; border-color: #315a47; color: #b8ddc9; }
}

@media (max-width: 980px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-hero { min-height: 38vh; padding: 2rem; }
  .auth-hero h1 { font-size: 3.5rem; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding-bottom: 6rem; }
  .mobile-nav { position: fixed; z-index: 30; bottom: 0; left: 0; right: 0; height: 66px; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); }
  .mobile-nav .nav-button { justify-content: center; padding: .4rem; flex-direction: column; gap: .1rem; font-size: .68rem; color: var(--muted); border-radius: 0; }
  .mobile-nav .nav-button.active { background: transparent; color: var(--brand-2); }
}

@media (max-width: 720px) {
  .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
  .topbar { padding: .75rem; }
  .topbar .button span { display: none; }
  .page-head { display: grid; }
  .page-head h1 { font-size: 2.4rem; }
  .item-row { display: grid; }
  .relation-row { grid-template-columns: 1fr; }
  .relation-edge { transform: rotate(90deg); margin: .5rem; }
  .client-hero { align-items: flex-start; flex-wrap: wrap; }
  .client-hero-actions { width: 100%; margin-left: 0; }
  .client-hero-actions .button { flex: 1; }
  .folder-tools { top: 64px; }
}

@media print {
  .sidebar, .topbar, .mobile-nav, .button { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

:root.theme-dark {
  color-scheme: dark;
  --ink: #e9efed;
  --muted: #a7b3af;
  --paper: #101917;
  --surface: #172320;
  --surface-2: #22312d;
  --line: #34443f;
  --brand: #163f3b;
}

:root.theme-light {
  color-scheme: light;
  --ink: #172321;
  --muted: #62706c;
  --paper: #f5f2eb;
  --surface: #fffdfa;
  --surface-2: #ebe8df;
  --line: #d9d6cc;
  --brand: #163f3b;
}
