/* ============================================================
   Sistema de diseno "papel + navy" (inspirado en LibroContratos)
   ============================================================ */
:root {
  /* Navy (acento) */
  --navy-900: #0b2042;
  --navy-800: #14315b;
  --navy-700: #1f4279;
  --navy-600: #2c5497;
  --navy-100: #dee6f1;
  --navy-050: #eef2f8;
  /* Papel (fondos) */
  --paper-100: #ffffff;
  --paper-200: #fbf8f2;
  --paper-300: #f2ede2;
  --paper-400: #e4ded1;
  --paper-500: #d8d2c4;
  /* Tinta (texto) */
  --ink-900: #0f1420;
  --ink-800: #1a1f2b;
  --ink-600: #4a5160;
  --ink-500: #6b7180;
  --ink-400: #8c92a0;
  /* Semanticos */
  --green-700: #1f6b4e; --green-500: #2e8b66; --green-100: #dcefe5;
  --amber-700: #8a5a12; --amber-500: #c8851f; --amber-100: #f7e8cb;
  --red-700: #8c2a2a;   --red-500: #b0413e;   --red-100: #f5dddc;

  --bg-page: var(--paper-200);
  --bg-surface: var(--paper-100);
  --accent: var(--navy-800);
  --accent-hover: var(--navy-700);
  --accent-press: var(--navy-900);
  --line-1: var(--paper-400);
  --line-2: var(--paper-500);

  --font-display: "Archivo", system-ui, -apple-system, sans-serif;
  --font-ui: "Inter Tight", system-ui, -apple-system, sans-serif;
  --font-doc: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --radius-sm: 4px; --radius-md: 6px; --radius-lg: 12px; --radius-pill: 999px;
  --shadow-1: 0 1px 2px #14315b0f, 0 4px 16px #14315b0a;
  --shadow-2: 0 8px 24px #14315b1a, 0 2px 6px #14315b0f;
}

* { box-sizing: border-box; }
body {
  font-family: var(--font-ui);
  margin: 0;
  background: var(--bg-page);
  color: var(--ink-800);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, .brand { font-family: var(--font-display); letter-spacing: -0.01em; color: var(--ink-900); }
a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar { background: var(--accent); color: #fff; padding: 0.8rem 1.5rem; box-shadow: var(--shadow-1); }
.topbar-inner {
  max-width: 1140px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; letter-spacing: 0.01em; display: inline-flex; align-items: center; }
.brand:hover { text-decoration: none; opacity: 0.92; }
.brand img { height: 34px; width: auto; display: block; }
.auth-logo { display: block; max-width: 220px; max-height: 96px; width: auto; margin: 0 auto 1.25rem; }
.user-nav { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; }
.user-name { color: #fff; opacity: 0.95; }
.badge {
  background: var(--amber-100); color: var(--amber-700);
  padding: 0.15rem 0.55rem; border-radius: var(--radius-pill);
  font-size: 0.72rem; font-weight: 600;
}
.link-button {
  background: transparent; border: none; color: inherit; cursor: pointer;
  text-decoration: underline; padding: 0; font: inherit;
}
.link-button.danger { color: var(--red-500); }
.topbar .link-button { color: #fff; opacity: 0.9; }
.topbar .link-button:hover { opacity: 1; }
.logout-form { margin: 0; }

.contrato-selector { margin: 0; display: flex; align-items: center; }
.contrato-selector select {
  background: var(--navy-700); color: #fff; border: 1px solid var(--navy-600);
  border-radius: var(--radius-md); padding: 0.35rem 0.6rem; font-size: 0.82rem;
  font-family: inherit; max-width: 22rem;
}
.contrato-selector select option { color: var(--ink-900); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Nav secundario (admin) ---------- */
.admin-nav {
  background: var(--navy-700); color: #fff; padding: 0.5rem 1.5rem;
  display: flex; gap: 1.4rem; justify-content: center; flex-wrap: wrap;
}
.admin-nav a { color: var(--navy-100); text-decoration: none; font-size: 0.86rem; font-weight: 500; }
.admin-nav a:hover { color: #fff; text-decoration: none; }
.admin-nav a.nav-disabled { color: #7d93b5; cursor: not-allowed; }
.admin-nav a.nav-disabled:hover { color: #7d93b5; }

/* ---------- Layout con menu lateral ---------- */
.app-shell { display: flex; align-items: flex-start; max-width: 1320px; margin: 0 auto; gap: 0; }
.container { flex: 1 1 auto; min-width: 0; margin: 1.75rem auto; padding: 0 1.5rem; max-width: 1080px; }
.app-shell > .container { margin: 1.75rem 0; }

.sidebar { flex: 0 0 224px; width: 224px; padding: 1.5rem 0.9rem; position: sticky; top: 0; }
.side-nav { display: flex; flex-direction: column; gap: 0.15rem; }
.side-link {
  display: flex; align-items: center; gap: 0.5rem; justify-content: space-between;
  padding: 0.5rem 0.75rem; border-radius: var(--radius-md);
  color: var(--ink-600); font-size: 0.9rem; font-weight: 500; text-decoration: none;
  border-left: 3px solid transparent;
}
.side-link:hover { background: var(--paper-300); color: var(--ink-900); text-decoration: none; }
.side-link.active {
  background: var(--navy-050); color: var(--navy-800); font-weight: 600;
  border-left-color: var(--accent);
}
.side-link.disabled { color: var(--ink-400); cursor: default; }
.side-link.disabled:hover { background: transparent; color: var(--ink-400); }
.side-soon {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--paper-400); color: var(--ink-500); padding: 0.05rem 0.4rem; border-radius: var(--radius-pill);
}
.side-group {
  margin: 1rem 0 0.3rem; padding: 0 0.75rem;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-400); font-family: var(--font-display);
}

/* Submenus desplegables (details/summary) */
.side-sub { display: block; }
.side-summary { cursor: pointer; list-style: none; }
.side-summary::-webkit-details-marker { display: none; }
.side-summary::after {
  content: '⌄'; font-size: 0.85rem; line-height: 1; color: var(--ink-400);
  transition: transform 0.15s ease;
}
.side-sub[open] > .side-summary::after { transform: rotate(180deg); }
.side-subnav { display: flex; flex-direction: column; gap: 0.1rem; margin: 0.1rem 0 0.25rem; }
.side-sublink {
  display: block; padding: 0.4rem 0.75rem 0.4rem 1.6rem; border-radius: var(--radius-md);
  color: var(--ink-500); font-size: 0.85rem; font-weight: 500; text-decoration: none;
  border-left: 3px solid transparent;
}
.side-sublink:hover { background: var(--paper-300); color: var(--ink-900); text-decoration: none; }
.side-sublink.active {
  background: var(--navy-050); color: var(--navy-800); font-weight: 600;
  border-left-color: var(--accent);
}

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { position: static; width: 100%; flex-basis: auto; padding: 0.75rem 1.5rem 0; }
  .side-nav { flex-direction: row; flex-wrap: wrap; gap: 0.3rem; }
  .side-link { border-left: none; padding: 0.4rem 0.7rem; }
  .side-link.active { border-left: none; }
  .side-group { width: 100%; margin-top: 0.5rem; }
  .app-shell > .container { margin: 1rem 0; }
}

.footer {
  text-align: center; color: var(--ink-400); padding: 2rem 0; font-size: 0.8rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
}
.footer-olisan { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; }
.footer-olisan img { height: 22px; width: auto; opacity: 0.9; }
.muted { color: var(--ink-500); }
.small { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }

.alert {
  padding: 0.75rem 1rem; border-radius: var(--radius-md); margin-bottom: 1rem;
  border: 1px solid transparent; font-size: 0.9rem;
}
.alert.error { background: var(--red-100); border-color: #e8b9b7; color: var(--red-700); }
.alert.success { background: var(--green-100); border-color: #aedcc6; color: var(--green-700); }
.alert.info { background: var(--navy-050); border-color: var(--navy-100); color: var(--navy-800); }
.alert.warn { background: var(--amber-100); border-color: #e6c48f; color: var(--amber-700); }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 1.25rem; gap: 1rem;
}
.page-header h1 { margin: 0; font-size: 1.75rem; }
.page-header-actions { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.breadcrumb { margin-top: 0.35rem; font-size: 0.85rem; color: var(--ink-500); display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.breadcrumb .sep { color: var(--ink-400); }
.breadcrumb .current { color: var(--ink-700); font-weight: 600; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; }
@media (max-width: 640px) { .form-grid-2 { grid-template-columns: 1fr; } }
.busqueda-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0; }
.busqueda-bar input[type="search"] { flex: 1 1 280px; min-width: 200px; }

/* ---------- Auth ---------- */
.auth-box {
  max-width: 420px; margin: 3.5rem auto; background: var(--bg-surface);
  padding: 2rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
  border: 1px solid var(--line-1);
}
.auth-box h1 { margin-top: 0; }
.auth-box label { display: block; margin-top: 1rem; font-weight: 500; }
.auth-box input {
  width: 100%; padding: 0.65rem 0.75rem; border: 1px solid var(--line-2);
  border-radius: var(--radius-md); font-size: 1rem; margin-top: 0.25rem; font-family: inherit;
}

/* ---------- Botones ---------- */
.btn {
  display: inline-block; padding: 0.55rem 1.1rem; border-radius: var(--radius-md);
  border: 1px solid var(--line-2); background: var(--bg-surface); color: var(--ink-800);
  font-size: 0.9rem; font-weight: 500; font-family: inherit; cursor: pointer; text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--paper-300); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--red-700); border-color: #e0b3b1; background: var(--red-100); }

/* ---------- Tablas ---------- */
.data-table {
  width: 100%; border-collapse: collapse; background: var(--bg-surface);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-1);
  border: 1px solid var(--line-1);
}
.data-table th, .data-table td {
  padding: 0.7rem 0.95rem; text-align: left; border-bottom: 1px solid var(--line-1); vertical-align: top;
}
.data-table th {
  background: var(--paper-300); font-size: 0.74rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-600);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #14315b08; }
.data-table .acciones { text-align: right; white-space: nowrap; }
.data-table .acciones a, .data-table .acciones .link-button { margin-left: 0.75rem; font-size: 0.88rem; }

/* ---------- Chips ---------- */
.chip {
  display: inline-block; padding: 0.12rem 0.6rem; border-radius: var(--radius-pill);
  font-size: 0.72rem; font-weight: 600; background: var(--paper-400); color: var(--ink-600);
}
.chip.ok { background: var(--green-100); color: var(--green-700); }
.chip.off { background: var(--red-100); color: var(--red-700); }
.chip.warn { background: var(--amber-100); color: var(--amber-700); }

.empty {
  background: var(--bg-surface); padding: 2.5rem; border-radius: var(--radius-lg);
  text-align: center; color: var(--ink-500); box-shadow: var(--shadow-1); border: 1px solid var(--line-1);
}

/* ---------- Formularios ---------- */
.form-card {
  background: var(--bg-surface); padding: 1.5rem; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); border: 1px solid var(--line-1); max-width: 640px;
  display: flex; flex-direction: column; gap: 1rem;
}
.form-card.wide { max-width: 900px; }
.form-card label {
  display: flex; flex-direction: column; font-weight: 500; font-size: 0.88rem; gap: 0.3rem;
}
.form-card label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; }
.form-card input[type=text],
.form-card input[type=email],
.form-card input[type=number],
.form-card input[type=date],
.form-card input[type=password],
.form-card input[type=file],
.form-card textarea,
.form-card select {
  padding: 0.55rem 0.7rem; border: 1px solid var(--line-2); border-radius: var(--radius-md);
  font-size: 0.92rem; font-family: inherit; background: #fff; color: var(--ink-800);
}
.form-card input:focus, .form-card textarea:focus, .form-card select:focus,
.auth-box input:focus {
  outline: none; border-color: var(--navy-600); box-shadow: 0 0 0 3px #2c549722;
}
.form-card textarea { resize: vertical; }
.form-card fieldset { border: 1px solid var(--line-1); border-radius: var(--radius-md); padding: 1rem 1.25rem; }
.form-card fieldset legend { font-weight: 600; padding: 0 0.4rem; font-family: var(--font-display); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.error-text { color: var(--red-700); font-size: 0.8rem; }
.field { display: block; margin: 0.75rem 0; }
.field-label { display: block; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.88rem; }

/* ---------- Tarjetas ---------- */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.card {
  background: var(--bg-surface); padding: 1.3rem; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); border: 1px solid var(--line-1); margin-bottom: 1rem;
}
.card h3 { margin: 0 0 0.85rem 0; font-size: 1.05rem; }
.card.placeholder { border: 1px dashed var(--line-2); background: var(--paper-200); text-align: center; }
dl.kv { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; font-size: 0.9rem; }
dl.kv dt { color: var(--ink-500); }
section.card h4 { margin-top: 1.2rem; margin-bottom: 0.5rem; font-size: 0.95rem; }

.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; margin-top: 1rem; }
.inline-form label { display: flex; flex-direction: column; font-size: 0.84rem; gap: 0.2rem; }
.inline-form select {
  padding: 0.45rem 0.6rem; border: 1px solid var(--line-2); border-radius: var(--radius-md);
  font-size: 0.9rem; min-width: 220px; font-family: inherit;
}
.inline-form.compact { gap: 0.3rem; margin-top: 0; }
.inline-form.compact select, .inline-form.compact input { padding: 0.3rem 0.5rem; font-size: 0.85rem; }

.error-box {
  background: var(--bg-surface); padding: 2rem; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); border: 1px solid var(--line-1);
}

.timeline { display: flex; flex-direction: column; gap: 1rem; }
.timeline-item {
  border-left: 3px solid var(--accent); background: var(--paper-200);
  padding: 0.8rem 1rem; border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.timeline-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.3rem; flex-wrap: wrap; }
.timeline-item p { margin: 0.3rem 0; }

.doc-list { list-style: none; padding: 0; margin: 0.4rem 0; display: flex; flex-wrap: wrap; gap: 0.8rem; }
.doc-list li { display: flex; align-items: center; gap: 0.4rem; }
.doc-row { background: var(--paper-200) !important; font-size: 0.88rem; }
.doc-row a { margin-right: 0.8rem; }

.actions-group { display: flex; gap: 0.5rem; }
.row-danger td { background: var(--red-100); }
.row-warn td { background: var(--amber-100); }
.ok-panel { background: var(--green-100); border-left: 3px solid var(--green-500); }

.radio-inline {
  display: inline-flex !important; align-items: center; gap: 0.4rem;
  margin-right: 1.5rem; font-weight: normal !important;
}

/* ---------- Calendario ---------- */
.cal-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.cal-nav { display: flex; align-items: center; gap: 0.5rem; }
.cal-nav h2 { margin: 0; min-width: 200px; text-align: center; font-size: 1.3rem; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; font-size: 0.75rem; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  background: var(--line-1); border: 1px solid var(--line-1); border-radius: var(--radius-lg); overflow: hidden;
}
.cal-header { background: var(--accent); color: #fff; padding: 0.5rem; text-align: center; font-weight: 600; font-size: 0.85rem; }
.cal-day { background: var(--bg-surface); min-height: 110px; padding: 0.4rem; display: flex; flex-direction: column; gap: 0.2rem; }
.cal-day-empty { background: var(--paper-200); }
.cal-day-today { background: var(--amber-100); }
.cal-day-num { font-weight: 600; font-size: 0.85rem; color: var(--ink-500); align-self: flex-end; }
.cal-day-today .cal-day-num { color: var(--amber-700); }
.cal-event {
  display: block; padding: 0.2rem 0.4rem; border-radius: var(--radius-sm);
  font-size: 0.72rem; color: #fff; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; border: 1px solid transparent;
}
.cal-event.inline { display: inline-block; font-size: 0.7rem; padding: 0.1rem 0.4rem; }
.cal-event:hover { filter: brightness(1.1); text-decoration: none; }
.cal-event strong { font-weight: 700; margin-right: 0.2rem; }
.cal-event.tipo-hito { background: var(--navy-600); }
.cal-event.tipo-garantia { background: var(--amber-500); }
.cal-event.tipo-contrato-inicio { background: var(--green-500); }
.cal-event.tipo-contrato-termino { background: var(--red-500); }
.cal-event.tipo-contrato-adj { background: #7c3aed; }
.cal-event.tipo-contrato-terreno { background: #0891b2; }
.cal-event.tipo-modificacion { background: var(--ink-500); }
.cal-list { list-style: none; padding: 0; margin: 0; }
.cal-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--paper-300); display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.cal-list li:last-child { border-bottom: none; }
.cal-list-fecha { min-width: 96px; font-weight: 600; color: var(--ink-800); }

/* ---------- Verificacion publica ---------- */
.verificacion { max-width: 640px; margin: 2.5rem auto; }
.verif-card { border: 1px solid var(--line-1); border-radius: var(--radius-lg); padding: 1.75rem; background: var(--bg-surface); box-shadow: var(--shadow-2); }
.verif-valida { border-top: 4px solid var(--green-500); }
.verif-invalida { border-top: 4px solid var(--red-500); }
.verif-estado { display: flex; align-items: flex-start; gap: 0.9rem; }
.verif-check {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  background: var(--green-500); color: #fff; font-size: 1.4rem; line-height: 40px; text-align: center; font-weight: 700;
}
.verif-card h1 { font-size: 1.4rem; margin: 0 0 0.2rem; }
.verif-card p { color: var(--ink-600); margin: 0.3rem 0; }
.verif-datos { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 1.25rem 0 0; font-size: 0.92rem; }
.verif-datos dt { font-weight: 600; color: var(--ink-600); }
.verif-datos dd { margin: 0; color: var(--ink-900); word-break: break-word; }
.verif-datos .verif-sep { margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px solid var(--paper-300); }
.verif-hash { font-family: var(--font-mono); font-size: 0.78rem; }
.verif-nota { margin-top: 1.1rem; font-size: 0.82rem; color: var(--ink-500); }
.verif-volver { text-align: center; margin-top: 1.25rem; }

/* ---------- Editor enriquecido (Quill) ---------- */
.quill-host { background: #fff; border-radius: var(--radius-md); }
.quill-host #quill-editor { min-height: 220px; font-size: 1rem; font-family: var(--font-doc); }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--line-2); }
.ql-container.ql-snow { border-bottom-left-radius: var(--radius-md); border-bottom-right-radius: var(--radius-md); }
.ql-toolbar.ql-snow { border-top-left-radius: var(--radius-md); border-top-right-radius: var(--radius-md); background: var(--paper-200); }
.quill-host .ql-editor img { max-width: 100%; height: auto; }

/* ---------- Asistente de redaccion por IA ---------- */
.quill-ia { margin-bottom: 0.5rem; }
.quill-ia-panel {
  margin-top: 0.5rem; padding: 0.75rem 0.9rem;
  border: 1px solid var(--line-2); border-radius: var(--radius-md); background: var(--paper-200);
}
.quill-ia-panel label { display: block; margin-bottom: 0.35rem; font-weight: 600; }
.quill-ia-panel textarea { width: 100%; font-family: inherit; font-size: 0.95rem; resize: vertical; }
.quill-ia-actions { display: flex; align-items: center; gap: 0.75rem; margin: 0.5rem 0 0.25rem; }
.quill-ia-status.error-text { color: var(--danger, #b91c1c); }

/* ---------- Cuerpo de comunicacion (documento) ---------- */
.com-cuerpo { line-height: 1.6; font-family: var(--font-doc); font-size: 1.02rem; color: var(--ink-900); }
.com-cuerpo img { max-width: 100%; height: auto; }
.com-cuerpo p { margin: 0 0 0.6rem; }
.com-cuerpo ul, .com-cuerpo ol { margin: 0 0 0.6rem 1.4rem; }

/* ---------- Visor de PDF firmado ---------- */
.pdf-visor-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.pdf-visor {
  width: 100%; height: 75vh; min-height: 480px; margin-top: 0.75rem;
  border: 1px solid var(--line-2); border-radius: var(--radius-md); background: var(--paper-200);
}
