/* SmartIndia Quotation Generator — matches reference design */

:root {
  --navy: #1a3a6b;
  --navy-deep: #0f2d5c;
  --lavender: #e8ddf5;
  --lavender-deep: #d9c8ef;
  --gold: #e8b923;
  --gold-border: #d4a017;
  --gold-frame: #c9a227;
  --light-blue: #d6e8f5;
  --table-border: #7eb8d9;
  --row-border: #a8cfe6;
  --text: #1a1a1a;
  --muted: #4a5568;
  --orange-accent: #f5a623;
  --si-orange: #ff8c00;
  --si-white: #ffffff;
  --sidebar-bg: #f4f6f9;
  --app-bg: #e8edf3;
  --danger: #c0392b;
  --success: #1e7e34;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif-italic: Georgia, "Times New Roman", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--app-bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

/* ========== App shell ========== */
.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--navy-deep);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  z-index: 20;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  font-size: 15px;
}

.topbar-brand span {
  color: var(--si-orange);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mode-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.15);
}

.mode-badge.view {
  background: #e8b923;
  color: #1a1a1a;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--gold);
  color: #1a1a1a;
}
.btn-primary:hover:not(:disabled) { background: #f0c43a; }

.btn-ghost {
  background: rgba(255,255,255,.12);
  color: #fff;
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.22); }

.btn-outline {
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--table-border);
}
.btn-outline:hover:not(:disabled) { background: var(--lavender); }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  background: var(--lavender);
  color: var(--navy);
  border: 1px solid var(--table-border);
}
.btn-icon:hover { background: var(--lavender-deep); }

.btn-icon.danger {
  background: #fde8e8;
  color: var(--danger);
  border-color: #f5b5b5;
}

/* ========== Sidebar ========== */
.sidebar {
  grid-row: 2;
  background: var(--sidebar-bg);
  border-right: 1px solid #d0d7e2;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid #d0d7e2;
}

.sidebar-header h2 {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--navy);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.sidebar-header p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid #d0d7e2;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #c5ceda;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.sidebar-search input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 2px rgba(26,58,107,.12);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.history-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 13px;
}

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid #dce3ee;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.history-item:hover {
  border-color: var(--table-border);
  box-shadow: 0 2px 6px rgba(26,58,107,.08);
}

.history-item.active {
  border-color: var(--navy);
  box-shadow: 0 0 0 2px rgba(26,58,107,.15);
  background: #f0f5fb;
}

.history-item .hi-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.history-item .hi-no {
  font-weight: 700;
  color: var(--navy);
  font-size: 13px;
}

.history-item .hi-amt {
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
}

.history-item .hi-client {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .hi-date {
  font-size: 11px;
  color: var(--muted);
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid #d0d7e2;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  letter-spacing: .04em;
}

/* ========== Main / editor ========== */
.main {
  grid-row: 2;
  overflow: auto;
  padding: 20px 24px 40px;
  background: var(--app-bg);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.editor-toolbar .hint {
  font-size: 12px;
  color: var(--muted);
}

.quotation-wrap {
  max-width: 860px;
  margin: 0 auto;
}

/* ========== Quotation document ========== */
.quotation {
  position: relative;
  background: #fff;
  padding: 28px 32px 20px;
  /* Double gold frame */
  border: 2px solid var(--gold-frame);
  box-shadow:
    0 0 0 4px #fff,
    0 0 0 6px var(--gold-frame),
    0 8px 28px rgba(0,0,0,.12);
}

.quotation::before,
.quotation::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--gold-frame);
  border-style: solid;
  pointer-events: none;
}
.quotation::before {
  top: 6px; left: 6px;
  border-width: 2px 0 0 2px;
}
.quotation::after {
  top: 6px; right: 6px;
  border-width: 2px 2px 0 0;
}

.q-corner-bl,
.q-corner-br {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--gold-frame);
  border-style: solid;
  pointer-events: none;
}
.q-corner-bl {
  bottom: 6px; left: 6px;
  border-width: 0 0 2px 2px;
}
.q-corner-br {
  bottom: 6px; right: 6px;
  border-width: 0 2px 2px 0;
}

/* Header */
.q-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.logo-badge {
  background: transparent;
  padding: 0;
  line-height: 0;
  flex-shrink: 0;
}

.logo-badge .logo-img {
  display: block;
  width: 110px;
  height: 110px;
  object-fit: contain;
}

.company-meta {
  color: var(--navy);
  font-size: 12.5px;
  line-height: 1.55;
  padding-top: 2px;
}
.company-meta .gstin {
  font-weight: 700;
  margin-bottom: 2px;
}
.company-meta .meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.company-meta .meta-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: #2b6cb0;
}

.q-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: .04em;
  margin: 0;
  padding-top: 4px;
  line-height: 1;
}

/* Meta bar */
.q-meta-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-top: 1px solid #c5d5e8;
  border-bottom: 1px solid #c5d5e8;
  margin-bottom: 16px;
  padding: 8px 0;
}

.q-meta-item {
  padding: 0 12px;
  font-size: 13px;
  color: var(--navy);
  font-weight: 700;
}
.q-meta-item:not(:last-child) {
  border-right: 1px solid #c5d5e8;
}
.q-meta-item .label {
  font-weight: 700;
}
.q-meta-item .value {
  font-weight: 700;
}

/* Bill to */
.bill-to {
  margin-bottom: 14px;
}
.bill-to .label {
  color: var(--navy);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
.bill-to .client-name {
  font-size: 22px;
  font-weight: 800;
  color: #111;
  line-height: 1.2;
  margin-bottom: 2px;
}
.bill-to .client-phone {
  font-size: 14px;
  color: #222;
  font-weight: 500;
}

/* Editable fields (contenteditable / inputs look like print) */
.editable {
  outline: none;
  border-radius: 3px;
  transition: background .15s, box-shadow .15s;
  min-width: 1ch;
}
.quotation:not(.readonly) .editable:hover {
  background: rgba(232, 221, 245, .45);
}
.quotation:not(.readonly) .editable:focus {
  background: rgba(232, 221, 245, .7);
  box-shadow: 0 0 0 2px rgba(26,58,107,.18);
}
.quotation.readonly .editable {
  cursor: default;
  pointer-events: none;
}

.field-input {
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  font-weight: inherit;
  width: 100%;
  padding: 0;
  outline: none;
  border-radius: 3px;
}
.quotation:not(.readonly) .field-input:hover {
  background: rgba(232, 221, 245, .45);
}
.quotation:not(.readonly) .field-input:focus {
  background: rgba(232, 221, 245, .7);
  box-shadow: 0 0 0 2px rgba(26,58,107,.18);
}
.quotation.readonly .field-input {
  pointer-events: none;
}

.num-input {
  width: 72px;
  text-align: center;
}
.rate-input {
  width: 90px;
  text-align: right;
}

/* Items table */
.items-table-wrap {
  border: 1.5px solid var(--table-border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 0;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.items-table thead th {
  background: var(--lavender);
  color: var(--navy);
  font-weight: 800;
  letter-spacing: .03em;
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1.5px solid var(--table-border);
  font-size: 12.5px;
}

.items-table thead th.col-no { width: 48px; text-align: center; }
.items-table thead th.col-qty { width: 70px; text-align: center; }
.items-table thead th.col-rate { width: 100px; text-align: right; }
.items-table thead th.col-total { width: 110px; text-align: right; }

.items-table tbody td {
  padding: 10px;
  vertical-align: top;
  border-bottom: 1px solid var(--row-border);
}

.items-table tbody tr:last-child td {
  border-bottom: none;
}

.items-table .col-no {
  text-align: center;
  font-weight: 800;
  color: var(--navy);
  font-size: 14px;
}
.items-table .col-qty { text-align: center; }
.items-table .col-rate,
.items-table .col-total {
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}

.service-title {
  font-weight: 800;
  color: #111;
  font-size: 13.5px;
  margin-bottom: 6px;
  display: block;
}

.desc-list {
  margin: 0;
  padding: 0 0 0 18px;
  list-style: disc;
}
.desc-list li {
  font-style: italic;
  font-size: 12.5px;
  color: #222;
  margin-bottom: 2px;
  line-height: 1.35;
}
.desc-list li .desc-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}
.desc-list li .desc-text {
  flex: 1;
  font-style: italic;
  font: inherit;
  font-style: italic;
  border: none;
  background: transparent;
  width: 100%;
  outline: none;
  color: inherit;
  padding: 0;
  resize: none;
  min-height: 1.3em;
  overflow: hidden;
}
.quotation:not(.readonly) .desc-list li .desc-text:hover,
.quotation:not(.readonly) .desc-list li .desc-text:focus {
  background: rgba(232, 221, 245, .45);
}

.item-actions,
.desc-actions,
.term-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.quotation.readonly .item-actions,
.quotation.readonly .desc-actions,
.quotation.readonly .term-actions,
.quotation.readonly .add-item-bar {
  display: none !important;
}

.add-item-bar {
  margin: 0 0 10px;
  display: flex;
  gap: 8px;
}

/* Keep remove icons out of the way until hover */
.desc-remove {
  opacity: 0;
  flex-shrink: 0;
  transition: opacity .15s;
}
.desc-row:hover .desc-remove,
.desc-remove:focus {
  opacity: 1;
}

/* Subtotal */
.subtotal-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--lavender);
  padding: 10px 14px;
  margin-top: 0;
  border: 1.5px solid var(--table-border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  font-weight: 800;
  color: var(--navy);
  font-size: 13.5px;
  letter-spacing: .03em;
}

/* Totals area */
.totals-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 18px;
  align-items: start;
}

.terms-block {
  min-width: 0;
}
.terms-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.terms-heading .bar {
  width: 4px;
  height: 16px;
  background: var(--orange-accent);
  border-radius: 1px;
  flex-shrink: 0;
}
.terms-heading h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  color: #111;
  letter-spacing: .03em;
}

.terms-fixed {
  margin: 0;
  font-size: 11.5px;
  color: #222;
  line-height: 1.55;
  text-align: justify;
}

/* Payment details — fixed, non-editable */
.payment-block {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #c5d5e8;
}

.payment-details {
  margin: 0;
  font-size: 12.5px;
  color: #222;
}

.payment-details > div {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 6px 10px;
  margin-bottom: 4px;
  align-items: baseline;
}

.payment-details dt {
  margin: 0;
  font-weight: 700;
  color: var(--navy);
}

.payment-details dt::after {
  content: " :";
}

.payment-details dd {
  margin: 0;
  font-weight: 600;
  letter-spacing: .01em;
}

.payment-qr {
  text-align: center;
  flex-shrink: 0;
}

.payment-qr img {
  display: block;
  width: 140px;
  height: 140px;
  object-fit: contain;
  border: 1px solid #d0d7e2;
  border-radius: 6px;
  background: #fff;
}

.payment-qr .qr-caption {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.amount-block {
  text-align: right;
}
.total-amount-row {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 10px;
}
.total-amount-row .talabel {
  color: var(--navy);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: .03em;
}
.total-amount-row .tavalue {
  font-size: 20px;
  font-weight: 800;
  color: #111;
  border-bottom: 3px solid var(--gold);
  padding-bottom: 2px;
  min-width: 120px;
  text-align: right;
}

.words-box {
  background: var(--light-blue);
  border-radius: 4px;
  padding: 8px 12px;
  text-align: left;
}
.words-box .wlabel {
  font-size: 10px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: .04em;
  margin-bottom: 2px;
}
.words-box .wvalue {
  font-family: var(--serif-italic);
  font-style: italic;
  font-size: 14px;
  color: #111;
}

/* Footer bar */
.q-footer {
  margin-top: 22px;
  background: var(--light-blue);
  text-align: center;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .28em;
  color: var(--navy);
  text-transform: uppercase;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy-deep);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 100;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 360px;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* Mobile history toggle */
.mobile-menu-btn {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

/* ========== Print / PDF ========== */
@media print {
  body { background: #fff; overflow: visible; }
  .app { display: block; height: auto; }
  .topbar, .sidebar, .editor-toolbar, .toast, .sidebar-backdrop, .mobile-menu-btn {
    display: none !important;
  }
  .main { padding: 0; overflow: visible; }
  .quotation-wrap { max-width: none; }
  .quotation {
    box-shadow: none;
    border: 2px solid var(--gold-frame);
  }
  .quotation .item-actions,
  .quotation .desc-actions,
  .quotation .term-actions,
  .quotation .add-item-bar {
    display: none !important;
  }
}

/* PDF export mode — hide chrome inside quotation */
.quotation.pdf-export .item-actions,
.quotation.pdf-export .desc-actions,
.quotation.pdf-export .term-actions,
.quotation.pdf-export .add-item-bar,
.quotation.pdf-export .btn-icon {
  display: none !important;
}
.quotation.pdf-export .editable,
.quotation.pdf-export .field-input,
.quotation.pdf-export .desc-text,
.quotation.pdf-export .term-text {
  background: transparent !important;
  box-shadow: none !important;
}

/* ========== Responsive ========== */
@media (max-width: 960px) {
  body { overflow: auto; }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
    height: auto;
    min-height: 100vh;
  }
  .mobile-menu-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: min(320px, 88vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 56px 0 0 0;
    background: rgba(0,0,0,.35);
    z-index: 35;
  }
  .sidebar-backdrop.show { display: block; }

  .main { padding: 14px 10px 32px; }
  .q-header {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .q-title { font-size: 24px; }
  .q-meta-bar {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .q-meta-item:not(:last-child) {
    border-right: none;
    border-bottom: 1px solid #c5d5e8;
    padding-bottom: 6px;
  }
  .totals-area {
    grid-template-columns: 1fr;
  }
  .amount-block { text-align: left; }
  .total-amount-row { justify-content: space-between; }
  .payment-block {
    grid-template-columns: 1fr;
    justify-items: start;
  }
  .payment-qr { justify-self: center; }
  .quotation { padding: 18px 14px 14px; }
  .items-table thead th.col-rate,
  .items-table .col-rate { width: 80px; }
}
