/* ==============================================================================
   VendlyPOS - Pad Universal de Firmas Digitales
   Estilos CSS Modernos y Responsivos (Mobile-First)
   ============================================================================== */

:root {
  --bg-main: #0b0f19;
  --bg-card: #151e2e;
  --bg-card-hover: #1b263b;
  --bg-input: #0f172a;
  --border-subtle: #1e293b;
  --border-strong: #334155;
  --border-focus: #3b82f6;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-glow: rgba(37, 99, 235, 0.25);

  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.3);

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);

  --canvas-bg: #ffffff;
  --canvas-stroke: #0f172a;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  font-size: 15px;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/* Layout General */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  max-width: 580px;
  margin: 0 auto;
  width: 100%;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 90px) 16px;
  position: relative;
}

/* Header */
.app-header {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.brand-icon {
  width: 20px;
  height: 20px;
  color: var(--primary);
  flex-shrink: 0;
}

.store-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 210px;
}

.type-badge {
  background: var(--primary-glow);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.transaction-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.meta-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

/* Sección Datos del Firmante */
.signee-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.flex-1 { flex: 1; min-width: 0; }
.flex-2 { flex: 2; min-width: 0; }

.form-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.form-input {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
}

/* Pad Container */
.pad-container {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.pad-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.pad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.6);
  border-bottom: 1px solid var(--border-subtle);
}

.pad-instruction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.instruction-icon {
  width: 14px;
  height: 14px;
  color: var(--primary);
  flex-shrink: 0;
}

.btn-text-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.btn-text-clear:hover, .btn-text-clear:active {
  color: var(--danger);
  background: var(--danger-bg);
}

.btn-icon-sm {
  width: 13px;
  height: 13px;
}

/* Canvas Wrapper */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 310px;
  background: var(--canvas-bg);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

#signature-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.canvas-guideline {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 46px;
  border-bottom: 1px dashed #cbd5e1;
  pointer-events: none;
  display: flex;
  justify-content: flex-end;
}

.guide-text {
  font-size: 0.7rem;
  color: #94a3b8;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 3px;
}

.canvas-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #cbd5e1;
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity 0.2s ease;
}

.canvas-watermark.hidden {
  opacity: 0;
  visibility: hidden;
}

.watermark-icon {
  width: 32px;
  height: 32px;
  stroke-width: 1.25;
}

.pad-footer {
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.4);
  border-top: 1px solid var(--border-subtle);
}

.legal-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
  text-align: center;
}

/* Footer / Action Bar */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(11, 15, 25, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  padding: 12px 16px calc(var(--safe-bottom) + 12px) 16px;
  display: flex;
  gap: 12px;
  max-width: 580px;
  margin: 0 auto;
  z-index: 50;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.btn-icon {
  width: 18px;
  height: 18px;
}

.btn-secondary {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover, .btn-secondary:active {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-primary {
  flex: 2;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:not(:disabled):hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-primary:not(:disabled):active {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: #1e293b;
  color: #64748b;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.6;
}

/* Modal de Éxito */
.modal-screen {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-screen.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 28px 22px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: modalEnter 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalEnter {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.success-icon-wrap {
  width: 68px;
  height: 68px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px auto;
}

.success-icon {
  width: 36px;
  height: 36px;
  color: var(--success);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.modal-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 20px;
}

.confirmation-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conf-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

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

.conf-value {
  color: var(--text-primary);
  font-weight: 600;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.success-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.06);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.notice-icon {
  width: 15px;
  height: 15px;
  color: var(--primary);
  flex-shrink: 0;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.loading-overlay.active {
  opacity: 1;
  visibility: visible;
}

.loading-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  min-width: 260px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-card h3 {
  font-size: 1rem;
  font-weight: 600;
}

.loading-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 90%;
  text-align: center;
}

.toast.active {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-error {
  background: #451a1a;
  border-color: #7f1d1d;
  color: #fca5a5;
}

.toast.toast-success {
  background: #064e3b;
  border-color: #065f46;
  color: #6ee7b7;
}

@media (min-width: 600px) {
  .app-layout {
    padding-top: 32px;
  }
  .canvas-wrapper {
    height: 360px;
  }
}
