/* ============================================================
   Purchase Order — purchase-order.css
   Premium 3-column card-based UI (mirrors invoice-maker)
   ============================================================ */

.po-wrap {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #374151;
  max-width: 1200px;
  margin: 0 auto;
  background: #f9fafb;
  border-radius: 12px;
  padding: 24px;
  box-sizing: border-box;
}
.po-wrap * { box-sizing: border-box; }

.po-header-title { margin-bottom: 32px; }
.po-header-title h2 { font-size: 26px; font-weight: 700; color: #111827; margin: 0 0 6px 0; }
.po-header-title p  { font-size: 15px; color: #6b7280; margin: 0; }

/* ── Grid ────────────────────────────────────────────────── */
.po-layout-grid {
  display: grid;
  grid-template-columns: 320px minmax(380px, 1fr) 280px;
  gap: 24px;
  align-items: start;
}
.po-col { display: flex; flex-direction: column; gap: 24px; }
.po-mt  { margin-top: 16px !important; }
.po-mt2 { margin-top: 12px !important; }

/* ── Cards ───────────────────────────────────────────────── */
.po-card {
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
  border: 1px solid #e5e7eb;
  overflow: hidden;
}
.po-card-header {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 20px;
  background: #fcfcfc;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 600; color: #374151; font-size: 15px;
}
.po-card-header svg { color: #4f46e5; }
.po-card-body { padding: 20px; }
.po-no-pad .po-card-body { padding: 0; }

/* ── Form Fields ─────────────────────────────────────────── */
.po-form-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid #f3f4f6;
}
.po-form-row:last-child { border-bottom: none; padding-bottom: 0; }
.po-inline-label { font-size: 14px; color: #4b5563; font-weight: 500; width: 120px; flex-shrink: 0; }
.po-form-row .po-input,
.po-form-row .po-select {
  width: 160px; text-align: right;
  border-color: transparent; background: transparent; padding: 6px 8px;
}
.po-form-row .po-input:focus,
.po-form-row .po-select:focus { background: #fff; border-color: #4f46e5; }

.po-float-label {
  display: block; font-size: 12px; font-weight: 600;
  color: #6b7280; margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.po-input, .po-select, .po-textarea {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid #e5e7eb; border-radius: 6px;
  font-size: 14px; color: #111827; background: #f9fafb;
  transition: all 0.2s; font-family: inherit; resize: none;
}
.po-input:focus, .po-select:focus, .po-textarea:focus {
  outline: none; border-color: #4f46e5; background: #fff;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.po-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}

/* ── Logo ────────────────────────────────────────────────── */
.po-logo-box {
  width: 100%; height: 90px;
  border: 2px dashed #d1d5db; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; position: relative;
  background: #f9fafb; transition: all 0.2s;
}
.po-logo-box:hover, .po-logo-box.po-drag-over { border-color: #4f46e5; background: #eff6ff; }
.po-logo-placeholder {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; color: #6b7280; font-size: 13px; font-weight: 500; pointer-events: none;
}
.po-logo-remove {
  position: absolute; top: 6px; right: 6px;
  background: rgba(17,24,39,0.6); color: #fff; border: none;
  border-radius: 50%; width: 24px; height: 24px;
  font-size: 12px; cursor: pointer; line-height: 24px; text-align: center; padding: 0;
}

/* ── Items Table ─────────────────────────────────────────── */
.po-items-section { padding: 0; }
.po-items-head {
  display: grid; grid-template-columns: 1fr 60px 100px 100px 32px;
  gap: 12px; padding: 12px 20px;
  background: #4f46e5; color: #fff; font-size: 13px; font-weight: 600;
}
.po-col-qty, .po-col-price, .po-col-amount { text-align: right; }

.po-item-row {
  display: grid; grid-template-columns: 1fr 60px 100px 100px 32px;
  gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid #f3f4f6; align-items: center;
}
.po-item-row:last-child { border-bottom: none; }

.po-r-col { display: flex; flex-direction: column; justify-content: center; height: 100%; }
.po-mob-label { display: none; }

.po-item-desc, .po-item-price, .po-item-qty {
  width: 100%; padding: 8px 10px;
  border: 1px solid transparent; border-radius: 4px;
  font-size: 14px; background: transparent; font-family: inherit;
}
.po-item-desc:focus, .po-item-price:focus, .po-item-qty:focus {
  outline: none; border-color: #4f46e5; background: #fff;
}
.po-item-desc { border-color: #e5e7eb; background: #f9fafb; }
.po-item-price, .po-item-qty { text-align: right; font-family: inherit; }

.po-price-wrap { position: relative; width: 100%; }
.po-price-sym {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  color: #9ca3af; font-size: 13px; pointer-events: none;
}
.po-price-wrap .po-item-price { padding-left: 20px; }

.po-item-amount { text-align: right; font-weight: 600; color: #111827; font-size: 14px; }
.po-item-del {
  background: none; border: none; color: #d1d5db;
  font-size: 20px; cursor: pointer; padding: 0; transition: color 0.15s;
}
.po-item-del:hover { color: #ef4444; }

.po-items-actions {
  padding: 16px 20px; border-top: 1px solid #f3f4f6; background: #fafafa;
}
.po-btn-add-item {
  background: #eff6ff; color: #4f46e5; border: 1px solid #4f46e5;
  border-radius: 6px; padding: 8px 16px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.po-btn-add-item:hover { background: #4f46e5; color: #fff; }

/* ── Totals ──────────────────────────────────────────────── */
.po-totals-area { padding: 20px; background: #fff; border-top: 1px solid #e5e7eb; }
.po-total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; font-size: 14px; color: #4b5563;
}
#po-subtotal { font-weight: 600; color: #111827; }
.po-addon-toggle { cursor: pointer; user-select: none; }
.po-addon-label { color: #4f46e5; font-weight: 600; font-size: 13px; }
.po-addon-toggle:hover .po-addon-label { color: #4338ca; }

.po-addon-row {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; padding: 6px 0;
}
.po-addon-input {
  width: 70px; padding: 6px 8px;
  border: 1.5px solid #e5e7eb; border-radius: 4px;
  font-size: 13px; text-align: right;
}
.po-addon-input:focus { outline: none; border-color: #4f46e5; }
.po-addon-pct { color: #6b7280; font-size: 13px; }
.po-addon-amt { font-weight: 600; color: #111827; min-width: 60px; text-align: right; }

.po-balance-row { margin-top: 16px; padding-top: 16px; border-top: 2px solid #e5e7eb; }
.po-balance-label { font-size: 14px; font-weight: 700; color: #111827; letter-spacing: 0.04em; }
.po-balance-amt { font-size: 20px; font-weight: 800; color: #111827; }

/* ── Actions Column ──────────────────────────────────────── */
.po-actions-panel {
  display: flex; flex-direction: column; gap: 12px;
  background: #fff; padding: 20px;
  border-radius: 10px; border: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.po-btn-primary, .po-btn-secondary, .po-btn-danger {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; border: none; border-radius: 6px; padding: 12px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; width: 100%; font-family: inherit;
}
.po-btn-primary { background: #4f46e5; color: #fff; padding: 14px 16px; font-size: 15px; }
.po-btn-primary:hover { background: #4338ca; box-shadow: 0 4px 6px -1px rgba(79,70,229,0.2); }
.po-btn-secondary { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.po-btn-secondary:hover { background: #1461ad; border-color: #9ca3af; }
.po-btn-danger.po-btn-reset-sidebar { background: #fee2e2; color: #ef4444; margin-top: 12px; }
.po-btn-danger:hover { background: #fecaca; }

.po-btn-download-mob { display: none; }

/* ── Preview Skeleton ────────────────────────────────────── */
.po-preview-graphic {
  background: #fff; border-radius: 10px; padding: 24px;
  border: 1px dashed #d1d5db; text-align: center;
}
.po-preview-graphic p { font-size: 12px; color: #6b7280; margin-top: 16px; margin-bottom: 0; line-height: 1.5; }
.po-pg-skeleton { width: 100%; }
.po-pg-s-header { display: flex; justify-content: space-between; margin-bottom: 16px; }
.po-pg-s-logo  { width: 40px; height: 16px; background: #e5e7eb; border-radius: 2px; }
.po-pg-s-title { width: 60px; height: 16px; background: #c7d2fe; border-radius: 2px; }
.po-pg-s-lines { height: 8px; background: #f3f4f6; margin-bottom: 8px; border-radius: 4px; }
.po-w-half { width: 50%; }
.po-pg-s-table  { height: 40px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 4px; margin-top: 16px; }
.po-pg-s-totals { width: 40%; height: 24px; background: #e5e7eb; margin-left: auto; margin-top: 16px; border-radius: 4px; }

/* ── Preview Modal ───────────────────────────────────────── */
.po-preview-overlay {
  position: fixed; inset: 0;
  background: rgba(17,24,39,0.7); backdrop-filter: blur(4px);
  z-index: 99999; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.po-preview-modal {
  background: #e5e7eb; border-radius: 12px;
  width: 100%; max-width: 820px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}
.po-preview-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 14px 16px; background: #fff;
  border-bottom: 1px solid #d1d5db; align-items: center;
}
.po-preview-actions button { width: auto; white-space: nowrap; }
.po-preview-actions .po-btn-primary  { flex: 1 1 100%; }
.po-preview-actions .po-btn-secondary { flex: 1; }

.po-btn-close {
  flex: 0 0 auto; margin-left: auto;
  background: #f3f4f6; border: 1px solid #d1d5db;
  border-radius: 6px; padding: 10px 16px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  color: #374151; transition: all 0.2s;
}
.po-btn-close:hover { color:white; background: #eb9a9a; }

.po-preview-doc { padding: 32px 0; overflow-y: auto; display: flex; justify-content: center; }

/* ── Document Styling ────────────────────────────────────── */
.po-preview-doc .po-doc {
  background: #fff; width: 210mm; min-height: 297mm; padding: 0;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  font-size: 13.5px; line-height: 1.6; color: #374151;
  font-family: inherit; overflow: hidden;
}
.po-doc-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 36px 40px 28px; background: #1e1b4b; position: relative; overflow: hidden;
}
.po-doc-header::after {
  content: ''; position: absolute; right: -40px; top: -40px;
  width: 200px; height: 200px; background: rgba(255,255,255,0.05); border-radius: 50%;
}
.po-doc-logo    { max-width: 160px; max-height: 70px; object-fit: contain; }
.po-doc-biz-name { font-size: 26px; font-weight: 800; color: #fff; letter-spacing: -0.01em; line-height: 1.2; }
.po-doc-biz-addr { font-size: 12px; color: rgba(255,255,255,0.65); margin-top: 6px; white-space: pre-line; line-height: 1.6; }
.po-doc-type    { font-size: 26px; font-weight: 700; color: #fff; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.9; }
.po-doc-right   { text-align: right; }
.po-doc-meta    { font-size: 12px; color: rgba(255,255,255,0.65); margin-top: 8px; line-height: 1.9; }

.po-doc-body    { padding: 36px 40px 40px; }

.po-doc-parties {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  margin-bottom: 36px; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden;
}
.po-doc-party { padding: 20px 24px; background: #f9fafb; }
.po-doc-party:first-child { border-right: 1px solid #e5e7eb; }
.po-doc-delivery-box {
  background: #f0f0ff; border-left: 4px solid #6366f1;
  border-radius: 0 6px 6px 0; padding: 12px 18px;
  font-size: 13px; color: #374151; margin-bottom: 24px;
}
.po-doc-party-lbl  { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: #6366f1; margin-bottom: 8px; margin-top: 8px;}
.po-doc-party-addr { font-size: 12.5px; color: #6b7280; white-space: pre-line; margin-top: 4px; line-height: 1.6; }

.po-doc-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.po-doc-table thead tr { background: #1e1b4b; }
.po-doc-table th {
  background: transparent; color: #fff; padding: 12px 14px;
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
}
.po-doc-table th.r, .po-doc-table td.r { text-align: right; }
.po-doc-table td { padding: 13px 14px; border-bottom: 1px solid #f3f4f6; font-size: 13.5px; color: #374151; }
.po-doc-table tbody tr:hover td { background: #f9fafb; }
.po-doc-table tr:last-child td { border-bottom: 2px solid #e5e7eb; }

.po-doc-totals {
  max-width: 300px; margin-left: auto; margin-bottom: 32px;
  border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden;
}
.po-doc-total-row {
  display: flex; justify-content: space-between; padding: 11px 16px;
  font-size: 13.5px; color: #4b5563; border-bottom: 1px solid #f3f4f6; background: #fff;
}
.po-doc-total-balance {
  display: flex; justify-content: space-between; padding: 14px 16px;
  font-size: 16px; font-weight: 700; color: #fff; background: #1e1b4b;
}
.po-doc-notes {
  background: #f0f0ff; border-left: 4px solid #6366f1;
  border-radius: 0 6px 6px 0; padding: 14px 18px;
  font-size: 13px; color: #374151; white-space: pre-line; margin-top: 8px; line-height: 1.6;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1199px) {
  .po-layout-grid { grid-template-columns: 1fr; }
  .po-col-3 { order: -1; flex-direction: row; flex-wrap: wrap; }
  .po-actions-panel { flex-direction: column; width: 100%; }
  .po-preview-graphic, .po-btn-reset-sidebar { display: none; }
  .po-btn-download-mob { display: flex; }
}

@media (max-width: 1024px) {
  .po-items-head { display: none; }
  .po-item-row {
    display: flex; flex-direction: column;
    padding: 16px; gap: 12px;
    border: 1px solid #129741 !important; border-radius: 8px; position: relative;
  }
  .po-r-col  { align-items: flex-start; justify-content: flex-start; width: 100%; }
  .po-mob-label {
    display: block; font-size: 11px; font-weight: 600;
    color: #6b7280; margin-bottom: 4px; text-transform: uppercase;
  }
  .po-item-desc, .po-item-price, .po-item-qty { text-align: left; background: #fff; }
  .po-price-wrap .po-item-price { padding-left: 20px; }
  .po-r-amt {
    flex-direction: row; justify-content: space-between; align-items: center;
    width: 100%; border-top: 1px dashed #e5e7eb; padding-top: 12px; margin-top: 4px;
  }
  .po-r-amt .po-mob-label { margin-bottom: 0; }
  .po-item-amount { font-size: 16px; }
  .po-item-del {
    position: absolute; top: 12px; right: 16px;
    background: #fee2e2; color: #ef4444;
    width: 24px; height: 24px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center; font-size: 16px;
  }
}

@media (max-width: 640px) {
  .po-wrap { padding: 16px; }
  .po-preview-overlay { padding: 0; align-items: flex-end; }
  .po-preview-modal { border-radius: 16px 16px 0 0; max-height: 95vh; }
  .po-preview-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px; }
  .po-preview-actions .po-btn-primary   { order: 1; flex: 1 1 100%; }
  .po-preview-actions .po-btn-secondary { order: 2; flex: 1; }
  .po-btn-close { order: 3; flex: 1; margin-left: 0; }
  .po-preview-doc { padding: 16px 0; overflow-x: hidden; }
  .po-preview-doc .po-doc { width: 100% !important; min-height: auto !important; box-shadow: none !important; }
  .po-doc-header { padding: 24px 20px 20px; flex-wrap: wrap; gap: 12px; }
  .po-doc-type { font-size: 18px; letter-spacing: 0.05em; }
  .po-doc-biz-name { font-size: 20px; }
  .po-doc-body  { padding: 20px; }
  .po-doc-parties { grid-template-columns: 1fr; }
  .po-doc-party:first-child { border-right: none; border-bottom: 1px solid #e5e7eb; }
  .po-doc-table th, .po-doc-table td { padding: 10px; font-size: 12px; }
}

@media print {
  .po-header-title, .po-layout-grid, .po-preview-actions { display: none !important; }
  .po-preview-overlay { display: block !important; position: static !important; background: none !important; padding: 0 !important; }
  .po-preview-modal   { box-shadow: none !important; max-height: none !important; border-radius: 0 !important; background: none !important; }
  .po-preview-doc     { padding: 0 !important; display: block !important; }
  .po-preview-doc .po-doc { width: 100% !important; box-shadow: none !important; padding: 0 !important; min-height: auto !important; }
}
