/* ================================================================
   FORMS — PrintLogic.Ai v3.0
   ================================================================
   Form cards, inputs, buttons, file drops, chat
   Source: mockup-redesign.html
   ================================================================ */

.page-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
}

.page-header-bar h1 {
  font-size: 20px;
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-6) var(--sp-8);
  box-shadow: var(--shadow-xs);
  max-width: 620px;
}

.info-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ink-lighter);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-5);
  font-size: 13px;
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: var(--sp-5);
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

.form-group label .req { color: var(--accent); }

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 14px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--ink-lighter);
  box-shadow: 0 0 0 3px rgb(15 20 25 / 6%);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

.display-field {
  background: var(--surface-alt);
  padding: 9px 12px;
  border-radius: var(--r-md);
  font-size: 14px;
  border: 1px solid var(--border);
  color: var(--text);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 20px;
  border-radius: var(--r-md);
  transition: all var(--t-fast);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
}

.btn svg { width: 15px; height: 15px; }

.btn-primary {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.btn-primary:hover { background: var(--ink-light); border-color: var(--ink-light); }

.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-success {
  background: var(--success);
  color: white;
  border-color: var(--success);
}
.btn-success:hover { background: #15803d; border-color: #15803d; }

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-warning {
  background: var(--warning);
  color: white;
  border-color: var(--warning);
}
.btn-warning:hover { background: #b45309; border-color: #b45309; }

.btn-link {
  background: transparent;
  color: var(--accent, #c8382e);
  border-color: transparent;
  padding: 4px 8px;
  text-decoration: underline;
}
.btn-link:hover { color: var(--accent-hover, #a02d24); }
.btn-link.text-danger { color: var(--danger); }
.btn-link.text-danger:hover { color: #b91c1c; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--surface-alt); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-full { width: 100%; }

/* File upload */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  cursor: pointer;
  transition: all var(--t-fast);
}

.file-drop:hover {
  border-color: var(--ink-lighter);
  background: var(--surface-alt);
}

.file-drop svg { margin: 0 auto var(--sp-2); color: var(--text-muted); width: 28px; height: 28px; }
.file-drop p { font-size: 13px; color: var(--text-secondary); }
.file-drop span { color: var(--accent); font-weight: 600; }

/* Chat */
.chat-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  min-height: 200px;
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.chat-msg {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  max-width: 85%;
  font-size: 13px;
  line-height: 1.5;
  animation: msgIn 0.2s var(--ease);
}

@keyframes msgIn {
  from { opacity: 0%; transform: translateY(6px); }
  to { opacity: 100%; transform: translateY(0); }
}

.chat-msg.user {
  background: var(--ink);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: var(--r-sm);
}

.chat-msg.bot {
  background: var(--surface);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: var(--r-sm);
}

.chat-input-row {
  display: flex;
  gap: var(--sp-2);
}

.chat-input-row textarea {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  resize: none;
  font-size: 14px;
}

.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--ink-lighter);
  box-shadow: 0 0 0 3px rgb(15 20 25 / 6%);
}

/* ============================================================================
   PO LINE-ITEM EDITOR (purchase-orders.js create modal)
   Scoped under .po-line-items-* / .po-line-item-* — no overlap with estimating.
   ========================================================================== */

.po-line-items-section {
  margin-bottom: var(--sp-3);
}

.po-line-items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-2);
}

.po-line-items-header,
.po-line-item-row {
  display: grid;
  grid-template-columns: 2.4fr 0.8fr 1fr 0.8fr 1.2fr 1fr 36px;
  gap: var(--sp-2);
  align-items: center;
}

.po-line-items-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-2);
}

.po-line-item-row {
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  margin-bottom: var(--sp-2);
}

.po-line-item-row input {
  padding: 6px 8px;
  font-size: 13px;
}

.po-line-item-row .po-li-total {
  font-weight: 600;
  text-align: right;
  color: var(--text);
}

.po-line-items-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--surface-alt);
  border-radius: var(--r-md);
  font-weight: 600;
}

.po-line-items-subtotal-value {
  color: var(--accent);
  min-width: 100px;
  text-align: right;
}

.po-line-items-empty {
  text-align: center;
  padding: var(--sp-5);
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-2);
}

/* Remove-line button: explicit scoped style so it stays visible
   regardless of .btn-danger cascade order between forms.css and
   email-integrations.css. */
.po-line-item-row .po-li-remove-btn {
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
  border-radius: var(--r-md);
  padding: 0;
  width: 28px;
  height: 28px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  justify-self: end;
}

.po-line-item-row .po-li-remove-btn:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.po-line-item-row .po-li-remove-btn:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  border-color: var(--border);
  cursor: not-allowed;
}

/* Narrow viewport — collapse to 2-col grid */
@media (width <= 720px) {
  .po-line-items-header { display: none; }

  .po-line-item-row {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-3);
  }
  .po-line-item-row .po-li-desc { grid-column: 1 / -1; }
  .po-line-item-row .po-li-remove-btn { grid-column: 2; justify-self: end; }
}

/* ============================================================================
   PO state-machine + detail modal (FLAGGED #214 Ship 2)
   ============================================================================ */

/* Action buttons: explicit scoped styles so they stay visible regardless of
   .btn-* cascade order between forms.css and email-integrations.css. Same
   workaround pattern as .po-li-remove-btn. */
.po-submit-btn {
  background: var(--ink);
  color: #fff;
  border: 1px solid var(--ink);
}
.po-submit-btn:hover { background: var(--ink-light); border-color: var(--ink-light); }

.po-cancel-btn,
.po-reject-btn {
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
}

.po-cancel-btn:hover,
.po-reject-btn:hover { background: #b91c1c; border-color: #b91c1c; }

.po-approve-btn {
  background: var(--success);
  color: #fff;
  border: 1px solid var(--success);
}
.po-approve-btn:hover { background: #15803d; border-color: #15803d; }

.po-email-btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.po-email-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.po-email-btn:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  border-color: var(--border);
  cursor: not-allowed;
}

.po-status-banner {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
  background: var(--surface-2, #f3f4f6);
  color: var(--text-primary, #1f2937);
}
.po-status-banner.status-draft            { background: #f3f4f6; color: #4b5563; }
.po-status-banner.status-pending_approval { background: #fef3c7; color: #92400e; }
.po-status-banner.status-approved         { background: #d1fae5; color: #065f46; }
.po-status-banner.status-sent             { background: #dbeafe; color: #1e40af; }
.po-status-banner.status-confirmed        { background: #dbeafe; color: #1e40af; }

.po-status-banner.status-partial,
.po-status-banner.status-partial_received { background: #e0e7ff; color: #3730a3; }
.po-status-banner.status-received         { background: #d1fae5; color: #065f46; }
.po-status-banner.status-rejected         { background: #fee2e2; color: #991b1b; }
.po-status-banner.status-cancelled        { background: #f3f4f6; color: #6b7280; }

.po-detail-modal .po-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 20px;
  margin-bottom: 20px;
}
.po-detail-modal .po-detail-grid > div { display: flex; flex-direction: column; }

.po-detail-modal .po-detail-grid label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 2px;
}
.po-detail-modal .po-detail-grid span { font-size: 14px; color: var(--text-primary, #1f2937); }
.po-detail-modal .po-detail-section-h { margin: 16px 0 8px; font-size: 14px; }
.po-detail-modal .po-items-table { width: 100%; margin-bottom: 16px; }
.po-detail-modal .po-detail-empty { text-align: center; color: var(--text-secondary, #6b7280); padding: 12px; }

.po-detail-modal .po-notes-block,
.po-detail-modal .po-approval-notes,
.po-detail-modal .po-rejection-notes {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-2, #f9fafb);
  border-left: 3px solid var(--border, #e5e7eb);
  border-radius: 4px;
}
.po-detail-modal .po-rejection-notes { border-left-color: #dc2626; }
.po-detail-modal .po-approval-notes  { border-left-color: #059669; }

.po-detail-modal .po-notes-block label,
.po-detail-modal .po-approval-notes label,
.po-detail-modal .po-rejection-notes label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 4px;
}

/* Action button color variants used by renderPOActions when not already
   defined globally. Scoped by class — won't collide with non-PO usage. */
.btn.btn-success {
  background: #059669;
  color: #fff;
  border: 1px solid #047857;
}
.btn.btn-success:hover { background: #047857; }

/* Make PO rows feel clickable */
tr.clickable-row { cursor: pointer; }
tr.clickable-row:hover { background: var(--surface-2, #f9fafb); }
