/*
 * Quotationly v4.0.0 — Global Edition
 * Frontend & Admin Styles
 */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  --qly-primary:    #004481;
  --qly-secondary:  #E9AF02;
  --qly-bg:         #f8faff;
  --qly-bg-2:       #f1f5f9;
  --qly-card-bg:    #ffffff;
  --qly-border:     #e0e6ef;
  --qly-border-lt:  #f1f5f9;
  --qly-text:       #1a202c;
  --qly-text-2:     #374151;
  --qly-muted:      #6b7280;
  --qly-input-bg:   #ffffff;
  --qly-success:    #059669;
  --qly-danger:     #dc2626;
  --qly-warn:       #d97706;
  --qly-info:       #0284c7;
  --qly-radius:     10px;
  --qly-radius-lg:  16px;
  --qly-shadow:     0 2px 8px rgba(0,0,0,.07);
  --qly-shadow-lg:  0 8px 32px rgba(0,0,0,.12);
  --qly-font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --qly-transition: 0.2s ease;
}

/* ── Reset / Base ─────────────────────────────────────────── */
.qly-wrap, .qly-wrap * {
  box-sizing: border-box;
  font-family: var(--qly-font);
}

.qly-wrap {
  color: var(--qly-text);
  line-height: 1.55;
}

/* ── Form Inputs ──────────────────────────────────────────── */
.qly-input,
.qly-select {
  display: block;
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--qly-border);
  border-radius: var(--qly-radius);
  font-size: 14px;
  color: var(--qly-text);
  background: var(--qly-input-bg);
  transition: border-color var(--qly-transition), box-shadow var(--qly-transition);
  outline: none;
  font-family: var(--qly-font);
}
.qly-input:focus,
.qly-select:focus {
  border-color: var(--qly-primary);
  box-shadow: 0 0 0 3px rgba(0,68,129,.12);
}
.qly-input::placeholder { color: #a0aab4; }
.qly-input[type="color"] { padding: 4px; height: 42px; }

.qly-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--qly-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}

.qly-field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.qly-btn,
.qly-btn-primary,
.qly-btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: var(--qly-radius);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: opacity var(--qly-transition), transform var(--qly-transition);
  white-space: nowrap;
}
.qly-btn:hover,
.qly-btn-primary:hover {
  opacity: .88;
  transform: translateY(-1px);
}
.qly-btn-primary {
  background: var(--qly-primary);
  color: #fff;
}
.qly-btn-outline {
  background: transparent;
  border: 1px solid var(--qly-border);
  color: var(--qly-text-2);
}
.qly-btn-outline:hover { background: var(--qly-bg-2); }

.qly-btn-danger {
  background: var(--qly-danger);
  color: #fff;
  padding: 7px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
.qly-btn-sm {
  padding: 6px 14px;
  font-size: 12px;
  border-radius: 6px;
}

/* ── Admin Wrap ───────────────────────────────────────────── */
.qly-admin-wrap { max-width: 1100px; }

.qly-settings-card {
  background: #fff;
  border: 1px solid var(--qly-border);
  border-radius: var(--qly-radius-lg);
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: var(--qly-shadow);
}
.qly-settings-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 800;
  color: var(--qly-text);
}
.qly-settings-desc {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--qly-muted);
  line-height: 1.5;
}

/* ── Status Badges ────────────────────────────────────────── */
.qly-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .3px;
}
.qly-badge-draft        { background: #94a3b8; }
.qly-badge-sent         { background: var(--qly-info); }
.qly-badge-accepted     { background: var(--qly-success); }
.qly-badge-rejected     { background: var(--qly-danger); }
.qly-badge-partial_paid { background: var(--qly-warn); }
.qly-badge-paid         { background: #7c3aed; }

/* ── Dashboard Quote Row ─────────────────────────────────── */
.qly-quote-row {
  background: var(--qly-card-bg);
  border: 1px solid var(--qly-border);
  border-radius: var(--qly-radius-lg);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  transition: box-shadow var(--qly-transition);
}
.qly-quote-row:hover { box-shadow: var(--qly-shadow-lg); }

.qly-quote-meta {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.qly-quote-num {
  font-size: 13px;
  font-weight: 800;
  color: var(--qly-primary);
}
.qly-quote-client {
  font-size: 14px;
  font-weight: 600;
  color: var(--qly-text);
}
.qly-quote-date {
  font-size: 12px;
  color: var(--qly-muted);
}
.qly-quote-total {
  font-size: 16px;
  font-weight: 900;
  color: var(--qly-primary);
}

.qly-quote-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.qly-action-btn {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--qly-border);
  background: #fff;
  cursor: pointer;
  transition: all var(--qly-transition);
  color: var(--qly-text-2);
}
.qly-action-btn:hover { background: var(--qly-bg-2); border-color: var(--qly-primary); color: var(--qly-primary); }
.qly-action-btn.danger { border-color: #fca5a5; color: var(--qly-danger); }
.qly-action-btn.danger:hover { background: #fef2f2; }

/* ── Wizard ───────────────────────────────────────────────── */
#qly-generator .qly-step {
  animation: qlyFadeIn .25s ease;
}

@keyframes qlyFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.qly-step-indicator.active .qly-step-num {
  box-shadow: 0 0 0 4px rgba(0,68,129,.2);
}

.qly-item-card {
  background: var(--qly-bg);
  border: 1px solid var(--qly-border);
  border-radius: var(--qly-radius);
  padding: 16px;
}

/* ── Preview Document ─────────────────────────────────────── */
.qly-preview-doc {
  font-family: var(--qly-font);
  font-size: 13px;
  color: var(--qly-text);
  background: #fff;
}
.qly-preview-header {
  padding: 24px 28px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
}
.qly-preview-title {
  font-size: 22px;
  font-weight: 900;
  color: #fff;
}
.qly-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.qly-preview-table th,
.qly-preview-table td {
  padding: 10px 12px;
  border: 1px solid var(--qly-border);
  text-align: left;
}
.qly-preview-table th {
  background: var(--qly-bg);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  font-weight: 700;
  color: var(--qly-text-2);
}
.qly-preview-table tfoot tr td {
  border-top: 2px solid var(--qly-border);
  font-weight: 700;
}

/* ── KPI Cards ────────────────────────────────────────────── */
.qly-kpi-card {
  background: var(--qly-card-bg);
  border: 1px solid var(--qly-border);
  border-radius: var(--qly-radius-lg);
  padding: 18px 20px;
  box-shadow: var(--qly-shadow);
}

/* ── Toasts ───────────────────────────────────────────────── */
#qly-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.qly-toast {
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  max-width: 360px;
  box-shadow: var(--qly-shadow-lg);
  animation: qlySlideUp .25s ease;
  pointer-events: auto;
}
@keyframes qlySlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.qly-toast-success { background: var(--qly-success); }
.qly-toast-error   { background: var(--qly-danger); }
.qly-toast-info    { background: var(--qly-info); }
.qly-toast-warn    { background: var(--qly-warn); }

/* ── Print ────────────────────────────────────────────────── */
@media print {
  .qly-wizard-nav,
  .qly-steps-bar,
  .qly-dash-topbar,
  .qly-quote-actions,
  #qly-respond-section,
  #qly-analytics-row,
  #qly-pagination,
  nav, header, footer,
  .admin-bar,
  #qly-toast-container {
    display: none !important;
  }
  .qly-preview-doc, #qly-preview-render, .qly-share-view {
    width: 100% !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    page-break-after: avoid;
  }
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  /* A4 portrait — explicit size prevents browser defaulting to Letter */
  @page { size: A4 portrait; margin: 14mm 12mm; }
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  .qly-quote-row { flex-direction: column; align-items: flex-start; }
  .qly-kpi-card-grid { grid-template-columns: 1fr 1fr; }
  #qly-analytics-row { grid-template-columns: 1fr 1fr; }
  .qly-preview-header { flex-direction: column; }
  .qly-grid-2, .qly-grid-3 { grid-template-columns: 1fr; }
}

/* ── Indian GST PDF Template  (v5.3.0) ───────────────────── */
.qly-in-doc {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  color: #1a202c;
  background: #fff;
}
.qly-in-doc-banner {
  text-align: center;
  background: #fef9c3;
  border: 1px solid #fde047;
  border-radius: 4px;
  padding: 4px 12px;
  margin-bottom: 12px;
  font-size: 10px;
  font-weight: 700;
  color: #713f12;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.qly-in-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 12px;
  padding: 22px 26px;
}
.qly-in-biz-name {
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 4px;
}
.qly-in-biz-detail {
  color: rgba(255,255,255,.8);
  font-size: 11px;
  line-height: 1.5;
}
.qly-in-header-left { flex: 1 1 auto; min-width: 0; }
.qly-in-header-right { text-align: right; flex: 0 0 auto; min-width: 160px; max-width: 260px; margin-left: auto; }
.qly-in-quote-label {
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -.01em;
}
.qly-in-quote-ref {
  color: rgba(255,255,255,.9);
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}
.qly-in-quote-title {
  color: rgba(255,255,255,.8);
  font-size: 12px;
  margin-top: 2px;
}
.qly-in-quote-date { color: rgba(255,255,255,.75); font-size: 12px; margin-top: 4px; }
.qly-in-valid-until { color: #fca5a5; font-size: 12px; font-weight: 600; margin-top: 2px; }

.qly-in-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 18px 26px;
  border-bottom: 1px solid #e5e7eb;
}
.qly-in-party-label {
  font-size: 10px;
  font-weight: 700;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}
.qly-in-party-name { font-size: 15px; font-weight: 800; color: #1a202c; margin-bottom: 4px; }
.qly-in-party-detail { font-size: 11px; color: #6b7280; line-height: 1.5; }
.qly-in-supply-line { font-size: 11px; color: #374151; margin-top: 4px; }

.qly-in-section { padding: 16px 26px; page-break-inside: avoid; break-inside: avoid; }
.qly-in-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.qly-in-th {
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  background: #f8faff;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #374151;
  font-weight: 700;
  text-align: left;
}
.qly-in-td { padding: 8px 10px; border: 1px solid #e5e7eb; }
.qly-in-td-right { text-align: right; }
.qly-in-td-center { text-align: center; }
.qly-in-muted { color: #9ca3af; }
.qly-in-bold { font-weight: 700; color: #1a202c; }
.qly-in-disc { color: #dc2626; }
.qly-in-item-name { font-weight: 600; color: #1a202c; }
.qly-in-item-hsn { font-size: 10px; color: #9ca3af; margin-top: 2px; }

.qly-in-totals {
  float: right;
  width: 340px;
  margin: 0 26px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  font-size: 12px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.qly-in-total-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 14px;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
}
.qly-in-total-row:last-child { border-bottom: none; }
.qly-in-grand-row {
  background: #f0fdf4;
  font-weight: 800;
  font-size: 13px;
  color: #1a202c;
}
.qly-in-paid { color: #059669; font-weight: 700; }

.qly-in-gst-label {
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  margin: 10px 0 6px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.qly-in-meta-line { font-size: 11px; color: #374151; margin-bottom: 4px; }
.qly-in-disclaimer { font-size: 10px; color: #6b7280; margin-top: 8px; }

.qly-in-bank-box {
  margin: 0 26px 16px;
  padding: 14px 18px;
  background: #f0f9ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.qly-in-bank-label {
  font-size: 11px;
  font-weight: 700;
  color: #1d4ed8;
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 8px;
}
.qly-in-bank-key { padding: 2px 8px 2px 0; color: #6b7280; font-size: 11px; width: 130px; }
.qly-in-bank-val { font-weight: 600; color: #1e3a5f; font-size: 11px; }

.qly-in-notes-box {
  margin: 0 26px 12px;
  padding: 14px 16px;
  border: 1px solid #dbeafe;
  border-radius: 6px;
  font-size: 12px;
  color: #374151;
  line-height: 1.6;
  page-break-inside: avoid;
  break-inside: avoid;
}
.qly-in-notes-label {
  font-size: 10px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}

.qly-in-sig-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin: 24px 26px 16px;
  flex-wrap: wrap;
  page-break-inside: avoid;
  break-inside: avoid;
}
.qly-in-acceptance-box {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 14px 20px;
  min-width: 220px;
  flex: 1;
}
.qly-in-accept-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #6b7280;
  font-weight: 600;
  margin-bottom: 8px;
}
.qly-in-accept-hint { font-size: 11px; color: #374151; margin-bottom: 16px; }
.qly-in-sig-line { border-bottom: 1px solid #374151; margin-bottom: 4px; height: 36px; }
.qly-in-date-line { border-bottom: 1px solid #374151; margin: 12px 0 4px; height: 20px; }
.qly-in-sig-caption { font-size: 11px; color: #6b7280; }

.qly-in-auth-box {
  text-align: center;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 14px 24px 10px;
  min-width: 180px;
  max-width: 240px;
}
.qly-in-stamp-img { max-width: 90px; max-height: 90px; object-fit: contain; display: block; margin: 0 auto 4px; }
.qly-in-sig-img   { max-width: 140px; max-height: 65px; object-fit: contain; display: block; margin: 0 auto 6px; }
.qly-in-auth-label {
  border-top: 1px solid #374151;
  margin: 8px 0 4px;
  padding-top: 6px;
  font-size: 11px;
  color: #374151;
  letter-spacing: .4px;
  text-transform: uppercase;
  font-weight: 600;
}
.qly-in-auth-name { font-size: 11px; color: #374151; font-weight: 600; margin-top: 2px; }
.qly-in-auth-biz  { font-size: 10px; color: #6b7280; margin-top: 2px; }

.qly-in-footer {
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  padding: 10px 26px;
  text-align: center;
  font-size: 10px;
  color: #9ca3af;
  clear: both;
}

/* ── Homepage ─────────────────────────────────────────────── */
.qly-home section { animation: qlyFadeIn .4s ease; }

/* ── Utility ──────────────────────────────────────────────── */
.qly-empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--qly-muted);
}
.qly-empty-state-icon { font-size: 48px; margin-bottom: 14px; }
.qly-empty-state-title { font-size: 18px; font-weight: 700; color: var(--qly-text); margin-bottom: 8px; }
.qly-empty-state-text { font-size: 14px; line-height: 1.6; margin-bottom: 20px; }

.qly-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(0,68,129,.2);
  border-top-color: var(--qly-primary);
  border-radius: 50%;
  animation: qlySpin .7s linear infinite;
}
@keyframes qlySpin { to { transform: rotate(360deg); } }

/* ── Autocomplete ─────────────────────────────────────────── */
.qly-suggestion-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--qly-border-lt);
  transition: background var(--qly-transition);
}
.qly-suggestion-item:last-child { border-bottom: none; }
.qly-suggestion-item:hover { background: var(--qly-bg); }
.qly-suggestion-name { font-weight: 700; color: var(--qly-text); }

/* ── Print / PDF page-break rules ────────────────────────── */
@media print {
  /* Hide chrome, keep only the document */
  .qly-wizard-nav,
  .qly-actions,
  .qly-step,
  #qly-action-bar          { display: none !important; }

  /* Prevent orphaned block cuts */
  .qly-in-bank-box,
  .qly-in-notes-box,
  .qly-in-sig-row,
  .qly-in-totals,
  .qly-in-section,
  .qly-in-gst-summary,
  .qly-in-header,
  .qly-in-parties          { page-break-inside: avoid; break-inside: avoid; }

  /* Re-declare header flex so print engines keep the right-side column on the right */
  .qly-in-header           { display: flex !important; flex-wrap: nowrap !important; justify-content: space-between !important; }
  .qly-in-header-left      { flex: 1 1 auto !important; }
  .qly-in-header-right     { flex: 0 0 auto !important; text-align: right !important; margin-left: auto !important; min-width: 160px !important; }

  /* Start signature block on same or fresh page — never split it */
  .qly-in-sig-row          { page-break-before: auto; }

  /* Keep table header with first row */
  .qly-in-table thead      { display: table-header-group; }
  .qly-in-table tr         { page-break-inside: avoid; break-inside: avoid; }

  /* Ensure white background for colour accuracy */
  .qly-in-doc              { background: #fff !important; box-shadow: none !important; }
}
.qly-suggestion-email { font-size: 11px; color: var(--qly-muted); }
