/* ============================================================
   Estimate Maker — estimate-maker.css
   Premium 3-column card-based UI (mirrors invoice-maker)
   ============================================================ */

/* ── Global App Scope ────────────────────────────────────── */
.em-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;
}
.em-wrap * { box-sizing: border-box; }

/* ── Header ──────────────────────────────────────────────── */
.em-header-title { margin-bottom: 32px; }
.em-header-title h2 {
  font-size: 26px;
  font-weight: 700;
  color: #111827;
  margin: 0 0 6px 0;
}
.em-header-title p {
  font-size: 15px;
  color: #6b7280;
  margin: 0;
}

/* ── Grid Layout ─────────────────────────────────────────── */
.em-layout-grid {
  display: grid;
  grid-template-columns: 320px minmax(380px, 1fr) 280px;
  gap: 24px;
  align-items: start;
}

.em-col {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.em-mt  { margin-top: 16px !important; }
.em-mt2 { margin-top: 12px !important; }

/* ── Cards ───────────────────────────────────────────────── */
.em-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;
}
.em-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;
}
.em-card-header svg { color: #4f46e5; }
.em-card-body { padding: 20px; }
.em-no-pad .em-card-body { padding: 0; }

/* ── Form Fields ─────────────────────────────────────────── */
.em-field-box { margin-bottom: 0; }

.em-form-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}
.em-form-row:last-child { border-bottom: none; padding-bottom: 0; }

.em-inline-label {
  font-size: 14px;
  color: #4b5563;
  font-weight: 500;
  width: 110px;
  flex-shrink: 0;
}
.em-form-row .em-input,
.em-form-row .em-select {
  width: 160px;
  text-align: right;
  border-color: transparent;
  background: transparent;
  padding: 6px 8px;
}
.em-form-row .em-input:focus,
.em-form-row .em-select:focus {
  background: #fff;
  border-color: #4f46e5;
}

.em-float-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.em-input,
.em-select,
.em-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 ease;
  font-family: inherit;
  resize: none;
}
.em-input:focus,
.em-select:focus,
.em-textarea:focus {
  outline: none;
  border-color: #4f46e5;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.em-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 Upload ─────────────────────────────────────────── */
.em-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;
}
.em-logo-box:hover { border-color: #4f46e5; background: #eff6ff; }
.em-logo-box.em-drag-over { border-color: #4f46e5; background: #eff6ff; }
.em-logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #6b7280;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
}
.em-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 ─────────────────────────────────────────── */
.em-items-section { padding: 0; }
.em-items-head {
  display: grid;
  grid-template-columns: 1fr 60px 100px 100px 32px;
  gap: 12px;
  padding: 12px 20px;
  background: #4f46e5;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
}
.em-col-qty, .em-col-price, .em-col-amount { text-align: right; }

.em-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;
}
.em-item-row:last-child { border-bottom: none; }

/* Mobile card columns */
.em-r-col { display: flex; flex-direction: column; justify-content: center; height: 100%; }
.em-mob-label { display: none; }

.em-item-desc, .em-item-price, .em-item-qty {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 14px;
  background: transparent;
  font-family: inherit;
}
.em-item-desc:focus, .em-item-price:focus, .em-item-qty:focus {
  outline: none;
  border-color: #4f46e5;
  background: #fff;
}
.em-item-desc { border-color: #e5e7eb; background: #f9fafb; }
.em-item-price, .em-item-qty { text-align: right; font-family: inherit; }

.em-price-wrap { position: relative; width: 100%; }
.em-price-sym {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  color: #9ca3af; font-size: 13px; pointer-events: none;
}
.em-price-wrap .em-item-price { padding-left: 20px; }

.em-item-amount {
  text-align: right;
  font-weight: 600;
  color: #111827;
  font-size: 14px;
}

.em-item-del {
  background: none;
  border: none;
  color: #d1d5db;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s;
}
.em-item-del:hover { color: #ef4444; }

.em-items-actions {
  padding: 16px 20px;
  border-top: 1px solid #f3f4f6;
  background: #fafafa;
}
.em-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;
}
.em-btn-add-item:hover { background: #4f46e5; color: #fff; }

/* ── Totals Area ─────────────────────────────────────────── */
.em-totals-area {
  padding: 20px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
}
.em-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
  color: #4b5563;
}
#em-subtotal { font-weight: 600; color: #111827; }
.em-addon-toggle { cursor: pointer; user-select: none; }
.em-addon-label { color: #4f46e5; font-weight: 600; font-size: 13px; }
.em-addon-toggle:hover .em-addon-label { color: #4338ca; }

.em-addon-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 0;
}
.em-addon-input {
  width: 70px;
  padding: 6px 8px;
  border: 1.5px solid #e5e7eb;
  border-radius: 4px;
  font-size: 13px;
  text-align: right;
}
.em-addon-input:focus { outline: none; border-color: #4f46e5; }
.em-addon-pct { color: #6b7280; font-size: 13px; }
.em-addon-amt { font-weight: 600; color: #111827; min-width: 60px; text-align: right; }

.em-balance-row {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px solid #e5e7eb;
}
.em-balance-label {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  letter-spacing: 0.04em;
}
.em-balance-amt {
  font-size: 20px;
  font-weight: 800;
  color: #111827;
}

/* ── Actions Column ──────────────────────────────────────── */
.em-actions-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #ffffff;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.em-btn-primary, .em-btn-secondary, .em-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;
}
.em-btn-primary {
  background: #4f46e5;
  color: #fff;
  padding: 14px 16px;
  font-size: 15px;
}
.em-btn-primary:hover { background: #4338ca; box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2); }

.em-btn-secondary {
  background: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
}
.em-btn-secondary:hover { background: #18e128; border-color: #9ca3af; }

.em-btn-danger.em-btn-reset-sidebar {
  background: #fee2e2;
  color: #ef4444;
  margin-top: 12px;
}
.em-btn-danger:hover { background: #fecaca; }

/* Mobile Download duplicate */
.em-btn-download-mob { display: none; }

/* ── Preview Skeleton ────────────────────────────────────── */
.em-preview-graphic {
  background: #ffffff;
  border-radius: 10px;
  padding: 24px;
  border: 1px dashed #d1d5db;
  text-align: center;
  margin-top: 0;
}
.em-preview-graphic p { font-size: 12px; color: #6b7280; margin-top: 16px; margin-bottom: 0; line-height: 1.5; }
.em-pg-skeleton { width: 100%; }
.em-pg-s-header { display: flex; justify-content: space-between; margin-bottom: 16px; }
.em-pg-s-logo { width: 40px; height: 16px; background: #e5e7eb; border-radius: 2px; }
.em-pg-s-title { width: 60px; height: 16px; background: #c7d2fe; border-radius: 2px; }
.em-pg-s-lines { height: 8px; background: #f3f4f6; margin-bottom: 8px; border-radius: 4px; }
.em-w-half { width: 50%; }
.em-pg-s-table { height: 40px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 4px; margin-top: 16px; }
.em-pg-s-totals { width: 40%; height: 24px; background: #e5e7eb; margin-left: auto; margin-top: 16px; border-radius: 4px; }

/* ── Preview Modal ───────────────────────────────────────── */
.em-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;
}
.em-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);
}
.em-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px;
  background: #ffffff;
  border-bottom: 1px solid #d1d5db;
  align-items: center;
}
.em-preview-actions button { width: auto; white-space: nowrap; }
.em-preview-actions .em-btn-primary { flex: 1 1 100%; }
.em-preview-actions .em-btn-secondary { flex: 1; }

.em-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;
}
.em-btn-close:hover { background: #efa7a3; }

.em-preview-doc {
  padding: 32px 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
}

/* ── Document (Preview HTML) ─────────────────────────────── */
.em-preview-doc .em-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;
}

.em-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 36px 40px 28px 36px;
  background: #1e1b4b;
  position: relative;
  overflow: hidden;
}
.em-doc-header::after {
  content: '';
  position: absolute;
  right: -40px; top: -40px;
  width: 200px; height: 200px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}
.em-doc-logo { max-width: 160px; max-height: 70px; object-fit: contain; }
.em-doc-biz-name {
  font-size: 26px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.em-doc-biz-addr {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  margin-top: 6px;
  white-space: pre-line;
  line-height: 1.6;
}
.em-doc-type {
  font-size: 30px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.9;
}
.em-doc-right { text-align: right; }
.em-doc-meta {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  margin-top: 8px;
  line-height: 1.9;
}

.em-doc-body { padding: 36px 40px 40px; }

.em-doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 36px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.em-doc-party { padding: 20px 24px; background: #f9fafb; }
.em-doc-party:first-child { border-right: 1px solid #e5e7eb; }
.em-doc-party-lbl {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6366f1;
  margin-top: 8px;
  margin-bottom: 8px;
}
.em-doc-party-addr {
  font-size: 12.5px;
  color: #6b7280;
  white-space: pre-line;
  margin-top: 4px;
  line-height: 1.6;
}

.em-doc-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.em-doc-table thead tr { background: #1e1b4b; }
.em-doc-table th {
  background: transparent;
  color: #ffffff;
  padding: 12px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.em-doc-table th.r, .em-doc-table td.r { text-align: right; }
.em-doc-table td {
  padding: 13px 14px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13.5px;
  color: #374151;
}
.em-doc-table tbody tr:hover td { background: #f9fafb; }
.em-doc-table tr:last-child td { border-bottom: 2px solid #e5e7eb; }

.em-doc-totals {
  max-width: 300px;
  margin-left: auto;
  margin-bottom: 32px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.em-doc-total-row {
  display: flex;
  justify-content: space-between;
  padding: 11px 16px;
  font-size: 13.5px;
  color: #4b5563;
  border-bottom: 1px solid #f3f4f6;
  background: #ffffff;
}
.em-doc-total-balance {
  display: flex;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  background: #1e1b4b;
}

.em-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;
}

.em-doc-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 11px;
  color: #9ca3af;
  border-top: 1px solid #e5e7eb;
  padding-top: 12px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1199px) {
  .em-layout-grid { grid-template-columns: 1fr; }
  .em-col-3 {
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .em-actions-panel { flex-direction: column; width: 100%; }
  .em-preview-graphic, .em-btn-reset-sidebar { display: none; }
  .em-btn-download-mob { display: flex; }
}

@media (max-width: 1024px) {
  .em-items-head { display: none; }
  .em-items-list { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
  .em-item-row {
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    position: relative;
  }
  .em-r-col { align-items: flex-start; justify-content: flex-start; width: 100%; }
  .em-mob-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 4px;
    text-transform: uppercase;
  }
  .em-item-desc, .em-item-price, .em-item-qty { text-align: left; background: #fff; }
  .em-price-wrap .em-item-price { padding-left: 20px; }
  .em-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;
  }
  .em-r-amt .em-mob-label { margin-bottom: 0; }
  .em-item-amount { font-size: 16px; }
  .em-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) {
  .em-wrap { padding: 16px; }

  /* Preview modal */
  .em-preview-overlay { padding: 0; align-items: flex-end; }
  .em-preview-modal {
    border-radius: 16px 16px 0 0;
    max-height: 95vh;
  }
  .em-preview-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 16px;
  }
  .em-preview-actions .em-btn-primary  { order: 1; flex: 1 1 100%; }
  .em-preview-actions .em-btn-secondary { order: 2; flex: 1; }
  .em-btn-close { order: 3; flex: 1; margin-left: 0; }

  /* Document scaling */
  .em-preview-doc {
    padding: 16px 0;
    overflow-x: hidden;
  }
  .em-preview-doc .em-doc {
    width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
  }
  .em-doc-header {
    padding: 24px 20px 20px;
    flex-wrap: wrap;
    gap: 12px;
  }
  .em-doc-type { font-size: 22px; letter-spacing: 0.06em; }
  .em-doc-biz-name { font-size: 20px; }
  .em-doc-body { padding: 20px; }
  .em-doc-parties { grid-template-columns: 1fr; }
  .em-doc-party:first-child { border-right: none; border-bottom: 1px solid #e5e7eb; }
  .em-doc-table th, .em-doc-table td { padding: 10px 10px; font-size: 12px; }
}

/* ── Print ───────────────────────────────────────────────── */
@media print {
  .em-header-title, .em-layout-grid, .em-preview-actions { display: none !important; }
  .em-preview-overlay { display: block !important; position: static !important; background: none !important; padding: 0 !important; }
  .em-preview-modal { box-shadow: none !important; max-height: none !important; border-radius: 0 !important; background: none !important; }
  .em-preview-doc { padding: 0 !important; display: block !important; }
  .em-preview-doc .em-doc { width: 100% !important; box-shadow: none !important; padding: 0 !important; min-height: auto !important; }
}
