@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
@import "tailwindcss";

@theme {
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --color-bg: #F8FAFC;
  --color-sidebar-bg: #FFFFFF;
  --color-accent: #2563EB;
  --color-text-main: #1E293B;
  --color-text-muted: #64748B;
  --color-border: #E2E8F0;
  --color-card-bg: #FFFFFF;
}

@layer base {
  body {
    @apply bg-bg text-text-main antialiased;
    font-family: var(--font-sans);
  }
}

@layer components {
  .btn-accent {
    @apply bg-accent text-white px-5 py-2.5 rounded-lg font-semibold text-sm transition-all hover:opacity-90 active:scale-95;
  }
  
  .card-minimal {
    @apply bg-card-bg border border-border rounded-xl shadow-[0_1px_3px_rgba(0,0,0,0.05)] p-6;
  }
  
  .input-minimal {
    @apply w-full px-4 py-2.5 border border-border rounded-lg text-sm transition-colors focus:outline-hidden focus:border-accent;
  }

  /* Editor Styles */
  .editor-content-wrapper {
    @apply flex-1 overflow-auto flex justify-center min-w-fit bg-[#e2e8f0] p-6;
  }
  .editor-content {
    @apply w-[210mm] min-h-[297mm] h-auto bg-white p-[40px_48px] shadow-[0_2px_8px_rgba(0,0,0,0.15)] outline-hidden leading-relaxed text-text-main text-sm flex-shrink-0 overflow-visible relative;
  }
  .editor-content:focus { outline: none; }
  .editor-content p { margin: 0; padding: 4px 0; }
  .editor-content h1 { font-size: 22px; margin: 16px 0 12px; font-weight: 600; text-align: center; }
  .editor-content strong, .editor-content b { font-weight: 600; }
  .editor-content u { text-decoration: underline; }
  .editor-content table { 
    width: 100%; 
    border-collapse: collapse; 
    margin: 16px 0;
    table-layout: fixed;
  }
  .editor-content td { 
    padding: 8px; 
    border: 1px solid #e2e8f0;
    vertical-align: top;
  }
  .editor-content img { 
    max-width: 100%; 
    height: auto;
    display: block;
    margin: 8px auto;
  }

  .image-placeholder {
    @apply border-2 border-dashed border-[#cbd5e1] rounded-lg p-4 mb-2 bg-[#f8fafc] cursor-pointer min-h-[70px] flex flex-col items-center justify-center transition-all relative;
  }
  .image-placeholder:hover {
    @apply border-accent bg-[#f0f7ff];
  }
  .image-placeholder.has-image {
    @apply border-none bg-transparent p-0 min-h-0 cursor-default;
  }
  .image-placeholder .delete-btn {
    @apply absolute -top-2 -right-2 w-5 h-5 bg-red-500 text-white rounded-full items-center justify-center text-[10px] cursor-pointer z-10;
    display: none;
    pointer-events: auto;
  }
  .image-placeholder:hover .delete-btn {
    display: flex;
  }
  .image-placeholder .placeholder-text {
    color: #94a3b8;
    font-size: 11px;
    margin: 0;
    pointer-events: none;
  }
  .image-placeholder.has-image .placeholder-text {
    display: none !important;
  }
  .template-info-section {
    @apply relative mb-4;
  }

  .manual-frame-badge {
    @apply absolute top-1 left-1 px-1.5 py-0.5 bg-yellow-400 text-yellow-900 text-[9px] font-bold rounded shadow-sm pointer-events-none;
  }

  /* Smart Field Bindable Controls */
  .smart-field-wrapper {
    display: inline-flex;
    align-items: center;
    margin: 0 2px;
    vertical-align: text-bottom;
    white-space: nowrap;
  }
  .smart-field-wrapper .field-label {
    color: #64748b;
    user-select: none;
  }
  .smart-field-wrapper .field-value {
    min-width: 32px;
    padding: 0 4px;
    margin: 0 2px;
    border: 1px solid #cbd5e1;
    border-radius: 2px;
    display: inline-block;
    background: #f8fafc;
    color: #0f172a;
    line-height: 1.2;
    font-size: inherit;
    vertical-align: text-bottom;
    box-sizing: border-box;
    min-height: 1.2em;
    outline: none;
  }
  .smart-field-wrapper .field-value:empty::before {
    content: '\200b';
  }
  .smart-field-wrapper .field-value:focus {
    background-color: #e2e8f0;
    border-color: #94a3b8;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
  }
  .smart-field-wrapper .delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 16px;
    height: 16px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    display: none;
    z-index: 10;
  }
  .smart-field-wrapper .delete-btn:hover {
    background: #dc2626;
  }
  .template-editor-mode .smart-field-wrapper:hover .delete-btn,
  .template-editor-mode .smart-field-wrapper:focus-within .delete-btn {
    display: block;
  }
  .report-signature-img {
    max-width: 120px;
    max-height: 40px;
    width: auto;
    height: auto;
    object-fit: contain;
    vertical-align: middle;
    display: inline-block;
  }
}

@media print {
  @page { size: A4; margin: 0; }
  body * { visibility: hidden !important; }
  .print-content, .print-content * { visibility: visible !important; }
  .print-wrapper {
    position: static !important;
    display: flex !important;
    justify-content: center !important;
    overflow: visible !important;
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .print-content {
    position: static !important;
    width: 210mm !important;
    min-height: auto !important;
    height: auto !important;
    box-shadow: none !important;
    padding: 10mm !important;
    margin: 0 !important;
    overflow: visible !important;
    background: white !important;
  }
  .print-content .image-placeholder:not(.has-image) {
    display: none !important;
  }
  .print-content .smart-field-wrapper .field-value {
    border: none !important;
    border-bottom: 1px solid #000 !important;
    border-radius: 0 !important;
    background: transparent !important;
    padding: 0 2px !important;
  }
  .print-content .smart-field-wrapper .delete-btn {
    display: none !important;
  }
  .print-content .ai-region {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .print-content .ai-region > [contenteditable="false"] {
    display: none !important;
  }
  .report-signature-img {
    max-width: 120px !important;
    max-height: 40px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    vertical-align: middle !important;
    display: inline-block !important;
  }
}
