/* ========================================================================
   Notarios.AI Design System Foundation
   Phase 23-01: Design tokens, global resets, component base styles
   ======================================================================== */

/* ========================================================================
   Section 1: CSS Custom Properties (Design Tokens)
   ======================================================================== */

:root {
  /* Brand Colors */
  --color-notarial-blue: #2563EB;
  --color-notarial-blue-dark: #1D4ED8;
  --color-midnight-navy: #1A2744;
  --color-twilight-navy: #24345A;
  --color-storm-navy: #243656;
  --color-ink-black: #0F172A;

  /* Surface Colors */
  --color-parchment-gray: #F8FAFC;
  --color-soft-ash: #F6F6F8;
  --color-white: #FFFFFF;
  --color-whisper-blue: #EBF5FF;

  /* Text Colors */
  --color-charcoal-slate: #1E293B;
  --color-dusk-gray: #64748B;
  --color-fog-gray: #94A3B8;

  /* Border Colors */
  --color-mist-edge: #E2E8F0;
  --color-slate-scroll: #CBD5E1;

  /* Typography */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-legal: 'Noto Serif', Georgia, serif;

  /* Shadows */
  --shadow-card: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-elevated: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06), 0 10px 15px -3px rgba(0,0,0,0.1);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-pill: 9999px;

  /* Layout */
  --sidebar-width-expanded: 240px;
  --sidebar-width-collapsed: 64px;
}

/* ========================================================================
   Section 2: Global Resets & Base Styles
   ======================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  background: var(--color-parchment-gray);
  color: var(--color-charcoal-slate);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ========================================================================
   Section 3: Custom Scrollbar
   ======================================================================== */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-slate-scroll);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-fog-gray);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-slate-scroll) transparent;
}

/* ========================================================================
   Section 4: Status Badges
   ======================================================================== */

.badge-borrador {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #FEF3C7;
  color: #92400E;
}

.badge-completado {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #D1FAE5;
  color: #065F46;
}

.badge-exportado {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #DBEAFE;
  color: #1E40AF;
}

.badge-activo {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #D1FAE5;
  color: #065F46;
}

.badge-inactivo {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #E5E7EB;
  color: #374151;
}

.badge-pendiente {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  border: 2px dashed #EF4444;
  color: #DC2626;
  background: transparent;
}

/* Legacy status badges (for compatibility) */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-draft {
  background: #FEF3C7;
  color: #92400E;
}

.status-completed {
  background: #D1FAE5;
  color: #065F46;
}

.status-approved {
  background: #D1FAE5;
  color: #065F46;
}

.status-exported {
  background: #DBEAFE;
  color: #1E40AF;
}

.status-unknown {
  background: #E5E7EB;
  color: #374151;
}

/* ========================================================================
   Section 5: Form System
   ======================================================================== */

/* --- Focus ring (standalone utility) --- */
.input-focus-ring:focus {
  outline: none;
  border-color: var(--color-notarial-blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* --- Form page wrapper --- */
.form-page {
  padding: 1.5rem;
  background: var(--color-parchment-gray);
}

/* --- Page title --- */
.page-title {
  font-size: 1.875rem;
  line-height: 2.25rem;
  font-weight: 700;
  color: var(--color-charcoal-slate);
  margin-bottom: 1.5rem;
}

/* --- Form card section --- */
.form-card {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
  padding: 1.5rem;
}

/* --- Section heading with icon --- */
.form-section-title {
  font-size: 1.25rem;
  line-height: 1.75rem;
  font-weight: 600;
  color: var(--color-charcoal-slate);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-section-icon {
  color: var(--color-notarial-blue);
}

/* --- Form label --- */
.form-label {
  display: block;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  color: var(--color-dusk-gray);
  margin-bottom: 0.5rem;
}

/* --- Form input --- */
.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-mist-edge);
  border-radius: var(--radius-lg);
  color: var(--color-charcoal-slate);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-notarial-blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-input::placeholder {
  color: var(--color-fog-gray);
}

.form-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --- Form field error text --- */
.form-error {
  color: #DC2626;
  font-size: 0.875rem;
  line-height: 1.25rem;
  margin-top: 0.25rem;
}

/* --- Form error banner --- */
.form-error-banner {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: #991B1B;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
}

/* --- Primary button --- */
.btn-primary {
  padding: 0.75rem 1.5rem;
  background: var(--color-notarial-blue);
  color: var(--color-white);
  border-radius: var(--radius-lg);
  font-weight: 500;
  transition: background-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary:hover {
  background: var(--color-notarial-blue-dark);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --- Secondary button --- */
.btn-secondary {
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--color-mist-edge);
  color: var(--color-charcoal-slate);
  border-radius: var(--radius-lg);
  font-weight: 500;
  background: var(--color-white);
  transition: background-color 0.15s;
}

.btn-secondary:hover {
  background: var(--color-parchment-gray);
}

.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --- Form helper text --- */
.form-helper {
  font-size: 0.875rem;
  color: var(--color-fog-gray);
  margin-top: 0.25rem;
}

/* --- Dropdown menu --- */
.form-dropdown {
  position: absolute;
  z-index: 20;
  width: 100%;
  margin-top: 0.25rem;
  background: var(--color-white);
  border: 1px solid var(--color-mist-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  max-height: 15rem;
  overflow: auto;
}

.form-dropdown-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background-color 0.15s;
  font-weight: 500;
  color: var(--color-charcoal-slate);
}

.form-dropdown-item:hover {
  background: var(--color-whisper-blue);
}

/* --- Segmented control --- */
.segmented-control {
  display: inline-flex;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-mist-edge);
  overflow: hidden;
}

.segmented-btn {
  padding: 0.625rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.15s, color 0.15s;
  background: var(--color-white);
  color: var(--color-charcoal-slate);
}

.segmented-btn:hover {
  background: var(--color-parchment-gray);
}

.segmented-btn.active {
  background: var(--color-notarial-blue);
  color: var(--color-white);
}

.segmented-btn + .segmented-btn {
  border-left: 1px solid var(--color-mist-edge);
}

/* --- Detail page label/value pairs --- */
.detail-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-dusk-gray);
}

.detail-value {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-charcoal-slate);
}

/* --- Link with primary color --- */
.link-primary {
  color: var(--color-notarial-blue);
  font-weight: 500;
  transition: color 0.15s;
}

.link-primary:hover {
  color: var(--color-notarial-blue-dark);
}

/* --- Danger button --- */
.btn-danger {
  padding: 0.5rem 1rem;
  background: #DC2626;
  color: var(--color-white);
  border-radius: var(--radius-lg);
  font-weight: 500;
  transition: background-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-danger:hover {
  background: #B91C1C;
}

.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Success button --- */
.btn-success {
  padding: 0.5rem 1rem;
  background: #16A34A;
  color: var(--color-white);
  border-radius: var(--radius-lg);
  font-weight: 500;
  transition: background-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-success:hover {
  background: #15803D;
}

.btn-success:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Small button variant --- */
.btn-primary-sm {
  padding: 0.375rem 0.75rem;
  background: var(--color-notarial-blue);
  color: var(--color-white);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.btn-primary-sm:hover {
  background: var(--color-notarial-blue-dark);
}

.btn-warning-sm {
  padding: 0.375rem 0.75rem;
  background: #D97706;
  color: var(--color-white);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.15s;
  cursor: pointer;
}

.btn-warning-sm:hover {
  background: #B45309;
}

/* --- Detail page header bar --- */
.detail-header {
  background: var(--color-white);
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
  border-bottom: 1px solid var(--color-mist-edge);
}

/* --- Muted text --- */
.text-muted {
  color: var(--color-fog-gray);
}

/* --- Table header cell --- */
.table-header {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-dusk-gray);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ========================================================================
   Section 6: Contract Preview (serif styling)
   ======================================================================== */

.contract-preview {
  font-family: var(--font-legal);
  font-size: 14px;
  line-height: 1.8;
  text-align: justify;
}

.contract-preview h1,
.contract-preview h2,
.contract-preview h3 {
  text-align: center;
  font-weight: bold;
  margin: 1.5rem 0 1rem 0;
}

.contract-preview p {
  margin-bottom: 1rem;
}

.contract-preview mark.unresolved {
  background: #FEF3C7;
  border: 2px solid #F59E0B;
  padding: 2px 4px;
  font-weight: bold;
  border-radius: 3px;
}

/* ========================================================================
   Section 7: Sidebar Transitions and Tooltips
   ======================================================================== */

.sidebar-transition {
  transition: width 200ms ease-in-out;
}

.sidebar-link-tooltip {
  position: relative;
}

.sidebar-link-tooltip:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  padding: 4px 8px;
  background: #1F2937;
  color: white;
  font-size: 0.75rem;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 100;
  pointer-events: none;
}

/* ========================================================================
   Section 8: Template Accordion
   ======================================================================== */

.accordion-item {
  border: 1px solid var(--color-mist-edge);
  border-radius: var(--radius-lg);
  margin-bottom: 0.75rem;
  overflow: hidden;
  background: var(--color-white);
}

.accordion-header {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  cursor: pointer;
  background: var(--color-parchment-gray);
  transition: background 0.2s;
  user-select: none;
}

.accordion-header:hover {
  background: var(--color-soft-ash);
}

.accordion-header .accordion-icon {
  margin-right: 0.75rem;
  transition: transform 0.2s;
  color: var(--color-dusk-gray);
  width: 1rem;
  text-align: center;
}

.accordion-header .accordion-icon.expanded {
  transform: rotate(90deg);
}

.accordion-header .client-name {
  font-weight: 600;
  color: var(--color-charcoal-slate);
  flex: 1;
}

.accordion-header .project-count {
  background: var(--color-whisper-blue);
  color: var(--color-notarial-blue-dark);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
}

.accordion-body {
  border-top: 1px solid var(--color-mist-edge);
  padding: 0;
}

.template-project {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-soft-ash);
}

.template-project:last-child {
  border-bottom: none;
}

.template-project-name {
  font-weight: 600;
  color: var(--color-charcoal-slate);
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.template-row {
  display: flex;
  align-items: center;
  padding: 0.5rem 0;
  gap: 0.75rem;
}

.template-row .domain-name {
  flex: 1;
  color: var(--color-dusk-gray);
  font-size: 0.875rem;
}

.template-row .filename {
  color: var(--color-fog-gray);
  font-size: 0.75rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-uploaded {
  background: #D1FAE5;
  color: #065F46;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-missing {
  background: var(--color-soft-ash);
  color: var(--color-dusk-gray);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
}

.btn-template-action {
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--color-mist-edge);
  background: var(--color-white);
  color: var(--color-charcoal-slate);
  transition: all 0.15s;
}

.btn-template-action:hover {
  background: var(--color-parchment-gray);
  border-color: var(--color-fog-gray);
}

.btn-template-action.upload {
  background: var(--color-notarial-blue);
  color: var(--color-white);
  border-color: var(--color-notarial-blue);
}

.btn-template-action.upload:hover {
  background: var(--color-notarial-blue-dark);
}

.btn-template-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.template-file-input {
  display: none;
}

/* ========================================================================
   Section 9: Login Gradient
   ======================================================================== */

.login-gradient {
  background: linear-gradient(135deg, var(--color-midnight-navy) 0%, var(--color-storm-navy) 100%);
}

/* ========================================================================
   Section 10: Chat Message Bubbles and Batch Progress
   ======================================================================== */

.batch-progress-bar {
  height: 4px;
  background: linear-gradient(90deg, var(--color-notarial-blue) 0%, #3B82F6 100%);
  border-radius: 2px;
  animation: progress-pulse 1.5s ease-in-out infinite;
}

@keyframes progress-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ========================================================================
   Section 11: Modal/Dialog Overlay
   ======================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-elevated);
}

/* ========================================================================
   Section 12: Password Toggle (still in use)
   ======================================================================== */

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-dusk-gray);
  cursor: pointer;
  padding: 4px;
}

.password-toggle:hover {
  color: var(--color-notarial-blue);
}

/* ========================================================================
   Section 13: Animations (still in use)
   ======================================================================== */

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-20px); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.animate-shake {
  animation: shake 0.5s ease-in-out;
}

/* ========================================================================
   Section 14: Wizard Lot Grid & Formula Badge (Phase 28-04)
   ======================================================================== */

.lot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(1.75rem, max-content));
  gap: 4px;
}

.lot-square-pendiente {
  background: #FCD34D;
}

.lot-square-revisado {
  background: #34D399;
}

.lot-square-actual {
  border: 2px solid #2563EB;
  box-shadow: 0 0 0 2px #2563EB;
}

.badge-formula {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-notarial-blue);
  background: var(--color-whisper-blue);
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
}
