/* Chilo Legal — Design System CSS */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@500;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --teal: #00BCE4;
  --teal-light: #E6F4F6;
  --teal-hover: #33CAED;

  --bg: #F6F8F7;
  --card: #FFFFFF;
  --text: #1A2226;
  --text-secondary: #4A5A60;
  --text-muted: #6B7D85;
  --border: #D1DADD;

  --sidebar-bg: #0F171A;
  --sidebar-link: #D8DEDF;
  --sidebar-muted: #8FA3A8;
  --sidebar-hover: rgba(0, 188, 228, 0.10);

  --success: #047857;
  --success-bg: #D1FAE5;
  --warning: #B45309;
  --warning-bg: #FEF3C7;
  --error: #B91C1C;
  --error-bg: #FEE2E2;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.10);

  --font-body: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
}

.dark {
  color-scheme: dark;
  --bg: #0D1416;
  --card: #141E21;
  --text: #E8ECEC;
  --text-secondary: #A8B8BC;
  --text-muted: #789096;
  --border: #2A3A3E;
  --sidebar-bg: #080E10;
  --teal-light: rgba(0, 122, 140, 0.18);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, .display {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }

p { margin-bottom: 1rem; }

a { color: var(--teal); text-decoration: none; transition: color 150ms ease; }
a:hover { color: var(--teal-hover); text-decoration: underline; }
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

button, a, [role="button"], .clickable, summary, select { cursor: pointer; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.65rem 1.25rem; border-radius: var(--radius-md); font-weight: 500;
  border: 1px solid transparent; transition: all 150ms ease; font-family: var(--font-body);
  font-size: 0.95rem; line-height: 1.2;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-hover); color: #fff; text-decoration: none; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--teal); color: var(--teal); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--teal); background: var(--teal-light); text-decoration: none; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 500; line-height: 1.4;
}
.badge-vigente { background: var(--success-bg); color: var(--success); }
.badge-derogado { background: var(--error-bg); color: var(--error); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-trust { background: var(--teal-light); color: var(--teal); }

/* Empty state */
.empty-state {
  text-align: center; padding: 2.5rem 1.5rem;
}
.empty-state-icon {
  width: 56px; height: 56px; margin: 0 auto 1rem;
  color: var(--text-muted);
}
.empty-state h3 { margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-secondary); margin-bottom: 1.25rem; max-width: 400px; margin-left: auto; margin-right: auto; }

/* Trust bar */
.trust-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.75rem 1.25rem;
  padding: 0.5rem 1rem; font-size: 0.78rem; color: var(--text-muted);
  background: var(--card); border-bottom: 1px solid var(--border);
}
.trust-bar svg { width: 14px; height: 14px; }

/* Forms */
input, textarea, select {
  font-family: var(--font-body);
  padding: 0.65rem 0.9rem; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--card); color: var(--text); font-size: 0.95rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
option { background: var(--card); color: var(--text); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0,122,140,0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.35rem; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* Responsive type scale */
@media (min-width: 768px) {
  h1 { font-size: 2.5rem; }
  h2 { font-size: 1.75rem; }
}

@media (min-width: 1024px) {
  h1 { font-size: 3rem; }
}

/* Documento Vivo — Case context bar */
.escrito-case-context {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 0.75rem 1rem 0;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}
.case-context-main { flex: 1; min-width: 0; }
.case-context-title {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.35rem;
}
.case-context-title h2 {
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 600;
  color: var(--text); margin: 0;
}
.case-context-meta {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;
  font-size: 0.78rem; color: var(--text-secondary);
}
.case-context-meta span { display: inline-flex; align-items: center; gap: 0.3rem; }
.case-context-meta .key { color: var(--text-muted); font-weight: 500; }
.case-context-meta .val { color: var(--text); font-weight: 500; }
.case-context-parties {
  display: flex; flex-direction: column; gap: 0.3rem;
  min-width: 180px; max-width: 35%;
}
.case-context-parties .party {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.78rem; padding: 0.25rem 0.5rem;
  background: var(--bg); border-radius: var(--radius-md);
}
.case-context-parties .party-role {
  color: var(--text-muted); font-weight: 500; text-transform: uppercase; font-size: 0.65rem; letter-spacing: 0.04em;
}
.case-context-parties .party-name {
  color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.case-context-empty { color: var(--text-muted); font-style: italic; font-size: 0.75rem; }
@media (max-width: 768px) {
  .escrito-case-context { flex-direction: column; gap: 0.75rem; }
  .case-context-parties { max-width: 100%; width: 100%; }
}

/* Documento Vivo — Section cards + inline editor */
.documento-vivo-overlay-inline {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.documento-vivo-overlay-inline.visible { display: flex; }
.documento-vivo-modal {
  background: var(--card);
  border: none;
  border-radius: 0;
  width: 100%; max-width: none; max-height: none;
  display: flex; flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.documento-vivo-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); gap: 1rem;
}
.documento-vivo-header h2 { font-size: 1.25rem; margin: 0; }
.documento-vivo-header p { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--text-muted); }
.documento-vivo-actions { display: flex; align-items: center; gap: 0.6rem; }
.documento-vivo-close {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 1.5rem; cursor: pointer; line-height: 1; padding: 0.25rem;
}
.documento-vivo-close:hover { color: var(--text); }
.documento-vivo-body {
  flex: 1; overflow-y: auto; padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.documento-vivo-empty { color: var(--text-muted); text-align: center; padding: 2rem; }

.dv-section-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.dv-section-card.pending { opacity: 0.75; border-style: dashed; }
.dv-section-card.generated { border-left: 4px solid var(--teal); }
.dv-section-card.editing { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,188,228,0.1); }

.dv-section-header {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.6rem;
}
.dv-section-title {
  font-weight: 700; font-size: 0.92rem; color: var(--text);
  display: inline-flex; align-items: center; gap: 0.45rem;
}
.dv-section-badge {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.15rem 0.45rem; border-radius: 4px;
}
.dv-section-badge.pending { background: var(--warning-bg); color: var(--warning); }
.dv-section-badge.generated { background: rgba(5,150,105,0.12); color: var(--success); }

.dv-section-preview {
  font-size: 0.85rem; color: var(--text-secondary); line-height: 1.55;
  max-height: 140px; overflow: hidden; position: relative;
}
.dv-section-preview::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 36px;
  background: linear-gradient(transparent, var(--bg));
}
.dv-section-preview p:last-child { margin-bottom: 0; }

.dv-section-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.dv-section-actions button { font-size: 0.78rem; padding: 0.35rem 0.7rem; }

.dv-editor-toolbar {
  display: flex; gap: 0.35rem; margin-bottom: 0.5rem;
}
.dv-editor-toolbar button {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); width: 32px; height: 32px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
}
.dv-editor-toolbar button:hover { border-color: var(--teal); color: var(--teal); }
.dv-editor-textarea {
  width: 100%; min-height: 160px; max-height: 420px;
  font-family: var(--font-body); font-size: 0.9rem; line-height: 1.6;
  padding: 0.85rem; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--card); color: var(--text); resize: vertical;
}
.dv-editor-textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,188,228,0.1); }

.dv-preface-textarea {
  width: 100%; min-height: 180px; max-height: 520px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem; line-height: 1.5;
  padding: 0.85rem; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--card); color: var(--text); resize: vertical;
}
.dv-preface-textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,188,228,0.1); }

.dv-preface-summary {
  font-size: 0.88rem; line-height: 1.55; color: var(--text);
}
.dv-preface-summary .dv-preface-field {
  margin-bottom: 0.5rem;
}
.dv-preface-summary .dv-preface-label {
  font-weight: 600; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em;
}
.dv-preface-summary .dv-preface-value {
  margin-top: 0.15rem;
}
.dv-preface-summary .dv-preface-empty {
  color: var(--text-muted); font-style: italic;
}

.dv-title-editable {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  margin: -0.15rem -0.4rem;
  border-radius: var(--radius-sm);
  border: 1px dashed transparent;
  transition: border-color 150ms ease, background-color 150ms ease;
}
.dv-title-editable:hover {
  border-color: var(--border);
  background: var(--bg);
}
.dv-title-input {
  color: var(--text);
  background: var(--card);
}

.dv-analysis-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 0.5rem;
}
.dv-analysis-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.75rem;
}
.dv-analysis-header strong { font-size: 1rem; color: var(--text); }
.dv-analysis-section h4 {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin: 0 0 0.4rem;
}
.dv-analysis-section p, .dv-analysis-section ul { font-size: 0.85rem; line-height: 1.55; margin: 0; }
.dv-analysis-section ul { padding-left: 1.1rem; }
.dv-analysis-section li { margin-bottom: 0.35rem; }
.dv-analysis-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 0.75rem 0;
}
.dv-analysis-fortalezas { border-left: 3px solid var(--success); padding-left: 0.75rem; }
.dv-analysis-riesgos { border-left: 3px solid var(--warning); padding-left: 0.75rem; }
.dv-analysis-empty { text-align: center; padding: 1.5rem; }
.dv-analysis-empty p { font-size: 0.85rem; color: var(--text-muted); margin: 0.4rem 0 0.9rem; }
.dv-analysis-loading { text-align: center; color: var(--teal); padding: 1.5rem; font-size: 0.9rem; }
.dv-analysis-error { text-align: center; color: var(--error); padding: 1rem; font-size: 0.85rem; }
.dv-analysis-meta { font-size: 0.7rem; color: var(--text-muted); text-align: right; margin-top: 0.75rem; }

@media (max-width: 640px) {
  .documento-vivo-header { flex-direction: column; align-items: flex-start; }
}
