/**
 * VIBEBUY INVOICE AI — EDITOR REDESIGN v2.1
 */

/* Layout Split Panel */
#vibe-invoice-dashboard .editor-container {
  display: flex;
  flex-direction: row;
  width: 100%;
  /* Height is now managed by flex-1 from parent flex-col */
  background: linear-gradient(135deg, #f8f9fb 0%, #f0f2f5 100%);
  overflow: hidden;
}

/* Scrollbar Hide Utility */
.scrollbar-hide::-webkit-scrollbar {
  display: none;
}
.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Panels Layout */
.editor-form-panel {
  min-width: 300px;
  max-width: 800px;
  height: 100%;
  overflow-y: auto;
  padding: 1.25rem;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  z-index: 10;
  position: relative;
}

/* Resizer Handle */
.editor-resizer {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  z-index: 50;
  position: relative;
  transition: background 0.2s;
  margin-left: -3px;
  margin-right: -3px;
}

.editor-resizer:hover,
.editor-resizer.is-dragging {
  background: rgba(47, 114, 85, 0.4);
}

.editor-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: #e2e8f0;
  border-radius: 6px;
}

.editor-resizer:hover::after {
  background: #2F7255;
}

/* Right Panel: Preview */
.editor-preview-panel {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  background-color: #f1f5f9;
  background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
  background-size: 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* Form Cards */
.editor-zone-card {
  background: white;
  border-radius: 6px;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.04),
    0 1px 2px rgba(0, 0, 0, 0.02);
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid rgba(0, 0, 0, 0.03);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.editor-zone-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.zone-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #f8fafc;
}

.zone-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zone-title-text {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-bold);
  color: #374151;
  letter-spacing: var(--tracking-tight);
}

/* Form Controls */
.field-group {
  margin-bottom: 0.75rem;
}

.field-label {
  display: block;
  font-size: 0.625rem; /* ~10px */
  font-weight: var(--font-weight-semibold);
  color: #64748b;
  margin-bottom: 0.25rem;
}

.editor-input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  font-size: var(--text-xs);
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  transition: all 0.2s ease;
  color: #1f2937;
}

.editor-input:focus {
  outline: none;
  border-color: #2F7255;
  box-shadow: 0 0 0 3px rgba(47, 114, 85, 0.1);
}

.editor-input::placeholder {
  color: #9ca3af;
}

/* Item Rows */
.item-row {
  background: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  position: relative;
  transition: all 0.2s;
}

.item-row:hover {
  border-color: #e2e8f0;
  background: #f1f5f9;
}

/* PDF Paper Mockup */
.pdf-viewer-wrapper {
  margin: 2.5rem auto;
  padding: 0;
  background: white;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.05),
    0 20px 50px -10px rgba(0, 0, 0, 0.15),
    0 10px 20px -5px rgba(0, 0, 0, 0.1);
  transform-origin: top center;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  width: 794px;
  min-height: 1123px;
  border-radius: 6px;
  overflow: hidden;
}

/* A4 Canvas Frame — áp dụng cho cả trang đơn và multi-page */
#preview-frame,
.preview-frame-instance {
  width: 794px;
  height: 1123px;
  flex-shrink: 0;
  background: white;
  overflow: hidden;
}

/* Sticky Action Bar */
.preview-actions-bar {
  position: sticky;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(
    0
  ); /* Handled by flex parent usually, but here we want it centered */
  width: auto;
  max-width: 90%;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 0.75rem 1.25rem;
  border-radius: 6px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 100;
  margin-top: auto;
}

.btn-action-outline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.8125rem; /* ~13px */
  font-weight: var(--font-weight-semibold);
  color: #475569;
  background: white;
  transition: all 0.2s;
}

.btn-action-outline:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #1e293b;
}

.btn-action-primary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  background: linear-gradient(135deg, #599669 0%, #2F7255 100%);
  color: white;
  border-radius: 6px;
  font-size: 0.8125rem; /* ~13px */
  font-weight: var(--font-weight-bold);
  box-shadow: 0 4px 12px rgba(47, 114, 85, 0.25);
  transition: all 0.2s;
}

.btn-action-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(47, 114, 85, 0.35);
}

/* Totals styling */
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
}

.total-label {
  font-size: var(--text-xs);
  color: #64748b;
}

.total-value {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-bold);
  color: #1f2937;
}

.grand-total-row {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 2px dashed #e2e8f0;
}

.grand-total-label {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-black);
  color: #111827;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

/* ===== TEMPLATE SWITCHER POPUP ===== */
.tpl-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.tpl-popup-box {
  background: white;
  border-radius: 6px;
  width: 600px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.tpl-popup-header {
  margin-bottom: 20px;
}

.tpl-popup-title {
  font-size: var(--text-base);
  font-weight: var(--font-weight-bold);
  color: #1c3829;
  margin: 0 0 4px 0;
}

.tpl-popup-sub {
  font-size: var(--text-xs);
  color: #9a8a7a;
  margin: 0;
}

.tpl-popup-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

@media (max-width: 640px) {
  .tpl-popup-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.tpl-popup-item {
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid #e8e0d4;
  transition:
    border-color 0.15s,
    transform 0.1s;
  background: white;
}

.tpl-popup-item:hover {
  border-color: #1c3829;
  transform: scale(1.02);
}

.tpl-popup-item.is-selected {
  border-color: #2F7255;
  background: rgba(47, 114, 85, 0.05);
}

/* Thumbnail: scaled HTML preview */
.tpl-thumb-wrapper {
  width: 100%;
  aspect-ratio: 3/4;
  overflow: hidden;
  background: #f5f5f5;
  position: relative;
}

.tpl-thumb-scaler {
  /* Base scale for A4 (794px) to thumb width */
  transform-origin: top left;
  width: 794px; /* A4 width in px at 96dpi */
  height: 1123px; /* A4 height in px at 96dpi */
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  border: none;
}

.tpl-thumb-label {
  padding: 8px 10px;
  font-size: calc(var(--text-xs) * 0.95);
  font-weight: var(--font-weight-semibold);
  color: #1c3829;
  background: white;
  border-top: 1px solid #e8e0d4;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tpl-thumb-check {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: #2F7255;
  color: white;
  font-size: 0.625rem; /* ~10px */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tpl-popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid #e8e0d4;
}

.tpl-btn-cancel {
  padding: 8px 18px;
  border-radius: 6px;
  border: 1px solid #e8e0d4;
  background: white;
  color: #5a4a3a;
  font-size: 0.8125rem; /* ~13px */
  cursor: pointer;
  font-weight: var(--font-weight-semibold);
}

.tpl-btn-confirm {
  padding: 8px 22px;
  border-radius: 6px;
  border: none;
  background: #2F7255;
  color: white;
  font-size: 0.8125rem; /* ~13px */
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: all 0.2s;
}

.tpl-btn-confirm:hover:not(:disabled) {
  background: #599669;
}

.tpl-btn-confirm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- LUXURY SAAS OVERRIDES --- */
.custom-scrollbar::-webkit-scrollbar {
  width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 6px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

#vibe-invoice-dashboard #ghost-measure {
  width: 794px;
}
