/* ============================================================
   app.css — Application Controls, Editor UI, Print CSS
   Styles for editable inputs, action buttons, and print mode.
   No external dependencies.
   ============================================================ */

/* --- Inline Inputs (seamless within invoice) --- */
.inv-input {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #bbb;
  outline: none;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  padding: 1px 2px;
  margin: 0;
  box-sizing: border-box;
  transition: border-color 0.2s, background-color 0.2s;
}

.inv-input:focus {
  border-bottom: 1px solid #4a86e8;
  background: #f0f7ff;
}

/* Text inputs — auto-size within their container */
input.inv-input {
  width: 60%;
}

/* Select dropdown — seamless */
select.inv-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  cursor: pointer;
  padding-right: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
  width: auto;
}

/* Textarea — seamless, resizable vertically only */
.inv-textarea {
  display: block;
  width: 100%;
  resize: vertical;
  border: none;
  border-bottom: 1px dashed #bbb;
  min-height: 1.5em;
  line-height: 1.4;
  transition: border-color 0.2s, background-color 0.2s;
}

.inv-textarea:focus {
  border-bottom: 1px solid #4a86e8;
  background: #f0f7ff;
}

/* Number inputs in item table — small and centered */
.inv-number {
  width: 100%;
  text-align: center;
  -moz-appearance: textfield;
}

.inv-number::-webkit-inner-spin-button,
.inv-number::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Item name input — wider, left aligned */
.inv-item-name {
  width: 100%;
  text-align: left;
  font-weight: 700;
}

/* Description input below item name */
.inv-item-desc {
  width: 100%;
  text-align: left;
  font-weight: 400;
  font-size: 7px;
  margin-top: 2px;
}

/* Charge inputs (Freight, Insurance, Other) */
.charge-input {
  width: 80px;
  text-align: right;
  margin-left: 4px;
}

.charge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1px 0;
}

/* Terms textarea */
.terms-textarea {
  width: 100%;
  min-height: 40px;
  border: none;
  border-bottom: none;
  resize: vertical;
  font-size: inherit;
  line-height: 1.4;
  transition: background-color 0.2s;
}

.terms-textarea:focus {
  background: #f0f7ff;
}

/* --- Action Buttons --- */

/* Add Item button */
.add-item-btn {
  background: #4a86e8;
  color: white;
  border: none;
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.add-item-btn:hover {
  background: #3b77d9;
}

/* Remove Item button */
.remove-btn {
  background: none;
  border: none;
  color: #dc2626;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  opacity: 0.5;
  transition: all 0.2s;
}

.remove-btn:hover {
  opacity: 1;
  background: #fee2e2;
  border-radius: 2px;
}


/* Seller Selector Bar (Top of screen) */
.seller-selector-bar {
  background: #f8f9fa;
  border-bottom: 1px solid #ddd;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  font-size: 13px;
  margin-bottom: 0;
  flex-wrap: wrap;
  gap: 12px;
}
.seller-selector-bar span {
  color: #666;
  margin-right: 8px;
}
.seller-selector-bar b {
  color: #111;
  font-size: 14px;
}

/* --- Print CSS --- */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  @page {
    margin: 10mm; /* Standard A4 printing margin */
    size: A4 portrait;
  }

  body {
    margin: 0;
    padding: 0;
    background: white;
    width: auto;
  }

  .invoice {
    max-width: none;
    border: 1px solid #333;
    margin: 0;
  }

  /* Prevent awkward page breaks in tables */
  tr {
    page-break-inside: avoid;
  }
  
  /* Prevent section splitting */
  table {
    page-break-inside: auto;
  }

  /* Hide all non-print elements */
  .no-print {
    display: none !important;
  }

  /* Make inputs look like plain text in print */
  .inv-input,
  .inv-textarea,
  .terms-textarea {
    border: none !important;
    border-bottom: none !important;
    background: transparent !important;
    outline: none !important;
    padding: 0 !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    resize: none;
  }

  select.inv-input {
    background-image: none !important;
    padding-right: 0 !important;
  }

  .inv-number {
    -moz-appearance: textfield;
  }

  /* Remove charge row flex layout in print — show as inline */
  .charge-row {
    display: inline;
  }

  .charge-input {
    display: inline;
    width: auto;
    margin-left: 4px;
  }

  .col-actions {
    display: none !important;
  }
}

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast-notification {
  background: #333;
  color: #fff;
  padding: 12px 24px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 14px;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: auto;
  text-align: center;
  white-space: pre-wrap;
}
.toast-notification.show {
  opacity: 1;
  transform: translateY(0);
}

/* Double-Click Protection */
button[data-clicked="true"] {
  position: relative !important;
  pointer-events: none !important;
  opacity: 0.6 !important;
  cursor: wait !important;
}
button[data-clicked="true"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1em;
  height: 1em;
  margin-top: -0.5em;
  margin-left: -0.5em;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: btn-spin 0.8s linear infinite;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}
