/* CRM Jurídico — tema claro profesional v8 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,600;8..60,700&display=swap');

:root {
  --crm-bg: #f0f2f6;
  --crm-surface: #ffffff;
  --crm-border: #dfe3ea;
  --crm-text: #0f1419;
  --crm-muted: #5c6570;
  --crm-accent: #1a365d;
  --crm-accent-hover: #234876;
  --crm-accent-soft: #e8eef5;
  --crm-accent-light: #f4f7fb;
  --crm-danger: #b42318;
  --crm-ok: #067647;
  --crm-warn: #b54708;
  --crm-font: 'Inter', system-ui, -apple-system, sans-serif;
  --crm-serif: 'Source Serif 4', Georgia, serif;
  --crm-radius: 14px;
  --crm-radius-sm: 10px;
  --crm-shadow: 0 1px 2px rgba(15, 20, 25, 0.04), 0 6px 20px rgba(15, 20, 25, 0.06);
  --crm-shadow-lg: 0 12px 40px rgba(15, 20, 25, 0.1);
  --crm-transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; min-height: 100%; background: var(--crm-bg); color: var(--crm-text); font-family: var(--crm-font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* —— Login —— */
.crm-login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(ellipse at 20% 0%, #fff 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, #dce4ef 0%, transparent 45%),
    linear-gradient(160deg, #fafbfc 0%, var(--crm-bg) 100%);
}
.crm-login-card {
  width: min(440px, 100%); background: var(--crm-surface); border: 1px solid var(--crm-border);
  border-radius: 20px; padding: 40px 36px; box-shadow: var(--crm-shadow-lg);
  animation: crmSlideUp 0.4s ease;
}
@keyframes crmSlideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.crm-login-brand { display: flex; gap: 16px; align-items: center; margin-bottom: 32px; }
.crm-login-brand h1 { margin: 0; font-family: var(--crm-serif); font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.crm-login-brand p { margin: 4px 0 0; color: var(--crm-muted); font-size: 14px; }
.crm-logo-mark {
  width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, #1a365d, #2c5282);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; font-family: var(--crm-serif);
  box-shadow: 0 6px 16px rgba(26, 54, 93, 0.3); flex-shrink: 0;
}
.crm-login-foot { margin-top: 24px; text-align: center; font-size: 13px; }
.crm-login-foot a { color: var(--crm-accent); text-decoration: none; font-weight: 500; transition: color var(--crm-transition); }
.crm-login-foot a:hover { color: var(--crm-accent-hover); text-decoration: underline; }

[hidden], .crm-is-hidden { display: none !important; }

/* —— Layout —— */
.crm-app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.crm-sidebar {
  background: var(--crm-surface); border-right: 1px solid var(--crm-border);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.crm-sidebar-brand {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px 22px;
  border-bottom: 1px solid var(--crm-border); margin-bottom: 16px;
}
.crm-sidebar-brand strong { display: block; font-size: 14px; font-weight: 700; }
.crm-sidebar-brand span { font-size: 10px; color: var(--crm-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.crm-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.crm-nav-item {
  border: none; background: transparent; text-align: left; padding: 11px 14px; border-radius: var(--crm-radius-sm);
  font: inherit; font-size: 14px; font-weight: 500; color: var(--crm-muted); cursor: pointer;
  display: flex; align-items: center; gap: 11px; transition: all var(--crm-transition); text-decoration: none;
}
.crm-nav-icon { opacity: 0.65; font-size: 16px; width: 20px; text-align: center; transition: opacity var(--crm-transition); }
.crm-nav-item:hover { background: var(--crm-accent-soft); color: var(--crm-text); transform: translateX(2px); }
.crm-nav-item:hover .crm-nav-icon { opacity: 1; }
.crm-nav-item.active {
  background: linear-gradient(135deg, #1a365d, #234876); color: #fff;
  box-shadow: 0 4px 14px rgba(26, 54, 93, 0.28);
}
.crm-nav-item.active .crm-nav-icon { opacity: 1; }
.crm-sidebar-foot {
  border-top: 1px solid var(--crm-border); padding-top: 16px; font-size: 12px; color: var(--crm-muted);
}
.crm-sidebar-foot span { display: block; margin-bottom: 8px; font-weight: 500; color: var(--crm-text); }

.crm-main { display: flex; flex-direction: column; min-width: 0; background: var(--crm-bg); }
.crm-topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 28px;
  background: rgba(255, 255, 255, 0.92); border-bottom: 1px solid var(--crm-border);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(10px);
}
.crm-search-wrap { flex: 1; }
.crm-search-wrap input {
  width: 100%; max-width: 520px; padding: 11px 16px 11px 40px; border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-sm); font: inherit; font-size: 14px;
  background: var(--crm-accent-light) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%235c6570' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") 14px center no-repeat;
  color: var(--crm-text); transition: all var(--crm-transition);
}
.crm-search-wrap input::placeholder { color: #9aa3ad; }
.crm-search-wrap input:focus { outline: none; border-color: var(--crm-accent); box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.12); background-color: #fff; }
.crm-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 7px 14px; border-radius: 999px; background: var(--crm-accent-soft); color: var(--crm-accent);
  border: 1px solid rgba(26, 54, 93, 0.1); white-space: nowrap;
}
.crm-content { padding: 28px 32px; overflow: auto; flex: 1; animation: crmFadeIn 0.15s ease; }
@keyframes crmFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.crm-page-header { margin-bottom: 24px; }
.crm-page-header h1 { margin: 0; font-family: var(--crm-serif); font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.crm-page-header p { margin: 8px 0 0; color: var(--crm-muted); font-size: 14px; max-width: 560px; }

/* —— Forms —— */
.crm-form label, .crm-modal-inner label {
  display: block; margin-bottom: 16px; font-size: 13px; font-weight: 600; color: var(--crm-muted);
}
.crm-form input, .crm-form select, .crm-form textarea,
.crm-modal-inner input, .crm-modal-inner select, .crm-modal-inner textarea {
  display: block; width: 100%; margin-top: 6px; padding: 11px 14px;
  border: 1px solid var(--crm-border); border-radius: var(--crm-radius-sm); font: inherit; font-size: 14px;
  background: #fff; color: var(--crm-text); transition: border-color var(--crm-transition), box-shadow var(--crm-transition);
}
.crm-form input:focus, .crm-form select:focus, .crm-form textarea:focus,
.crm-modal-inner input:focus, .crm-modal-inner select:focus, .crm-modal-inner textarea:focus {
  outline: none; border-color: var(--crm-accent); box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.1);
}
.crm-form textarea, .crm-modal-inner textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.crm-form-section { margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--crm-border); }
.crm-form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.crm-form-section-title {
  font-family: var(--crm-serif); font-size: 13px; font-weight: 700; color: var(--crm-accent);
  margin: 0 0 14px; text-transform: uppercase; letter-spacing: 0.05em;
}

/* —— Buttons —— */
.crm-btn {
  border: 1px solid var(--crm-border); background: var(--crm-surface); color: var(--crm-text);
  padding: 10px 18px; border-radius: var(--crm-radius-sm); font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: all var(--crm-transition); white-space: nowrap;
}
.crm-btn:hover { border-color: #c5cad3; background: #fafbfc; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(15, 20, 25, 0.06); }
.crm-btn:active { transform: translateY(0); box-shadow: none; }
.crm-btn-primary {
  background: linear-gradient(135deg, #1a365d, #234876); border-color: #1a365d; color: #fff;
  box-shadow: 0 2px 8px rgba(26, 54, 93, 0.2);
}
.crm-btn-primary:hover { filter: brightness(1.06); border-color: #1a365d; background: linear-gradient(135deg, #1a365d, #234876); color: #fff; }
.crm-btn-ghost { background: transparent; width: 100%; margin-top: 8px; border-color: transparent; }
.crm-btn-ghost:hover { background: var(--crm-accent-soft); border-color: transparent; }
.crm-btn:disabled { opacity: 0.55; cursor: wait; transform: none !important; box-shadow: none !important; }
.crm-btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.crm-btn-danger { background: #fef3f2; border-color: #fecdca; color: var(--crm-danger); }
.crm-btn-danger:hover { background: #fee4e2; border-color: #fca5a5; color: var(--crm-danger); }
.crm-btn-icon { padding: 8px 10px; min-width: 36px; }

.crm-error { color: var(--crm-danger); font-size: 13px; margin-top: 10px; font-weight: 500; }
.crm-error-card { background: #fef3f2; border: 1px solid #fecdca; color: var(--crm-danger); padding: 14px 16px; border-radius: var(--crm-radius); }

/* —— Toast —— */
.crm-toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  padding: 14px 20px; border-radius: var(--crm-radius-sm); font-size: 14px; font-weight: 500;
  box-shadow: var(--crm-shadow-lg); max-width: 380px; animation: crmToastIn 0.3s ease;
  border: 1px solid var(--crm-border); background: var(--crm-surface); color: var(--crm-text);
}
.crm-toast--ok { border-left: 4px solid var(--crm-ok); }
.crm-toast--err { border-left: 4px solid var(--crm-danger); }
.crm-toast--info { border-left: 4px solid var(--crm-accent); }
@keyframes crmToastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* —— KPIs —— */
.crm-kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.crm-kpi {
  background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius);
  padding: 20px 18px; box-shadow: var(--crm-shadow); border-left: 4px solid var(--crm-accent);
  transition: transform var(--crm-transition), box-shadow var(--crm-transition);
}
.crm-kpi:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(15, 20, 25, 0.09); }
.crm-kpi--urgente { border-left-color: var(--crm-danger); }
.crm-kpi--ok { border-left-color: var(--crm-ok); }
.crm-kpi--warn { border-left-color: var(--crm-warn); }
.crm-kpi-label { font-size: 11px; color: var(--crm-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.crm-kpi-value { font-size: 32px; font-weight: 700; font-family: var(--crm-serif); margin-top: 10px; line-height: 1; letter-spacing: -0.02em; }

/* —— Cards & tables —— */
.crm-card {
  background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius);
  padding: 22px; margin-bottom: 18px; box-shadow: var(--crm-shadow);
  transition: box-shadow var(--crm-transition);
}
.crm-card:hover { box-shadow: 0 4px 20px rgba(15, 20, 25, 0.07); }
.crm-card h2, .crm-card h3 { margin: 0 0 14px; font-family: var(--crm-serif); font-size: 1.12rem; font-weight: 700; }
.crm-card-accent { border-top: 3px solid var(--crm-accent); }

.crm-table-wrap { overflow-x: auto; border-radius: var(--crm-radius-sm); border: 1px solid var(--crm-border); }
.crm-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.crm-table th, .crm-table td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--crm-border); }
.crm-table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--crm-muted);
  background: #f8f9fb; font-weight: 700; white-space: nowrap;
}
.crm-table tbody tr { transition: background var(--crm-transition); }
.crm-table tbody tr:last-child td { border-bottom: none; }
.crm-table tbody tr:hover td { background: #f6f8fb; }
.crm-table .crm-link {
  color: var(--crm-accent); cursor: pointer; font-weight: 600; border: none; background: none;
  font: inherit; padding: 0; text-decoration: none;
}
.crm-table .crm-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.crm-empty { text-align: center; padding: 40px 20px; color: var(--crm-muted); }
.crm-empty-icon { font-size: 32px; margin-bottom: 8px; opacity: 0.4; }

/* —— Pills & chips —— */
.crm-pill { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: capitalize; letter-spacing: 0.02em; }
.crm-pill-urgente { background: #fee4e2; color: var(--crm-danger); }
.crm-pill-alta { background: #fff4e5; color: var(--crm-warn); }
.crm-pill-media { background: var(--crm-accent-soft); color: var(--crm-accent); }
.crm-pill-baja { background: #f0f0ee; color: var(--crm-muted); }
.crm-pill-cerrado { background: #e8f5ee; color: var(--crm-ok); }
.crm-pill-area { background: #eef2ff; color: #3730a3; }
.crm-chip {
  display: inline-block; padding: 7px 14px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--crm-border); color: var(--crm-muted); text-decoration: none;
  transition: all var(--crm-transition); background: #fff;
}
.crm-chip:hover { border-color: var(--crm-accent); color: var(--crm-accent); background: var(--crm-accent-soft); }
.crm-chip.active { background: var(--crm-accent); color: #fff; border-color: var(--crm-accent); box-shadow: 0 2px 8px rgba(26, 54, 93, 0.2); }
.crm-filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.crm-filters { align-items: center; gap: 16px; }
.crm-actions-cell { white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.crm-toolbar-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

.crm-input-block {
  width: 100%; margin-bottom: 10px; padding: 11px 14px; border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-sm); font: inherit; font-size: 14px; transition: border-color var(--crm-transition);
}
.crm-input-block:focus { outline: none; border-color: var(--crm-accent); box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.1); }
.crm-mt { display: block; margin-top: 14px; }
.crm-hint { font-size: 13px; color: var(--crm-muted); margin-bottom: 14px; }
.crm-modal-title { font-family: var(--crm-serif); margin: 0 0 20px; font-size: 1.35rem; font-weight: 700; }

.crm-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.crm-toolbar h2 { margin: 0; font-family: var(--crm-serif); font-size: 1.25rem; }

/* —— Timeline —— */
.crm-timeline { list-style: none; padding: 0; margin: 0; }
.crm-timeline li {
  padding: 12px 0 12px 20px; border-left: 2px solid var(--crm-border); margin-left: 10px;
  position: relative; font-size: 14px; line-height: 1.5;
}
.crm-timeline li::before {
  content: ''; position: absolute; left: -6px; top: 16px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--crm-accent); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--crm-border);
}
.crm-timeline time { font-size: 12px; color: var(--crm-muted); font-weight: 500; display: block; margin-bottom: 2px; }
.crm-timeline em { font-style: normal; font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--crm-accent); letter-spacing: 0.04em; }

/* —— Modal —— */
.crm-modal {
  border: none; border-radius: 18px; padding: 0; max-width: 560px;
  width: calc(100% - 32px); box-shadow: var(--crm-shadow-lg);
}
.crm-modal--wide { max-width: 760px; }
.crm-modal::backdrop { background: rgba(15, 20, 25, 0.5); backdrop-filter: blur(4px); animation: crmBackdropIn 0.2s ease; }
@keyframes crmBackdropIn { from { opacity: 0; } to { opacity: 1; } }
.crm-modal-inner { padding: 28px; margin: 0; max-height: 88vh; overflow-y: auto; }
.crm-modal-actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;
  position: sticky; bottom: 0; background: linear-gradient(to top, #fff 80%, transparent); padding-top: 16px;
}

.crm-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.crm-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.crm-row-alert { background: #fffbeb !important; }
.crm-row-alert td:first-child { font-weight: 600; color: var(--crm-warn); }

.crm-skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.crm-skeleton {
  height: 96px; border-radius: var(--crm-radius);
  background: linear-gradient(90deg, #eceef2 25%, #f5f6f8 50%, #eceef2 75%);
  background-size: 200% 100%; animation: crmShimmer 1.2s infinite;
}
.crm-skeleton-block {
  height: 220px; border-radius: var(--crm-radius);
  background: linear-gradient(90deg, #eceef2 25%, #f5f6f8 50%, #eceef2 75%);
  background-size: 200% 100%; animation: crmShimmer 1.2s infinite; margin-top: 16px;
}
@keyframes crmShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.crm-detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 24px; font-size: 14px; }
.crm-detail-grid dt { color: var(--crm-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin: 0; font-weight: 700; }
.crm-detail-grid dd { margin: 5px 0 14px; font-weight: 500; color: var(--crm-text); }

.crm-loading {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 48px 24px; color: var(--crm-muted); font-size: 14px;
}
.crm-spinner {
  width: 22px; height: 22px; border: 2px solid var(--crm-border);
  border-top-color: var(--crm-accent); border-radius: 50%;
  animation: crmSpin 0.65s linear infinite;
}
@keyframes crmSpin { to { transform: rotate(360deg); } }

.crm-fab {
  position: fixed; bottom: 28px; right: 28px; z-index: 100;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, #1a365d, #234876); color: #fff;
  font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 20px rgba(26, 54, 93, 0.35);
  transition: transform var(--crm-transition), box-shadow var(--crm-transition);
}
.crm-fab:hover { transform: scale(1.06); }

.crm-quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }

.crm-doc-upload { display: grid; gap: 12px; margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--crm-border); }
.crm-doc-upload label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--crm-muted); }
.crm-doc-upload input[type="text"],
.crm-doc-upload input[type="file"],
.crm-doc-upload select { font-weight: 400; color: var(--crm-text); }

.crm-doc-list { display: flex; flex-direction: column; gap: 10px; }
.crm-doc-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--crm-bg); border: 1px solid var(--crm-border); border-radius: var(--crm-radius-sm);
}
.crm-doc-icon { font-size: 1.5rem; flex-shrink: 0; }
.crm-doc-meta { flex: 1; min-width: 0; }
.crm-doc-name {
  display: block; font-weight: 600; color: var(--crm-accent); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.crm-doc-name:hover { text-decoration: underline; }
.crm-doc-sub { display: block; font-size: 12px; color: var(--crm-muted); margin-top: 2px; }
.crm-doc-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.crm-doc-empty { margin: 8px 0 0; }

.crm-case-hero {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 20px 22px; background: var(--crm-surface); border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius); margin-bottom: 18px; box-shadow: var(--crm-shadow);
}
.crm-case-hero h2 { margin: 0; font-family: var(--crm-serif); font-size: 1.4rem; }

@media (max-width: 900px) {
  .crm-app { grid-template-columns: 1fr; }
  .crm-sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .crm-nav { flex-direction: row; flex-wrap: wrap; }
  .crm-content { padding: 20px 16px; }
  .crm-grid-2, .crm-grid-3 { grid-template-columns: 1fr; }
  .crm-toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
  .crm-fab { bottom: 16px; right: 16px; }
}
