/* Kathuriya Estimate / Quotation — wood & forest desk theme */
:root {
  --primary: #1f6b4a;
  --primary-dark: #17553a;
  --primary-soft: #e7f3ec;
  --accent: #a86b32;
  --accent-soft: #f7efe4;
  --bg: #e9eee9;
  --bg-glow: radial-gradient(1200px 480px at 10% -10%, #d9e8de 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #efe4d4 0%, transparent 50%),
    #e9eee9;
  --surface: #ffffff;
  --ink: #1e2a24;
  --muted: #6d7a72;
  --label: #5c6b63;
  --line: #cfd8d2;
  --line-soft: #e4ebe6;
  --sidebar: #14241d;
  --sidebar-active: #1f3a2e;
  --navbar: rgba(255, 255, 255, 0.92);
  --danger: #c62828;
  --ok: #1f7a45;
  --warn: #c48a16;
  --draft: #c48a16;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Georgia", serif;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 36, 29, 0.05), 0 8px 24px rgba(20, 36, 29, 0.04);
  --shadow-soft: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 10px 28px rgba(20, 36, 29, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--bg-glow);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* ===== Shell ===== */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background:
    linear-gradient(180deg, rgba(168, 107, 50, 0.12), transparent 28%),
    var(--sidebar);
  color: #c5d4cb;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #0d1712;
}

.brand {
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand strong {
  display: block;
  color: #fff;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand span {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: #93a79b;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar nav {
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #c5d4cb;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-btn.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--navbar);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.crumb {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.03em;
}

.content {
  padding: 14px 18px 48px;
  max-width: 1240px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
  box-shadow: var(--shadow);
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
}

.btn:hover {
  background: #f7faf8;
  border-color: #b7c5bc;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn.success {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}

.btn.btn-whatsapp {
  background: #128c7e;
  border-color: #128c7e;
  color: #fff;
}

.btn.btn-whatsapp:hover {
  background: #0e7368;
  border-color: #0e7368;
}

.btn.danger {
  color: var(--danger);
  border-color: #efc2c2;
  background: #fff;
}

.btn.danger:hover {
  background: #fff5f5;
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.card-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, #fbfcfb, #f3f7f4);
  min-height: 44px;
}

.card-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.card-body {
  padding: 14px;
}

.section-break {
  margin: 0 0 10px;
  padding: 6px 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-dark);
  border-bottom: 1px solid var(--line-soft);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field label {
  display: block;
  font-size: 11px;
  color: var(--label);
  margin-bottom: 4px;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 107, 74, 0.14);
}

.field input:disabled {
  background: #f4f7f5;
  color: var(--muted);
}

.field textarea {
  min-height: 64px;
  resize: vertical;
}

.field .hint,
.hint {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

.req {
  color: var(--danger);
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

table.data th,
table.data td {
  border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
  padding: 8px 10px;
  vertical-align: middle;
  background: #fff;
}

table.data th:last-child,
table.data td:last-child {
  border-right: 0;
}

table.data tbody tr:last-child td {
  border-bottom: 0;
}

table.data th {
  background: #f1f6f3;
  color: var(--label);
  font-weight: 700;
  font-size: 11px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

table.data tbody tr:nth-child(even) td {
  background: #fafcfb;
}

table.data .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.data .amount,
table.data td.num strong {
  font-weight: 700;
  color: var(--primary-dark);
}

table.data input,
table.data select {
  width: 100%;
  min-width: 64px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 6px;
  background: transparent;
}

table.data input:focus,
table.data select:focus {
  border-color: var(--primary);
  background: #fff;
  outline: none;
}

.list-link {
  color: var(--primary);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-weight: 600;
  font-size: inherit;
}

.list-link:hover {
  text-decoration: underline;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #eef2ef;
  color: var(--muted);
  line-height: 1.5;
}

.pill.draft {
  background: #fff4df;
  color: #8a6208;
}

.pill.saved,
.pill.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.pill.converted {
  background: #e8f1fc;
  color: #1a5fb4;
}

.pill.inactive {
  background: #f0f0f0;
  color: #6c757d;
}

.totals {
  display: grid;
  gap: 8px;
  max-width: 340px;
  margin-left: auto;
}

.totals .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.totals .row strong {
  font-size: 15px;
}

.totals input {
  width: 110px;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
}

.totals-box {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbfcfb, #f3f7f4);
}

.totals-box .row.grand {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-weight: 700;
}

.totals-box .row.grand strong {
  font-size: 18px;
  color: var(--primary-dark);
  letter-spacing: -0.02em;
}

/* Print / preview sheet */
.preview {
  background:
    linear-gradient(180deg, #fffdf9 0%, #ffffff 40%),
    #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.card-head .preview-actions {
  margin-left: auto;
}

.doc-letterhead {
  text-align: center;
  margin-bottom: 18px;
  padding: 4px 8px 16px;
  position: relative;
  border-bottom: 2px solid var(--ink);
}

.doc-letterhead-mark {
  width: 42px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--primary));
}

.doc-company-name {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1.15;
}

.doc-company-address {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

.doc-title {
  margin-top: 14px;
}

.doc-title span {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.doc-meta-row {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr;
  gap: 14px;
  margin: 0 0 18px;
}

.doc-party,
.doc-ref {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #fbfcfb;
}

.doc-party-heading {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.doc-party-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.doc-party-row,
.doc-ref-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 12.5px;
  line-height: 1.45;
}

.doc-party-label,
.doc-ref-row span {
  color: var(--label);
  font-weight: 600;
}

.doc-ref-row strong {
  font-weight: 700;
}

table.data.quote-items th {
  background: var(--sidebar);
  color: #e7efe9;
  border-color: #1b3027;
}

table.data.quote-items td {
  vertical-align: top;
}

table.data.quote-items .hint {
  color: #7a8a81;
}

@media print {
  @page {
    margin: 12mm;
  }

  body * {
    visibility: hidden;
  }

  #print-root,
  #print-root * {
    visibility: visible;
  }

  #print-root {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: #fff !important;
  }

  .no-print,
  .sidebar,
  .topbar,
  .preview-actions {
    display: none !important;
  }

  .table-wrap {
    overflow: visible !important;
  }

  table.data {
    min-width: 0 !important;
  }
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.toolbar h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.add-item-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.add-item-wrap select {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: #fff;
  min-width: 210px;
}

.wood-picker {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.wood-picker select {
  flex: 1;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  background: #fff;
}

.unit-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.unit-row input {
  flex: 1;
  min-width: 0;
}

.unit-row select {
  flex: 0 0 auto;
  width: auto;
  min-width: 72px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  background: #fff;
}

.callout {
  background: linear-gradient(135deg, var(--primary-soft), #f7efe4);
  border: 1px solid #cfe0d5;
  color: #24543c;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 12px;
}

.item-card {
  border-left: 4px solid var(--primary);
}

.item-card.editing {
  border-left-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(168, 107, 50, 0.18), var(--shadow-soft);
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.image-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.image-row img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 36, 29, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 16px;
  box-shadow: 0 18px 48px rgba(20, 36, 29, 0.18);
}

.modal h3 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
}

.share-modal {
  width: min(440px, 100%);
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.share-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.share-btn:active {
  background: #f3f6f8;
}

.share-btn .share-ico {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
}

.share-btn.share-whatsapp {
  border-color: #b7e0c2;
  background: #f3fbf5;
}

.share-btn.share-whatsapp .share-ico {
  color: #128c7e;
}

#share-text {
  width: 100%;
  min-height: 140px;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.45;
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

.doc-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.doc-title-row .doc-id {
  font-weight: 700;
  font-size: 15px;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 30;
  }

  .brand {
    padding: 10px 12px;
    border-bottom: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  .brand strong {
    font-size: 16px;
  }

  .sidebar nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    padding: 6px 8px;
    gap: 4px;
  }

  .nav-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 10px 12px;
    min-height: 40px;
  }

  .nav-btn.active {
    box-shadow: inset 0 -3px 0 var(--accent);
  }

  .topbar {
    padding: 10px 12px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .actions {
    width: 100%;
  }

  .actions .btn {
    flex: 1 1 auto;
    min-height: 40px;
    padding: 8px 12px;
  }

  .content {
    max-width: none;
    padding: 10px 10px 28px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }

  .form-grid,
  .form-grid.two {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .form-grid > .field[style*="grid-column"],
  .form-grid > .field.full {
    grid-column: 1 / -1 !important;
  }

  .field input,
  .field select,
  .field textarea,
  .add-item-wrap select,
  .wood-picker select,
  .unit-row select,
  table.data input,
  table.data select {
    font-size: 16px;
    min-height: 42px;
    padding: 8px 10px;
  }

  .btn,
  .btn.small {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 14px;
  }

  .add-item-wrap {
    width: 100%;
  }

  .add-item-wrap select {
    flex: 1;
    min-width: 0;
    width: 100%;
  }

  .card-head {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 10px;
  }

  .card-body {
    padding: 10px;
  }

  .table-wrap {
    margin: 0 -10px;
    padding: 0 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.data {
    min-width: 640px;
  }

  table.data.quote-items {
    min-width: 520px;
  }

  .preview {
    padding: 12px;
    overflow-x: auto;
  }

  .doc-company-name {
    font-size: 20px;
  }

  .doc-meta-row {
    grid-template-columns: 1fr;
  }

  .wood-picker select {
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .form-grid,
  .form-grid.two {
    grid-template-columns: 1fr;
  }

  .actions .btn {
    width: 100%;
  }

  .doc-title-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .share-grid {
    grid-template-columns: 1fr 1fr;
  }

  .share-btn {
    min-height: 72px;
  }

  table.data {
    min-width: 560px;
  }
}
