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