/* ==========================================================================
   GESTABOX-web — Minimalist Design System
   Inter typeface · mobile-first · light/dark parity
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Neutral scale (light) */
  --gray-0:  #ffffff;
  --gray-50: #fafafa;
  --gray-100:#f4f4f5;
  --gray-200:#e4e4e7;
  --gray-300:#d4d4d8;
  --gray-400:#a1a1aa;
  --gray-500:#71717a;
  --gray-600:#52525b;
  --gray-700:#3f3f46;
  --gray-800:#27272a;
  --gray-900:#18181b;
  --gray-950:#09090b;

  /* Brand & accents */
  --brand:        #1e293b;   /* slate-800 — sobrio, legal */
  --brand-soft:   #f1f5f9;
  --accent:       #2563eb;   /* blue-600 */
  --accent-hover: #1d4ed8;
  --accent-soft:  #eff6ff;

  --success:      #16a34a;
  --success-soft: #dcfce7;
  --warning:      #d97706;
  --warning-soft: #fef3c7;
  --danger:       #dc2626;
  --danger-soft:  #fee2e2;

  /* Semantic — light */
  --bg:           var(--gray-50);
  --bg-elevated:  var(--gray-0);
  --bg-muted:     var(--gray-100);
  --bg-hover:     var(--gray-100);

  --text:         var(--gray-900);
  --text-muted:   var(--gray-600);
  --text-subtle:  var(--gray-500);
  --text-on-accent: #ffffff;

  --border:       var(--gray-200);
  --border-strong:var(--gray-300);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10:40px;
  --space-12:48px;
  --space-16:64px;

  /* Radii */
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --fs-xs:  12px;
  --fs-sm:  13px;
  --fs-base:14px;
  --fs-md:  15px;
  --fs-lg:  17px;
  --fs-xl:  20px;
  --fs-2xl: 24px;
  --fs-3xl: 30px;

  --lh-tight: 1.25;
  --lh-normal:1.5;

  --transition: 150ms ease;
}

/* ---------- Dark theme ---------- */
:root[data-theme="dark"] {
  --bg:           var(--gray-950);
  --bg-elevated:  var(--gray-900);
  --bg-muted:     var(--gray-800);
  --bg-hover:     var(--gray-800);

  --text:         var(--gray-50);
  --text-muted:   var(--gray-400);
  --text-subtle:  var(--gray-500);

  --border:       var(--gray-800);
  --border-strong:var(--gray-700);

  --brand:        #e2e8f0;
  --brand-soft:   var(--gray-800);
  --accent:       #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft:  rgba(59,130,246,0.15);

  --success-soft: rgba(22,163,74,0.18);
  --warning-soft: rgba(217,119,6,0.18);
  --danger-soft:  rgba(220,38,38,0.18);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow:    0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5), 0 4px 10px rgba(0,0,0,0.3);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 600;
  line-height: var(--lh-tight);
  color: var(--text);
  letter-spacing: -0.01em;
}
p { margin: 0; color: var(--text-muted); }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
img, svg { display: block; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.hidden-panel { display: none; }
.active-panel { display: block; }

/* ---------- Theme-based logo swap ---------- */
.logo-light { display: block; }
.logo-dark  { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark  { display: block; }

/* ==========================================================================
   VIEWS
   ========================================================================== */
.view { display: none; }
.view.active { display: block; }

/* ==========================================================================
   LOGIN VIEW
   ========================================================================== */
#login-view.view.active {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--bg);
}
.login-container {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
}
.brand-header {
  display: flex;
  justify-content: center;
}
.login-logo {
  height: 48px;
  width: auto;
}

/* ==========================================================================
   CARDS
   ========================================================================== */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.glass-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); }
#login-view .card { width: 100%; padding: var(--space-8) var(--space-6); }
.card-header { margin-bottom: var(--space-6); text-align: center; }
.card-header h2 { font-size: var(--fs-xl); margin-bottom: var(--space-2); }
.card-header p { font-size: var(--fs-sm); color: var(--text-muted); }
.card-footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  text-align: center;
}
.card-footer p { font-size: var(--fs-xs); color: var(--text-subtle); }

/* ==========================================================================
   FORMS
   ========================================================================== */
.input-group { margin-bottom: var(--space-4); }
.input-group label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
  margin-bottom: var(--space-2);
}
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.input-wrapper input,
.input-wrapper select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

/* Native select + input-with-datalist: custom chevron */
select,
input[list] {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px 16px;
  padding-right: 36px;
  cursor: pointer;
}
input[list]:focus,
select:focus {
  cursor: text;
}
/* Hide default arrow for IE/Edge legacy */
select::-ms-expand { display: none; }
/* Hide datalist arrow indicator in Chromium (we use our chevron) */
input[list]::-webkit-calendar-picker-indicator {
  opacity: 0;
  position: absolute;
  right: 0;
  width: 36px;
  height: 100%;
  cursor: pointer;
}
.input-wrapper input { padding-left: 38px; padding-right: 12px; }
.input-wrapper input[type="password"] { padding-right: 40px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
.input-icon {
  position: absolute;
  left: 12px;
  display: flex;
  align-items: center;
  color: var(--text-subtle);
  pointer-events: none;
}
.input-action-btn {
  position: absolute;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-subtle);
  transition: background var(--transition), color var(--transition);
}
.input-action-btn:hover { background: var(--bg-hover); color: var(--text); }
.input-help-text { display: block; font-size: var(--fs-xs); color: var(--text-subtle); margin-top: var(--space-1); }

/* Checkbox */
.checkbox-container {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.checkbox-container input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}
.checkbox-container .checkmark { display: none; }
.form-actions-row { margin: var(--space-4) 0; }

/* Material-style floating label inputs */
.google-material-input {
  position: relative;
}
.google-material-input input,
.google-material-input textarea {
  padding-top: 18px;
  padding-bottom: 6px;
}
.google-material-input label {
  position: absolute;
  left: 12px;
  top: 14px;
  font-size: var(--fs-sm);
  color: var(--text-subtle);
  pointer-events: none;
  transition: var(--transition);
  background: transparent;
  padding: 0 2px;
}
.google-material-input input:focus + label,
.google-material-input input:not(:placeholder-shown) + label,
.google-material-input textarea:focus + label,
.google-material-input textarea:not(:placeholder-shown) + label {
  top: 2px;
  font-size: 10px;
  color: var(--accent);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 16px;
  font-size: var(--fs-sm);
  font-weight: 500;
  border-radius: var(--radius);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
  border: 1px solid transparent;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  width: 100%;
}
.btn-text {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }

.btn-danger-solid {
  background: var(--danger) !important;
  color: #fff !important;
  border-color: var(--danger) !important;
}
.btn-danger-solid:hover:not(:disabled) { filter: brightness(0.93); }

.btn-danger-outline {
  background: var(--bg-elevated);
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn-icon-only {
  width: 36px;
  height: 36px;
  padding: 0;
}
.btn-sm { padding: 6px 10px; font-size: var(--fs-xs); }
/* btn-sm con primary NO debe ocupar 100% del ancho — comportamiento inline */
.btn-sm.btn-primary,
.btn-sm.btn-secondary { width: auto; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ==========================================================================
   SPINNER
   ========================================================================== */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   ALERTS
   ========================================================================== */
.alert {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
}
.alert-icon { display: inline-flex; flex-shrink: 0; }
.alert-message { flex: 1; }
.alert-danger  { background: var(--danger-soft);  color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-success { background: var(--success-soft); color: var(--success); }

/* ==========================================================================
   DASHBOARD LAYOUT
   ========================================================================== */
.dashboard-layout {
  display: grid;
  grid-template-columns: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: var(--space-4);
  width: 260px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden;
}

/* Soporte premium para Sidebar colapsado */
.sidebar.collapsed {
  width: 72px;
  padding: var(--space-4) var(--space-2);
  align-items: center;
}

.sidebar.collapsed .sidebar-brand {
  display: none;
}

.sidebar.collapsed .sidebar-brand-collapsed {
  display: flex !important;
  justify-content: center;
  align-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 18px;
  margin-bottom: var(--space-6);
  border: 1px solid var(--accent);
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.15);
}

.sidebar.collapsed .sidebar-nav {
  align-items: center;
  width: 100%;
}

.sidebar.collapsed .nav-item {
  width: 44px;
  height: 44px;
  padding: 0;
  justify-content: center;
  border-radius: 8px;
}

.sidebar.collapsed .nav-item span:last-child {
  display: none;
}

.sidebar.collapsed .sidebar-footer {
  display: none;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-6);
}
.sidebar-logo { height: 32px; }
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.disabled { opacity: 0.4; pointer-events: none; }
.nav-icon { display: inline-flex; }

.sidebar-footer { margin-top: auto; }
.inactivity-widget {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  font-size: var(--fs-xs);
}
.widget-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
  color: var(--text);
  margin-bottom: var(--space-2);
}
.widget-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}
.widget-dot.active { background: var(--success); }
.widget-desc { font-size: var(--fs-xs); color: var(--text-subtle); margin-bottom: var(--space-1); }
.timer-display {
  font-size: var(--fs-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.progress-bar-container {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  margin-top: var(--space-2);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 1s linear;
}
.session-info {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.session-info-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
}

/* Main content */
.main-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.view-title {
  font-size: var(--fs-lg);
  font-weight: 600;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius);
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.user-name { font-size: var(--fs-sm); font-weight: 500; color: var(--text); }
.user-email { font-size: var(--fs-xs); color: var(--text-subtle); }

.panel-body {
  flex: 1;
  padding: var(--space-6);
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
}
/* Contenedor centrado en pantallas anchas — evita que los paneles se estiren */
.panel-body > .panel-section,
.panel-body > section,
.panel-body > .panel-content,
.panel-body > #expedientes-section,
.panel-body > #dashboard-section,
.panel-body > #clientes-section,
.panel-body > #usuarios-section,
.panel-body > #ajustes-section {
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.dashboard-panel { display: block; }
.dashboard-panel.hidden { display: none !important; }

/* ==========================================================================
   WELCOME BANNER & STATS
   ========================================================================== */
.welcome-banner {
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
}
.welcome-title { font-size: var(--fs-xl); margin-bottom: var(--space-2); }
.welcome-banner p { font-size: var(--fs-sm); }
.welcome-badge {
  background: var(--success-soft);
  color: var(--success);
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.stat-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
}
.stat-icon-wrapper {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon-wrapper.blue   { background: var(--accent-soft); color: var(--accent); }
.stat-icon-wrapper.gold   { background: var(--warning-soft); color: var(--warning); }
.stat-data { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { font-size: var(--fs-xs); color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: var(--fs-2xl); font-weight: 600; color: var(--text); }
.stat-trend { font-size: var(--fs-xs); }
.stat-trend.positive { color: var(--success); }
.stat-trend.neutral  { color: var(--text-subtle); }

.workspace-empty {
  padding: var(--space-10) var(--space-6);
  text-align: center;
}
.empty-icon {
  display: inline-flex;
  margin-bottom: var(--space-3);
  color: var(--text-subtle);
}
.workspace-empty h3 { font-size: var(--fs-lg); margin-bottom: var(--space-2); }
.workspace-empty p { font-size: var(--fs-sm); max-width: 480px; margin: 0 auto var(--space-4); }

/* ==========================================================================
   PANEL HEADER (Expedientes)
   ========================================================================== */
.panel-header-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.panel-header-text h3 { font-size: var(--fs-xl); margin-bottom: var(--space-1); }
.panel-header-text p { font-size: var(--fs-sm); }
.panel-title-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-1);
}
.panel-title-row h3 { margin-bottom: 0; }
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   EXPEDIENTES GRID (cards responsive)
   ========================================================================== */
.expedientes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.exp-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.exp-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.exp-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
}
.exp-card-title {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
  flex: 1;
}
.exp-card-ref {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
  line-height: var(--lh-tight);
  word-break: break-word;
}
.exp-card-code {
  font-size: var(--fs-xs);
  font-family: 'Courier New', Courier, monospace;
  font-weight: 500;
  color: var(--text-subtle);
  letter-spacing: 0.04em;
  align-self: flex-start;
}
.exp-card-title .badge { align-self: flex-start; }

.exp-card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.exp-card-body > div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: var(--space-3);
  align-items: baseline;
  min-width: 0;
}
.exp-card-body dt {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.exp-card-body dd {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text);
  word-break: break-word;
  min-width: 0;
}
.exp-card-sub { color: var(--text-muted); font-size: var(--fs-xs); }
.exp-card-money {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
/* Cliente principal */
.exp-card-client {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--bg-muted);
  border-radius: var(--radius);
}
.exp-card-client-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.exp-card-client-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.exp-card-client-label {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.exp-card-client-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exp-card-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
}

/* Zona de botones de acción */
.exp-card-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.exp-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: var(--space-2) 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.exp-action-btn svg { flex-shrink: 0; }
.exp-action-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.exp-card-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  color: var(--text-subtle);
}
.exp-card-meta svg { flex-shrink: 0; opacity: 0.7; }
.exp-card-meta-user { font-weight: 500; color: var(--text-muted); }
.exp-card .btn-eliminar-exp {
  color: var(--text-subtle);
  flex-shrink: 0;
}
.exp-card .btn-eliminar-exp:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* ==========================================================================
   TOOLBAR (búsqueda + filtros)
   ========================================================================== */
.table-toolbar {
  padding: var(--space-4) !important;
  margin-bottom: var(--space-4);
  display: flex !important;
  flex-direction: column;
  gap: var(--space-3) !important;
}
.search-box-wrapper { position: relative; }
.search-box-wrapper input {
  width: 100%;
  padding-left: 38px;
  padding-right: 160px; /* Espacio reservado para el badge de resultados */
}
.search-box-wrapper.has-badge input { padding-right: 160px; }
@media (max-width: 640px) {
  .search-box-wrapper input { padding-right: 90px; }
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}
.filtros-detallados-container {
  border-top: 1px solid var(--border);
  padding-top: var(--space-4);
  overflow: hidden;
  transition: max-height var(--transition);
}
.filtros-detallados-container.hidden {
  display: none;
}
.filtros-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}
.input-group-sm label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.input-modern-sm, .select-modern-sm {
  width: 100%;
  height: 34px;
  padding: 4px 8px;
  font-size: var(--fs-sm);
}

/* ==========================================================================
   TABLAS
   ========================================================================== */
.table-card {
  padding: 0 !important;
  overflow: hidden;
}
.table-responsive { overflow-x: auto; }
.google-data-table {
  width: 100%;
  font-size: var(--fs-sm);
}
.google-data-table thead th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.google-data-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}
.google-data-table tbody tr:last-child td { border-bottom: none; }
.google-data-table tbody tr:hover { background: var(--bg-hover); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--bg-muted);
  color: var(--text-muted);
}
/* Estados de expediente — TBESTADOEXPEDIENTE */
.badge-est-act { background: var(--success-soft);  color: var(--success); }           /* ACT — ACTIVO */
.badge-est-cer { background: var(--bg-muted);       color: var(--text-subtle); }       /* CER — CERRADO */
.badge-est-ina { background: var(--bg-muted);       color: var(--text-subtle); }       /* INA — INACTIVO */
.badge-est-pen { background: var(--warning-soft);   color: var(--warning); }           /* PEN — PENDIENTE DE FALLO */
.badge-est-pfa { background: #fff7ed;               color: #c2410c; }                  /* PFA — PENDIENTE FIJACION AUDIENCIA */
.badge-est-sob { background: #f5f3ff;               color: #6d28d9; }                  /* SOB — SOBRESEIDO */
:root[data-theme="dark"] .badge-est-pfa { background: rgba(194,65,12,0.18);  color: #fb923c; }
:root[data-theme="dark"] .badge-est-sob { background: rgba(109,40,217,0.18); color: #a78bfa; }


.search-empty-state {
  padding: var(--space-12) var(--space-4);
  text-align: center;
  color: var(--text-subtle);
}
.search-empty-state svg { margin: 0 auto var(--space-3); display: block; }
.search-empty-state p { font-size: var(--fs-sm); }

/* ==========================================================================
   OVERLAYS / MODALES
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  padding: var(--space-4);
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: var(--space-6);
  box-shadow: var(--shadow-lg);
}
.overlay-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-4);
  background: var(--warning-soft);
  color: var(--warning);
}

/* Cajón centralizado (Crear expediente) — override styles inline */
#cajon-crear-expediente .overlay-card {
  max-width: 720px !important;
  padding: 0 !important;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.cajon-header {
  padding: var(--space-5) var(--space-6) !important;
  border-bottom: 1px solid var(--border) !important;
  background: var(--bg-elevated) !important;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.cajon-header h4 { font-size: var(--fs-lg) !important; margin: 0 !important; }
.cajon-header p { font-size: var(--fs-sm) !important; margin: 4px 0 0 !important; color: var(--text-muted) !important; }
.cajon-btn-close {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-muted) !important;
  flex-shrink: 0;
}
.cajon-btn-close:hover { background: var(--bg-hover); color: var(--text) !important; }
.cajon-body-scroll {
  padding: var(--space-6) !important;
  overflow-y: auto;
  flex: 1;
}
.cajon-footer {
  padding: var(--space-4) var(--space-6) !important;
  border-top: 1px solid var(--border) !important;
  background: var(--bg-elevated) !important;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.form-row-double {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* Form sections (Crear Expediente) */
.form-section {
  padding-bottom: var(--space-5);
  margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
}
.form-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}
.form-section-header {
  margin-bottom: var(--space-4);
}
.form-section-header h5 {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px 0;
}
.form-section-header p {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  margin: 0;
}

/* Required marker */
.req {
  color: var(--danger);
  font-weight: 600;
  margin-left: 2px;
}

/* Footer buttons: not full width */
.cajon-footer .btn { width: auto; }

/* ==========================================================================
   WIZARD — Crear Expediente paso a paso
   ========================================================================== */
.cajon-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
}
#wizard-step-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin: 4px 0 0;
}

.wizard-stepper {
  list-style: none;
  margin: var(--space-5) 0 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.wizard-stepper .step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  position: relative;
  min-width: 0;
}
.wizard-stepper .step::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--border);
  margin-left: var(--space-2);
  transition: background var(--transition);
}
.wizard-stepper .step:last-child::after { display: none; }
.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-muted);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  flex-shrink: 0;
  border: 1px solid var(--border);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.step-label {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wizard-stepper .step.active .step-num {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}
.wizard-stepper .step.active .step-label { color: var(--text); }
.wizard-stepper .step.done .step-num {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.wizard-stepper .step.done::after { background: var(--accent); }
.wizard-stepper .step.done .step-label { color: var(--text); }

/* Wizard step container */
.wizard-step { display: none; }
.wizard-step.active {
  display: block;
  animation: fade-in 200ms ease-out;
}

/* Wizard footer layout */
.wizard-footer {
  justify-content: space-between !important;
}
.wizard-footer-actions {
  display: flex;
  gap: var(--space-2);
}

/* Ghost button (for Cancelar) */
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

/* ==========================================================================
   IMPLICADOS — Paso 3 del wizard
   ========================================================================== */
.implicado-form {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  background: var(--bg);
}
.implicado-tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  padding: 4px;
  background: var(--bg-muted);
  border-radius: var(--radius);
  width: fit-content;
}
.implicado-tab {
  padding: 6px 14px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.implicado-tab.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.implicado-mode { display: block; }
.implicado-mode.hidden { display: none; }

.implicados-lista-wrapper {
  margin-top: var(--space-4);
}
.implicados-lista-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.implicados-lista-header h6 {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
}
.implicados-lista {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.implicados-empty {
  font-size: var(--fs-sm);
  color: var(--text-subtle);
  font-style: italic;
  margin: 0;
  padding: var(--space-4);
  text-align: center;
  background: var(--bg-muted);
  border-radius: var(--radius);
}

.implicado-chip {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition);
}
.implicado-chip--etiqueta {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.implicado-chip-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}
.implicado-chip-top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.implicado-chip-name {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}
.implicado-chip-doc {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  margin-top: 1px;
}
.implicado-chip-nota {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-style: italic;
  margin-top: 3px;
  line-height: 1.4;
  word-break: break-word;
}
.implicado-chip-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
  flex-shrink: 0;
}
.implicado-chip-remove {
  width: 28px;
  height: 28px;
  color: var(--text-subtle);
}
.implicado-chip-remove:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* Badge etiqueta */
.imp-etiqueta-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Fila checkbox etiqueta */
.imp-etiqueta-row {
  margin: var(--space-2) 0 var(--space-3);
}
.imp-etiqueta-row .checkbox-container {
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.rev-implicados-lista {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}


/* Review (Paso 5: confirmación) */
.review-intro {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}
.review-intro strong { font-weight: 600; }

.review-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-4);
  background: var(--bg-elevated);
}
.review-group:last-child { margin-bottom: 0; }
.review-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.review-group-header h6 {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
}
.review-edit-btn {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--accent);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.review-edit-btn:hover { background: var(--accent-soft); }

.review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-5);
  margin: 0;
}
.review-grid > div { min-width: 0; }
.review-grid .review-full { grid-column: 1 / -1; }
.review-grid dt {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.review-grid dd {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text);
  word-break: break-word;
}
.review-long {
  white-space: pre-wrap;
  line-height: var(--lh-normal);
}

@media (max-width: 480px) {
  .review-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   SUCCESS SCREEN — Después de guardar expediente
   ========================================================================== */
.wizard-success {
  position: relative;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-6);
  min-height: 520px;
  overflow: hidden;
}
.success-content {
  text-align: center;
  max-width: 360px;
  width: 100%;
  position: relative;
  z-index: 2;
  animation: success-rise 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.success-content h3 {
  font-size: var(--fs-xl);
  font-weight: 600;
  margin: var(--space-4) 0 var(--space-2);
  color: var(--text);
}
.success-content p {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin: 0 0 var(--space-5);
}
.success-number {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.success-number-label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.success-number-value {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.success-content .btn { width: 100%; }

/* Animated checkmark */
.success-check {
  width: 88px;
  height: 88px;
  margin: 0 auto;
}
.success-check svg {
  width: 100%;
  height: 100%;
}
.success-check svg circle {
  stroke: var(--success);
  stroke-width: 2.5;
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  transform-origin: center;
  animation: check-circle 600ms cubic-bezier(0.65, 0, 0.45, 1) 100ms forwards;
}
.success-check svg path {
  stroke: var(--success);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 50;
  stroke-dashoffset: 50;
  animation: check-tick 350ms cubic-bezier(0.65, 0, 0.45, 1) 600ms forwards;
}
@keyframes check-circle { to { stroke-dashoffset: 0; } }
@keyframes check-tick   { to { stroke-dashoffset: 0; } }
@keyframes success-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Confetti — 12 pequeños cuadrados que caen */
.success-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}
.success-confetti span {
  position: absolute;
  top: -20px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall 2.4s ease-in forwards;
}
.success-confetti span:nth-child(1)  { left:  8%; background: var(--accent);  animation-delay: 0.30s; }
.success-confetti span:nth-child(2)  { left: 16%; background: var(--success); animation-delay: 0.55s; }
.success-confetti span:nth-child(3)  { left: 24%; background: var(--warning); animation-delay: 0.10s; }
.success-confetti span:nth-child(4)  { left: 32%; background: var(--accent);  animation-delay: 0.40s; }
.success-confetti span:nth-child(5)  { left: 40%; background: var(--success); animation-delay: 0.65s; }
.success-confetti span:nth-child(6)  { left: 48%; background: var(--danger);  animation-delay: 0.20s; }
.success-confetti span:nth-child(7)  { left: 56%; background: var(--accent);  animation-delay: 0.50s; }
.success-confetti span:nth-child(8)  { left: 64%; background: var(--warning); animation-delay: 0.15s; }
.success-confetti span:nth-child(9)  { left: 72%; background: var(--success); animation-delay: 0.35s; }
.success-confetti span:nth-child(10) { left: 80%; background: var(--accent);  animation-delay: 0.60s; }
.success-confetti span:nth-child(11) { left: 88%; background: var(--danger);  animation-delay: 0.25s; }
.success-confetti span:nth-child(12) { left: 94%; background: var(--success); animation-delay: 0.45s; }
@keyframes confetti-fall {
  0%   { opacity: 0; transform: translateY(-20px) rotate(0deg); }
  10%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(110vh) rotate(540deg); }
}

/* Mobile: stepper más compacto */
@media (max-width: 480px) {
  .wizard-stepper .step .step-label { display: none; }
  .wizard-stepper .step::after { margin-left: var(--space-1); }
  .wizard-footer { flex-direction: column-reverse; gap: var(--space-2); align-items: stretch; }
  .wizard-footer-actions { width: 100%; }
  .wizard-footer-actions .btn { flex: 1; }
}

/* Cajón lateral (Estado de expediente) */
.cajon-lateral-container {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
}
.cajon-lateral-container.hidden {
  display: none;
}
.cajon-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
.cajon-content {
  position: relative;
  width: 100%;
  max-width: 600px;
  height: 100%;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
/* ==========================================================================
   ESTADO EXPEDIENTE — modal centrado, vista detallada sin tabs
   ========================================================================== */
.estado-modal-container {
  position: relative;
  display: block;
  padding: 0;
  background: transparent;
}
/* Cuando el estado está visible dentro del panel-body, quitar padding del body
   para que la cabecera sticky toque el tope del scroll */
.panel-body:has(#cajon-estado-expediente:not(.hidden)) {
  padding: 0;
}
.estado-modal-container.hidden { display: none; }
.cajon-overlay { display: none !important; }
.estado-modal-content {
  position: relative;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  max-height: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: none;
  overflow: visible;
  animation: fade-in 200ms ease-out;
}
.estado-tabs {
  display: flex;
  gap: var(--space-1);
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 5;
}
/* Cabecera del estado también sticky */
.estado-modal-content > .cajon-header {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 6;
}
.estado-modal-content > .estado-tabs {
  top: 60px; /* debajo de la cabecera sticky */
}
/* Footer del estado: lo dejamos en flujo normal para que no tape contenido */
.estado-modal-content > .cajon-footer {
  position: sticky;
  bottom: 0;
  background: var(--bg-elevated);
  z-index: 5;
}
.estado-tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
}
.estado-tab:hover { color: var(--text); }
.estado-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.estado-detalle-body {
  flex: 1;
  overflow: visible;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.estado-seccion {
  display: block;
}
.estado-seccion-titulo {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
/* Cabecera mejorada del Estado del Expediente */
.estado-header-mejorado {
  padding: var(--space-5) var(--space-6) var(--space-4) !important;
}

/* CÓDIGO DEL EXPEDIENTE — Identificador oficial, MUY visible */
.estado-codigo-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 70%, #000 30%) 100%);
  color: #fff;
  padding: 8px 14px 8px 16px;
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
  position: relative;
  overflow: hidden;
}
.estado-codigo-badge::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: rgba(255,255,255,0.4);
}
.estado-codigo-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.85;
}
.estado-codigo-value {
  font-size: var(--fs-lg);
  font-weight: 700;
  font-family: 'Inter', monospace;
  font-feature-settings: 'tnum';
  letter-spacing: 0.05em;
  line-height: 1;
}
.estado-codigo-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.15);
  color: #fff;
  transition: background var(--transition);
  margin-left: var(--space-1);
}
.estado-codigo-copy:hover { background: rgba(255,255,255,0.28); }
.estado-codigo-copy.copied {
  background: var(--success);
  color: #fff;
}

.estado-subtitulo-texto {
  margin: 6px 0 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-weight: 500;
}

/* Referencia editable en cabecera del estado */
.estado-ref-view {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.estado-titulo-texto {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  line-height: var(--lh-tight);
  word-break: break-word;
}
.estado-ref-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  color: var(--text-subtle);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}
.cajon-header:hover .estado-ref-edit-btn,
.estado-ref-edit-btn:focus { opacity: 1; }
.estado-ref-edit-btn:hover { background: var(--bg-hover); color: var(--accent); }

.estado-ref-editor { display: flex; flex-direction: column; gap: var(--space-2); }
.estado-ref-input {
  font-size: var(--fs-lg);
  font-weight: 600;
  height: 38px;
  width: 100%;
}
.estado-ref-editor-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}
.estado-ref-editor-actions .btn { width: auto; }

/* KPIs del dashboard */
.estado-kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}
@media (min-width: 640px) {
  .estado-kpis { grid-template-columns: repeat(4, 1fr); }
}
.estado-kpi {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.estado-kpi-label {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.estado-kpi-value {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.estado-kpi-value.accent { color: var(--accent); }
.estado-kpi-badge { display: flex; align-items: center; min-height: 24px; }
.estado-kpi-editable { padding-bottom: var(--space-3); }

/* Valor demanda editable */
.estado-kpi-editable-valor { position: relative; }
.estado-kpi-valor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.estado-kpi-edit-btn {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-subtle);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}
.estado-kpi-editable-valor:hover .estado-kpi-edit-btn { opacity: 1; }
.estado-kpi-edit-btn:hover { background: var(--bg-hover); color: var(--accent); }
.estado-kpi-valor-editor {
  margin-top: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.estado-kpi-valor-editor input {
  height: 34px;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.estado-kpi-valor-actions {
  display: flex;
  gap: var(--space-1);
  justify-content: flex-end;
}
.estado-kpi-valor-actions .btn { width: auto; padding: 4px 10px; }

/* Input de motivo en el diálogo de confirmación */
.confirm-input-wrap {
  width: 100%;
  margin-bottom: var(--space-4);
  text-align: left;
}
.confirm-input-wrap label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}
.confirm-input-wrap textarea {
  width: 100%;
  resize: vertical;
  min-height: 80px;
}
.estado-eex-select {
  width: 100%;
  height: 32px;
  padding: 4px 28px 4px 8px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  background-color: var(--bg-elevated);
  margin-top: 2px;
}

/* Cliente Principal destacado */
/* ═══ Cliente Principal — BANDA COMPACTA en cabecera ═══ */
.estado-cliente-strip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: linear-gradient(90deg, var(--accent-soft) 0%, transparent 100%);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.estado-cliente-strip::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
}
.estado-cliente-strip .estado-cliente-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 65%, #000 35%) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-sm);
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 6px color-mix(in srgb, var(--accent) 35%, transparent);
}
.estado-cliente-info-strip {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.estado-cliente-line-1 {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 0;
}
.estado-cliente-mini-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  flex-shrink: 0;
}
.estado-cliente-strip .estado-cliente-name {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.estado-cliente-line-2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  flex-wrap: wrap;
}
.estado-cliente-strip .estado-cliente-doc-type {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
}
.estado-cliente-strip .estado-cliente-doc-type:empty { display: none; }
.estado-cliente-strip .estado-cliente-doc {
  font-family: 'Inter', monospace;
  font-feature-settings: 'tnum';
  color: var(--text-muted);
}
.estado-cliente-strip .estado-cliente-doc:empty { display: none; }
.estado-cliente-sep { color: var(--border-strong); }
.estado-cliente-contacto-inline {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}
.estado-cliente-contacto-inline a {
  color: var(--accent);
  text-decoration: none;
  font-size: var(--fs-xs);
  padding: 2px 0;
}
.estado-cliente-contacto-inline a:hover { text-decoration: underline; }
.estado-cliente-contacto-inline a + a::before { content: '·'; margin-right: 6px; color: var(--border-strong); }

.estado-cliente-btn-edit-strip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  flex-shrink: 0;
}
.estado-cliente-btn-edit-strip:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
@media (max-width: 640px) {
  .estado-cliente-strip { padding: var(--space-3) var(--space-4); }
  .estado-cliente-strip .estado-cliente-name { white-space: normal; }
  .estado-cliente-btn-edit-strip span { display: none; }
  .estado-cliente-btn-edit-strip { padding: 6px 8px; }
}

/* Variante MINI: dentro de la cabecera, debajo del N° Expediente */
.estado-cliente-strip-mini {
  margin-top: var(--space-3);
  padding: 6px 10px 6px 12px !important;
  gap: 8px !important;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, var(--accent-soft) 0%, transparent 70%);
}
.estado-cliente-strip-mini::before { width: 2px; border-radius: 8px 0 0 8px; }
.estado-cliente-strip-mini .estado-cliente-avatar {
  width: 28px; height: 28px; font-size: 11px; flex-shrink: 0;
}
.estado-cliente-strip-mini .estado-cliente-mini-label { font-size: 9.5px; letter-spacing: 0.06em; }
.estado-cliente-strip-mini .estado-cliente-name { font-size: 13px; font-weight: 600; }
.estado-cliente-strip-mini .estado-cliente-line-1 { gap: 6px; }
.estado-cliente-strip-mini .estado-cliente-line-2 { font-size: 11px; gap: 6px; margin-top: 1px; }
.estado-cliente-strip-mini .estado-cliente-doc-type { padding: 1px 5px; font-size: 9.5px; }
.estado-cliente-strip-mini .estado-cliente-btn-edit-strip { padding: 4px 6px; }
.estado-cliente-strip-mini .estado-cliente-btn-edit-strip span { display: none; }

/* ============================================
   CABECERA REDISEÑADA v2 — layout horizontal limpio
   ============================================ */
.estado-header-v2 {
  padding: var(--space-5) var(--space-6) var(--space-4) !important;
  gap: var(--space-3) !important;
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.estado-header-v2 .cajon-header-title {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* FILA 1: badge + chips alineados horizontalmente */
.estado-header-row1 {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
/* Botón Imprimir Etiqueta — al lado del código del expediente */
.estado-btn-imprimir-etiqueta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.estado-btn-imprimir-etiqueta:hover {
  background: var(--accent);
  color: var(--text-on-accent);
  transform: translateY(-1px);
}
.estado-btn-imprimir-etiqueta:disabled { opacity: 0.6; cursor: wait; }
@media (max-width: 640px) {
  .estado-btn-imprimir-etiqueta span { display: none; }
  .estado-btn-imprimir-etiqueta { padding: 6px 8px; }
}

.estado-chips-inline {
  margin: 0 !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.hdr-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.4;
  white-space: nowrap;
}
.hdr-chip-tipo {
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
/* FILA 2: título grande de referencia */
.estado-header-row2 {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 !important;
}
.estado-header-v2 .estado-titulo-texto {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.01em;
}
.estado-header-v2 .estado-ref-edit-btn {
  margin-top: 4px;
  opacity: 0.6;
  flex-shrink: 0;
}
.estado-header-v2 .estado-ref-edit-btn:hover { opacity: 1; }

/* FILA 3 (cliente-strip-mini) — ajuste margen */
.estado-header-v2 .estado-cliente-strip-mini {
  margin-top: 2px !important;
}

/* Botón cerrar alineado arriba a la derecha */
.estado-header-v2 .cajon-btn-close {
  margin-top: 2px;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .estado-header-v2 { padding: var(--space-4) var(--space-4) var(--space-3) !important; }
  .estado-header-v2 .estado-titulo-texto { font-size: 17px; }
  .estado-chips-inline { font-size: 10.5px !important; }
}

/* Editor inline del cliente en la banda */
.estado-cliente-strip .estado-cliente-editor {
  position: absolute;
  inset: 0;
  background: var(--bg-elevated);
  padding: var(--space-3) var(--space-6);
  z-index: 2;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* KPI grid: 5 columnas en desktop */
.estado-kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}
@media (min-width: 720px) {
  .estado-kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .estado-kpis { grid-template-columns: repeat(5, 1fr); }
}

/* ─── Cliente Principal — tarjeta de identidad enriquecida (legacy, no en uso ahora) ─── */
.estado-cliente-block {
  position: relative;
  background: linear-gradient(135deg, var(--accent-soft) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.estado-cliente-block::before {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.06;
  pointer-events: none;
}
.estado-cliente-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--bg-elevated);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--accent);
  margin-bottom: var(--space-3);
}
.estado-cliente-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.estado-cliente-btn-edit {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  z-index: 1;
}
.estado-cliente-btn-edit:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.estado-cliente-main {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.estado-cliente-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 60%, #000 40%) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-lg);
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.estado-cliente-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.estado-cliente-name {
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
  line-height: 1.2;
}
.estado-cliente-doc-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.estado-cliente-doc-type {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
}
.estado-cliente-doc-type:empty { display: none; }
.estado-cliente-doc {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-family: 'Inter', monospace;
  font-feature-settings: 'tnum';
}
.estado-cliente-doc:empty { display: none; }

/* Datos de contacto: teléfonos y email */
.estado-cliente-contacto {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed color-mix(in srgb, var(--accent) 25%, transparent);
}
.estado-cliente-contacto:empty {
  display: none;
}
.estado-cliente-contact-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  color: var(--text);
  background: var(--bg-elevated);
  padding: 5px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: all var(--transition);
}
.estado-cliente-contact-item:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.estado-cliente-contact-item svg {
  color: var(--accent);
  flex-shrink: 0;
}
.estado-cliente-editor {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--accent);
}
.estado-cliente-editor .input-group {
  margin: 0;
  flex: 1;
  min-width: 0;
  display: flex;
}
.estado-cliente-editor .input-group input {
  width: 100%;
  height: 36px;
}
.estado-cliente-editor .btn {
  height: 36px;
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}
@media (max-width: 480px) {
  .estado-cliente-editor { flex-wrap: wrap; }
  .estado-cliente-editor .input-group { flex: 1 0 100%; }
  .estado-cliente-editor .btn { flex: 1; }
}

/* Bloques agrupados */
.estado-card-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
}
.estado-block-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.estado-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.estado-block-edit-btn {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.estado-block-edit-btn:hover { background: var(--accent-soft); }
.estado-block-edit .input-group { margin-bottom: var(--space-3); }
.estado-block-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.estado-block-edit-actions .btn { width: auto; }
.estado-desc-texto {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: var(--lh-normal);
  white-space: pre-wrap;
}
.estado-desc-texto.is-clamped {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.estado-desc-toggle {
  margin-top: var(--space-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent);
  padding: 0;
}
.estado-desc-toggle:hover { text-decoration: underline; }
.estado-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (min-width: 640px) {
  .estado-meta-grid { grid-template-columns: repeat(3, 1fr); }
}
.estado-meta-grid label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.estado-meta-grid p {
  margin: 2px 0 0 0;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.estado-editar-form .input-group { margin-bottom: var(--space-4); }

/* Header de sección con acción */
.estado-seccion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

/* Formulario agregar implicado en estado */
.estado-add-implicado-form {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  background: var(--bg-muted);
  margin-bottom: var(--space-3);
}
.implicado-emode { display: block; }
.implicado-emode.hidden { display: none; }

/* ==========================================================================
   MODAL ETIQUETA DEL EXPEDIENTE (preview imprimible / PDF)
   ========================================================================== */
.etiqueta-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.etiqueta-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.etiqueta-modal-header h4 { font-size: var(--fs-md); font-weight: 600; margin: 0; }
.etiqueta-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
  background: var(--gray-300);
  display: flex;
  justify-content: center;
}
:root[data-theme="dark"] .etiqueta-modal-body { background: var(--gray-950); }

/* La hoja simula papel tamaño Carta (8.5" x 11") */
.etiqueta-hoja {
  background: #ffffff;
  color: #000;
  width: 100%;
  max-width: 612px;          /* 8.5in @ 72dpi */
  aspect-ratio: 8.5 / 11;    /* proporción carta; crece si el contenido excede */
  padding: 8% 7%;            /* márgenes de documento proporcionales */
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  font-family: Arial, Helvetica, sans-serif;
  flex-shrink: 0;
  overflow: hidden;
}
.etiqueta-hoja .et-marca { font-size: 22px; font-weight: 700; margin-bottom: 14px; color: #000; }
.etiqueta-hoja .et-num { font-size: 15px; margin-bottom: 10px; color: #000; }
.etiqueta-hoja .et-num-label { color: #444; }
.etiqueta-hoja .et-num-val { font-weight: 700; }
.etiqueta-hoja .et-line { font-size: 13px; margin-bottom: 4px; color: #222; }
.etiqueta-hoja .et-line-k { color: #555; }
.etiqueta-hoja .et-tribunal { font-size: 15px; font-weight: 600; text-decoration: underline; margin: 14px 0 12px; color: #000; }
.etiqueta-hoja .et-imp-row { display: flex; justify-content: space-between; gap: 20px; font-size: 15px; padding: 5px 0; color: #000; }
.etiqueta-hoja .et-imp-nombre { flex: 1; }
.etiqueta-hoja .et-imp-rol { white-space: nowrap; color: #222; }
.etiqueta-hoja .et-imp-empty { font-size: 13px; color: #888; font-style: italic; }
.etiqueta-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
}
.etiqueta-modal-footer .btn { width: auto; }

/* Stats bar de la pestaña Implicados */
.imp-stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-muted);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}
.imp-stats-count { display: flex; align-items: baseline; gap: var(--space-2); }
.imp-stats-num {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.imp-stats-label { font-size: var(--fs-sm); color: var(--text-muted); }

/* Party card (implicado asociado) — compacta */
.party-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}
.party-card:hover { border-color: var(--border-strong); }
.party-row-main {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
}
.party-quick-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
  margin-left: auto;
}
.party-etiqueta-toggle {
  cursor: pointer;
  height: 24px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-subtle);
  transition: background var(--transition), color var(--transition);
}
.party-etiqueta-toggle input[type="checkbox"] { display: none; }
.party-etiqueta-toggle:has(input:checked) { color: var(--accent); background: var(--accent-soft); }
.party-etiqueta-toggle:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }

/* Botón eliminar implicado — discreto, rojo en hover */
.party-remove-btn {
  height: 24px;
  width: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}
.party-remove-btn:hover {
  background: #fee2e2;
  border-color: #ef4444;
  color: #ef4444;
}
[data-theme="dark"] .party-remove-btn:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* Fila de rol + nota badge */
.party-rol-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  background: var(--bg-muted);
  min-height: 36px;
  flex-wrap: wrap;
}
.party-rol-badge-wrap { display: flex; align-items: center; }
.party-rol-badge {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition);
}
.party-rol-badge:hover { background: var(--bg-hover); color: var(--text); }
.party-rol-select {
  height: 28px;
  font-size: var(--fs-xs);
  padding: 2px 24px 2px 8px;
  max-width: 200px;
}
.party-nota-badge {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  font-style: italic;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 0;
}
.party-nota-badge:hover { color: var(--text); }
.party-nota-badge::before { content: '"'; }
.party-nota-badge::after  { content: '"'; }

/* Editor de nota (expandido) */
.party-nota-expanded {
  padding: var(--space-2) var(--space-3);
  border-top: 1px dashed var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.party-nota-input {
  flex: 1;
  height: 32px;
  font-size: var(--fs-xs);
  padding: 4px 10px;
}
.party-nota-save { flex-shrink: 0; width: auto; }
.party-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  flex-shrink: 0;
}
.party-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.party-name { font-size: var(--fs-sm); font-weight: 500; color: var(--text); word-break: break-word; }
.party-doc { font-size: var(--fs-xs); color: var(--text-subtle); }
.party-contact {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 1px;
}
.party-contact svg { flex-shrink: 0; }
.party-email-link {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.party-email-link:hover { text-decoration: underline; }
.party-remove {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  color: var(--text-subtle);
}
.party-remove:hover { color: var(--danger); background: var(--danger-soft); }

/* Fila de controles: rol + etiqueta */
.party-row-controls {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.party-field {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.party-field label {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.party-rol-select {
  width: 100%;
  height: 34px;
  padding: 4px 32px 4px 10px;
  font-size: var(--fs-sm);
}
.party-etiqueta-check {
  flex-shrink: 0;
  height: 34px;
  white-space: nowrap;
}

.tab-header {
  display: flex !important;
  background: var(--bg-muted) !important;
  border-bottom: 1px solid var(--border) !important;
  padding: 0 !important;
}
.tab-btn {
  flex: 1;
  padding: var(--space-3) !important;
  font-size: var(--fs-sm) !important;
  font-weight: 500 !important;
  color: var(--text-muted) !important;
  border: none !important;
  border-bottom: 2px solid transparent !important;
  background: none !important;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent) !important;
}

/* ==========================================================================
   TOAST
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 2000;
}
.toast, .google-toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  color: var(--text);
  min-width: 240px;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  animation: toast-in 200ms ease-out;
}
.toast.toast-success, .google-toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error,   .google-toast.toast-error   { border-left: 3px solid var(--danger); }
.toast.toast-warning, .google-toast.toast-warning { border-left: 3px solid var(--warning); }
.toast-content-wrapper { flex: 1; min-width: 0; }
.toast-btn-action {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 500;
  font-size: var(--fs-sm);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.toast-btn-action:hover { background: var(--accent-soft); }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

/* ==========================================================================
   LOADING OVERLAY
   ========================================================================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.loading-overlay.hidden { display: none; }
.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-8);
}
.loading-logo { height: 40px; }
.loading-spinner-container { padding: var(--space-2); }
.loading-ring {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-text { font-size: var(--fs-sm); font-weight: 500; color: var(--text); }
.loading-sub  { font-size: var(--fs-xs); color: var(--text-subtle); }

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
.animate-fade-in { animation: fade-in 200ms ease-out; }
.animate-scale-up { animation: scale-up 180ms ease-out; }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes scale-up {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   RESPONSIVE — mobile-first overrides
   ========================================================================== */
@media (max-width: 768px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 80%;
    max-width: 280px;
    transform: translateX(-100%);
    transition: transform var(--transition);
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.active-mobile { transform: translateX(0); }
  .topbar { padding: var(--space-3) var(--space-4); }
  .panel-body { padding: var(--space-4); }
  .welcome-banner { flex-direction: column; }
  .form-row-double { grid-template-columns: 1fr; }
  .user-meta { display: none; }
}

@media (max-width: 480px) {
  .panel-header-wrapper { flex-direction: column; align-items: stretch; }
  .panel-header-wrapper .btn { width: 100%; }
  .filtros-grid { grid-template-columns: 1fr; }
  .cajon-content { max-width: 100%; }
}

/* ==========================================================================
   CATALOG ADD BUTTON (form helper)
   ========================================================================== */
.btn-add-catalog {
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
}
.btn-add-catalog:hover { text-decoration: underline; }

/* ==========================================================================
   TIMELINE (Historial expediente)
   ========================================================================== */
.timeline-container {
  position: relative;
  padding-left: var(--space-6);
}
.timeline-container::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding-bottom: var(--space-4);
}
.timeline-marker {
  position: absolute;
  left: -22px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elevated);
}
.timeline-time { font-size: var(--fs-xs); color: var(--text-subtle); margin-bottom: 2px; }
.timeline-title { font-size: var(--fs-sm); font-weight: 500; color: var(--text); }
.timeline-desc { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }

/* ==========================================================================
   PAGINACIÓN PREMIUM
   ========================================================================== */
.paginacion-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-6);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
}

.paginacion-container.hidden {
  display: none !important;
}

.paginacion-info {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.paginacion-info span {
  font-weight: 600;
  color: var(--text);
}

.paginacion-derecha {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.paginacion-controles {
  display: flex;
  align-items: center;
  gap: 4px;
}

.paginacion-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.paginacion-btn:hover:not(:disabled) {
  background-color: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--accent);
}

.paginacion-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background-color: var(--bg-muted);
  color: var(--text-subtle);
}

.paginacion-numeros {
  display: flex;
  align-items: center;
  gap: 4px;
}

.paginacion-num-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.paginacion-num-btn:hover:not(.active) {
  background-color: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--accent);
}

.paginacion-num-btn.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.paginacion-num-btn.dots {
  border-color: transparent;
  background-color: transparent;
  cursor: default;
  color: var(--text-subtle);
  min-width: 24px;
  pointer-events: none;
}

.paginacion-selector-tamano {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.paginacion-select {
  height: 34px;
  padding: 4px 28px 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background-color: var(--bg-elevated);
  color: var(--text);
  font-size: var(--fs-sm);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
}

.paginacion-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* ---------- Badge de Resultados de Búsqueda Minimalista ---------- */
.search-results-badge {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  animation: fadeIn 200ms ease;
  white-space: nowrap;
  z-index: 10; /* Asegurar que se renderice encima de la caja de texto */
}

.search-results-badge.hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .search-results-badge {
    padding: 2px 7px;
    font-size: 10.5px;
  }
  .search-results-badge .badge-text-full { display: none; }
  .btn-toggle-filtros-compact .btn-toggle-filtros-label { display: none; }
  .btn-toggle-filtros-compact { padding: 8px 10px !important; }
}
.search-results-badge .badge-text-short { display: none; }
@media (max-width: 640px) {
  .search-results-badge .badge-text-short { display: inline; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-50%) scale(0.95); }
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}


