/* =================================================================
   APPLICATION STYLES (SCREEN ONLY)
   For print styles, see print.css
   ================================================================= */

/* Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: #111;
  line-height: 1.5;
  background: #f5f5f5;
  height: 100%;
}

/* Header */
.app-header {
  background: #0f6cbd;
  color: white;
  padding: 1rem 2rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1800px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 40px;
  width: auto;
  border-radius: 6px;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
}

/* Footer */
.app-footer {
  background: transparent;
  color: rgba(0,0,0,0.25);
  text-align: center;
  padding: 0.6rem 2rem;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  user-select: none;
}

.app-footer a {
  color: rgba(0,0,0,0.3);
  font-weight: 600;
  text-decoration: none;
}

.app-footer a:hover {
  color: rgba(0,0,0,0.5);
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: #0f6cbd;
  color: white;
}

.btn-primary:hover {
  background: #0d5aab;
}

.btn-secondary {
  background: #666;
  color: white;
}

.btn-secondary:hover {
  background: #555;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.85rem;
}

.btn-danger {
  background: #d13438;
  color: white;
}

.btn-danger:hover {
  background: #b02c30;
}

/* Main Layout */
.app-container {
  display: grid;
  grid-template-columns: 380px 1fr;
  max-width: 1800px;
  margin: 0 auto;
  height: calc(100vh - 60px);
  gap: 0;
}

/* Form Sidebar */
.form-sidebar {
  background: white;
  border-right: 1px solid #ddd;
  overflow-y: auto;
  padding: 1.5rem;
}

.form-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #e5e5e5;
}

.form-section:last-child {
  border-bottom: none;
}

.form-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #0f6cbd;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: #333;
}

.form-control {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: #0f6cbd;
  box-shadow: 0 0 0 2px rgba(15, 108, 189, 0.1);
}

textarea.form-control {
  resize: vertical;
  font-family: inherit;
}

select.form-control {
  cursor: pointer;
}

/* Preview Area */
.preview-area {
  background: #f2f2f2;
  overflow-y: auto;
  padding: 20mm;
}

/* Template Styles (for screen display) */
.page {
  background: white;
  width: 210mm;
  min-height: 297mm;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  padding: 8mm 10mm;
  margin: 0 auto 10mm;
  position: relative;
}

.header {
  margin-bottom: 6mm;
  border-bottom: 2px solid #000;
  padding-bottom: 4mm;
}

.title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.subtitle {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-top: 2mm;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6mm;
}

.box {
  border: 1.5px solid #444;
  border-radius: 4px;
  padding: 4mm;
  min-height: 25mm;
  margin-bottom: 6mm;
}

.box h3 {
  margin: 0 0 2mm 0;
  font-size: 13.5px;
  font-weight: 700;
}

.label {
  font-size: 11.25px;
  color: #333;
  margin-top: 1.5mm;
}

.row {
  display: grid;
  grid-template-columns: 28mm 1fr;
  gap: 3mm;
  align-items: end;
  margin-top: 1.5mm;
}

.row .label {
  margin: 0;
}

/* Fields */
.field {
  border-bottom: 1px solid #aaa;
  min-height: 17px;
  padding: 2px 0 1px;
  line-height: 1.25;
}

.field[contenteditable="true"] {
  outline: none;
  cursor: text;
}

.field[contenteditable="true"]:focus {
  background: #ffffcc;
  border-bottom-color: #0f6cbd;
}

.field-value {
  display: none;
}

/* Notes and text */
.note {
  font-size: 10.5px;
  color: #333;
  line-height: 1.4;
}

.note.red {
  color: #a60000;
}

.small {
  font-size: 10.25px;
}

.muted {
  color: #666;
}

.text-muted {
  color: #666;
  font-size: 0.875rem;
}

/* Stamp overlay */
.stamp-overlay {
  position: absolute;
  top: 3mm;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 6mm);
  max-height: calc(100% - 16mm);
  object-fit: contain;
  object-position: center;
  opacity: 0.9;
  pointer-events: none;
}

/* Signature blocks */
.sign-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6mm;
  margin-top: 6mm;
}

.sign {
  border: 1.5px solid #444;
  border-radius: 4px;
  padding: 4mm;
  min-height: 22mm;
  position: relative;
}

.sign .line {
  border-top: 1px solid #666;
  margin-top: 10mm;
}

.sign .caption {
  font-size: 10.5px;
  color: #333;
  margin-top: 2mm;
}

/* Footer fields */
.footer-fields {
  display: block;
  margin-top: 6mm;
}

.cols-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4mm;
}

.cols-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4mm;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 8px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid #ddd;
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.close-modal {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: #666;
  line-height: 1;
  padding: 0;
  width: 2rem;
  height: 2rem;
}

.close-modal:hover {
  color: #000;
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid #ddd;
  padding: 0 1.5rem;
  background: #f5f5f5;
}

.tab-btn {
  background: none;
  border: none;
  padding: 1rem 1.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: #666;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: #333;
}

.tab-btn.active {
  color: #0f6cbd;
  border-bottom-color: #0f6cbd;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.tab-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
}

/* List Items */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 0.75rem;
  background: white;
}

.list-item-content {
  flex: 1;
}

.list-item-content strong {
  display: block;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.list-item-actions {
  display: flex;
  gap: 0.5rem;
}

.badge {
  display: inline-block;
  background: #0f6cbd;
  color: white;
  padding: 0.125rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-left: 0.5rem;
}

.empty-message {
  text-align: center;
  color: #666;
  padding: 2rem;
  font-style: italic;
}

/* Edit Forms */
.edit-form {
  display: none;
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.edit-form.active {
  display: block;
}

.edit-form h4 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* Checkbox label */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Backup Actions */
.backup-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 300px;
}

/* Toast Messages */
.toast-message {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #333;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 2000;
}

.toast-message.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .app-container {
    grid-template-columns: 320px 1fr;
  }
}

@media (max-width: 968px) {
  .app-container {
    grid-template-columns: 1fr;
    height: auto;
  }
  
  .form-sidebar {
    border-right: none;
    border-bottom: 1px solid #ddd;
  }
  
  .preview-area {
    padding: 10mm;
  }
}

@media (max-width: 640px) {
  .app-header {
    padding: 1rem;
  }
  
  .header-content {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  
  .header-actions {
    flex-direction: column;
  }
  
  .form-sidebar {
    padding: 1rem;
  }
  
  .modal {
    padding: 0.5rem;
  }
  
  .modal-content {
    max-height: 95vh;
  }
}
