:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --success: #15803d;
  --danger: #b91c1c;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  text-wrap: balance;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.desktop-only {
  display: none;
}

.mobile-only {
  display: inline-flex;
}

:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Login */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 26px;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28);
}

.login-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 999px;
  background: #dbeafe;
  color: var(--primary);
  margin-bottom: 12px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.45rem;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topbar-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-icon {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: #ffffff;
  font-size: 1.25rem;
  border-radius: 10px;
  cursor: pointer;
}

/* Main container */
.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 14px calc(96px + env(safe-area-inset-bottom));
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.responsive-2col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

/* Stats & Filter Chips */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-pill-amber {
  border-left: 4px solid #d97706;
}

.stat-pill-blue {
  border-left: 4px solid #2563eb;
}

.stat-num {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.search-wrap {
  margin-bottom: 10px;
}

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  min-height: 36px;
}

.filter-chip.active {
  background: var(--text);
  color: #ffffff;
  border-color: var(--text);
}

.cards-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.client-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-left: 4px solid #cbd5e1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.card-accent-Borrador  { border-left-color: #94a3b8; }
.card-accent-Pendiente { border-left-color: #d97706; }
.card-accent-Firmado   { border-left-color: #2563eb; }
.card-accent-Aceptado  { border-left-color: #16a34a; }
.card-accent-Rechazado { border-left-color: #dc2626; }
.card-accent-Cancelado { border-left-color: #6b7280; }
.card-accent-Caducado  { border-left-color: #ea580c; }
.card-accent-Archivado { border-left-color: #475569; }

.client-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}

.client-card:active {
  transform: scale(0.99);
}

.client-card-main {
  min-width: 0;
  flex: 1;
}

.client-card-title {
  font-size: 1.03rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 3px;
}

.client-card-sub {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 8px;
}

.client-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.client-card-date {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.client-card-price {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  background: #eff6ff;
  padding: 2px 8px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-Borrador  { background: #e2e8f0; color: #334155; }
.badge-Pendiente { background: #fef3c7; color: #b45309; }
.badge-Firmado   { background: #dbeafe; color: #1d4ed8; }
.badge-Aceptado  { background: #dcfce7; color: #15803d; }
.badge-Rechazado { background: #fee2e2; color: #b91c1c; }
.badge-Cancelado { background: #f3f4f6; color: #4b5563; }
.badge-Caducado  { background: #ffedd5; color: #c2410c; }
.badge-Archivado { background: #e2e8f0; color: #1e293b; }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 30;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 20px;
  box-shadow: 0 8px 20px rgba(29, 78, 216, 0.35);
  cursor: pointer;
}

/* Detail & Tabs */
.detail-header-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.info-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.step-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 14px;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
}

.step-tab {
  border: 0;
  background: transparent;
  color: #334155;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 40px;
  padding: 8px 4px;
  border-radius: 9px;
  cursor: pointer;
}

.step-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

/* Forms & Sections */
.card-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
  box-shadow: var(--shadow);
}

.card-section legend,
.card-section h2,
.card-section h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 8px;
  padding: 0 4px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.88rem;
  font-weight: 500;
  color: #334155;
  margin-bottom: 10px;
}

input, select, textarea {
  width: 100%;
  font-size: 16px;
  font-family: inherit;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
}

input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-subtle);
  color: var(--muted);
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 44px;
}

.checkbox-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 0.98rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-full { width: 100%; }
.btn-lg { min-height: 52px; }
.btn-sm { min-height: 36px; padding: 4px 12px; font-size: 0.85rem; }

.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-success { background: var(--success); color: #ffffff; }
.btn-danger { background: var(--danger); color: #ffffff; }
.btn-danger-outline { background: #ffffff; color: var(--danger); border-color: var(--danger); }
.btn-ghost { background: transparent; color: var(--primary); }

.link-copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.link-copy-row input {
  font-size: 0.88rem;
  background: var(--surface-subtle);
}

/* History list */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.history-list li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.history-label {
  color: var(--muted);
}

.history-val {
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Contract preview */
.contract-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
  font-size: 0.94rem;
}

.contract-sheet-scroll {
  max-height: 62dvh;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: #ffffff;
}

.contract-sheet h2 {
  font-size: 1.08rem;
  text-align: center;
  margin: 0 0 8px;
}

.contract-place-date {
  text-align: right;
  color: var(--muted);
  margin-bottom: 14px;
}

.contract-block {
  margin-bottom: 12px;
}

.contract-block h4 {
  margin: 0 0 4px;
  font-size: 0.94rem;
}

.contract-block p {
  margin: 0 0 4px;
}

.contract-sigs-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.contract-sig-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  min-height: 90px;
}

.contract-sig-box img {
  max-width: 100%;
  max-height: 70px;
  object-fit: contain;
}

/* Signature Canvas */
.sig-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.sig-header-actions {
  display: flex;
  gap: 6px;
}

.sig-canvas {
  width: 100%;
  height: 170px;
  border: 1.5px dashed #94a3b8;
  border-radius: 12px;
  background: #ffffff;
  touch-action: none;
  display: block;
  cursor: crosshair;
}

/* Public Signing Page */
.sign-header {
  background: #0f172a;
  color: #ffffff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
}

.sign-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sign-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.sign-brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #3b82f6;
}

.sign-secure-pill {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.sign-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 14px calc(48px + env(safe-area-inset-bottom));
}

.center-box {
  max-width: 520px;
  margin: 36px auto;
  text-align: center;
  padding: 32px 22px;
}

.status-icon-ok {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: #dcfce7;
  color: var(--success);
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sign-workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.reader-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.form-error {
  color: var(--danger);
  background: #fee2e2;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 0;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 50;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.error {
  background: var(--danger);
}

.travel-calc-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.travel-calc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.travel-calc-head strong {
  display: block;
  font-size: 0.9rem;
}

.travel-calc-result {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.travel-calc-result p {
  margin: 0 0 8px;
  font-weight: 500;
}

.travel-calc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Tablet & Desktop Breakpoints */
@media (min-width: 768px) {
  .cards-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .responsive-2col {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 960px) {
  .cards-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .sign-workspace {
    grid-template-columns: 1.25fr 0.95fr;
  }

  .sign-form-card {
    position: sticky;
    top: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
