/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #16a34a;
  --green-dark: #0f7235;
  --green-light: #dcfce7;
  --green-mid: #86efac;
  --gold: #d97706;
  --gold-light: #fef3c7;
  --cream: #fefce8;
  --white: #ffffff;
  --text: #1a2e1a;
  --text-mid: #3d5a3d;
  --text-light: #6b7c6b;
  --border: #bbf7d0;
  --shadow: 0 4px 24px rgba(22,163,74,0.10);
  --radius: 14px;
  --radius-sm: 8px;
}

html { font-size: 16px; }

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(135deg, #f0fdf4 0%, #fefce8 50%, #f0fdf4 100%);
  min-height: 100vh;
  color: var(--text);
}

/* === HEADER === */
.site-header {
  text-align: center;
  padding: 2.2rem 1rem 1.5rem;
  background: linear-gradient(135deg, var(--green) 0%, #15803d 60%, #166534 100%);
  position: relative;
  overflow: hidden;
}
.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.header-lotus {
  font-size: 2.4rem;
  display: block;
  margin-bottom: 0.4rem;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.2));
  animation: floatLotus 3s ease-in-out infinite;
}
@keyframes floatLotus {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.site-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.site-subtitle {
  font-family: 'Cinzel', serif;
  font-size: clamp(0.85rem, 3vw, 1.1rem);
  font-weight: 400;
  color: var(--green-mid);
  letter-spacing: 0.12em;
  margin-top: 0.2rem;
}

/* === MAIN === */
.main-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.form-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 1px 4px rgba(22,163,74,0.08);
  padding: 1.6rem 1.4rem;
  border: 1.5px solid var(--border);
}

/* === FIELDS === */
.field-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.field-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  min-width: 72px;
  flex-shrink: 0;
}
.select-wrapper {
  flex: 1;
  position: relative;
}
.select-wrapper select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 0.58rem 2.2rem 0.58rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  background: #f9fefb;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
.select-wrapper select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}
.select-arrow {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--green);
  pointer-events: none;
  font-size: 1rem;
}

/* === BOOKS SECTION === */
.books-section {
  margin-top: 1.2rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: visible; /* allow dropdown to escape the container */
}
.books-header {
  display: grid;
  grid-template-columns: 1fr 72px 90px 44px;
  gap: 0.5rem;
  background: linear-gradient(135deg, var(--green) 0%, #15803d 100%);
  padding: 0.65rem 0.8rem;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  letter-spacing: 0.04em;
}
.col-qty, .col-amt { text-align: center; }
.col-act { text-align: center; }

/* === BOOK ROW === */
.book-row {
  display: grid;
  grid-template-columns: 1fr 72px 90px 44px;
  gap: 0.5rem;
  align-items: center;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--green-light);
  animation: rowIn 0.25s ease;
}
@keyframes rowIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.book-row:last-child { border-bottom: none; }
.book-row:nth-child(even) { background: #f9fefb; }

/* On desktop: book-row-bottom is transparent to the parent grid */
.book-row-bottom { display: contents; }
/* Hide mini labels on desktop */
.field-mini-label { display: none; }

/* === SEARCHABLE BOOK DROPDOWN === */
.book-select-wrap {
  position: relative;
}
.book-search-input {
  width: 100%;
  padding: 0.52rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  background: #fff;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.book-search-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}
.book-search-input::placeholder { color: #9ca3af; font-size: 0.85rem; }

.book-dropdown-list {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1.5px solid var(--green);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(22,163,74,0.18);
  max-height: 220px;
  overflow-y: auto;
  z-index: 999;
  display: none;
}
.book-dropdown-list.open { display: block; }
.book-dropdown-list::-webkit-scrollbar { width: 5px; }
.book-dropdown-list::-webkit-scrollbar-thumb { background: var(--green-mid); border-radius: 4px; }

.book-option {
  padding: 0.5rem 0.8rem;
  font-size: 0.86rem;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text);
  border-bottom: 1px solid #f0fdf4;
}
.book-option:last-child { border-bottom: none; }
.book-option:hover, .book-option.highlighted { background: var(--green-light); color: var(--green-dark); font-weight: 600; }
.book-option.no-results { color: var(--text-light); cursor: default; font-style: italic; }
.book-option mark { background: #fef08a; border-radius: 2px; font-style: normal; }

/* hidden actual value holder */
.book-value-input { display: none; }

/* === NUMBER INPUTS === */
.book-row input[type="number"] {
  width: 100%;
  padding: 0.52rem 0.4rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: 'Nunito', sans-serif;
  text-align: center;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fff;
}
.book-row input[type="number"]:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}
.book-row input[type="number"]::-webkit-inner-spin-button { opacity: 0.5; }

/* === REMOVE BUTTON === */
.btn-remove {
  background: none;
  border: 1.5px solid #fca5a5;
  color: #ef4444;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  margin: auto;
}
.btn-remove:hover { background: #fef2f2; transform: scale(1.1); }

/* === FORM ACTIONS === */
.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
}
.form-actions button {
  flex: 1;
  min-width: 130px;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Nunito', sans-serif;
  font-size: 0.97rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}
#addBookBtn {
  background: var(--green-light);
  color: var(--green-dark);
  border: 1.5px solid var(--green-mid);
}
#addBookBtn:hover { background: #bbf7d0; transform: translateY(-1px); }

#submitBtn {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
  box-shadow: 0 3px 12px rgba(22,163,74,0.3);
}
#submitBtn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(22,163,74,0.35); }
#submitBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* === LOADER OVERLAY === */
.loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.25s ease;
}
.loader-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.loader-card {
  background: linear-gradient(135deg, #fff 0%, #f0fdf4 100%);
  border-radius: 20px;
  padding: 2.4rem 2rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(22,163,74,0.2), 0 4px 16px rgba(0,0,0,0.1);
  border: 2px solid var(--border);
  max-width: 300px;
  width: 90%;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* === LOTUS SPINNER === */
.lotus-spinner {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto 1.2rem;
}
.petal {
  position: absolute;
  width: 22px;
  height: 30px;
  background: linear-gradient(180deg, #86efac, var(--green));
  border-radius: 50% 50% 40% 40%;
  top: 0; left: 50%;
  transform-origin: 50% 100%;
  margin-left: -11px;
  opacity: 0.9;
}
.p1 { transform: rotate(0deg); }
.p2 { transform: rotate(60deg); }
.p3 { transform: rotate(120deg); }
.p4 { transform: rotate(180deg); }
.p5 { transform: rotate(240deg); }
.p6 { transform: rotate(300deg); }
.lotus-spinner { animation: rotateLotus 2s linear infinite; }
@keyframes rotateLotus { to { transform: rotate(360deg); } }
.center-circle {
  position: absolute;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #fcd34d, #d97706);
  border-radius: 50%;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px rgba(217,119,6,0.5);
}

.loader-title {
  font-family: 'Cinzel', serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 0.4rem;
}
.loader-sub {
  font-size: 1.15rem;
  color: var(--text-mid);
  margin-bottom: 0.3rem;
}
.loader-chant {
  font-size: 1.15rem;
  color: var(--gold);
  font-weight: 700;
  margin-top: 0.5rem;
}
.loader-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 1rem;
}
.loader-dots span {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: dot 1.2s ease-in-out infinite;
}
.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* === CONFIRM DIALOG === */
.confirm-card {
  background: #fff;
  border-radius: 20px;
  padding: 2rem 1.8rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  border: 2px solid var(--border);
  max-width: 320px;
  width: 90%;
  animation: slideUp 0.3s ease;
}
.confirm-icon { font-size: 2.4rem; margin-bottom: 0.6rem; }
.confirm-title {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 0.6rem;
}
.confirm-msg {
  font-size: 0.92rem;
  color: var(--text-mid);
  line-height: 1.6;
  margin-bottom: 1.4rem;
}
.confirm-actions {
  display: flex;
  gap: 0.75rem;
}
.btn-cancel-confirm, .btn-ok-confirm {
  flex: 1;
  padding: 0.7rem 0.5rem;
  border-radius: var(--radius-sm);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all 0.18s;
}
.btn-cancel-confirm {
  background: #f3f4f6;
  color: var(--text);
  border: 1.5px solid #e5e7eb;
}
.btn-cancel-confirm:hover { background: #e5e7eb; }
.btn-ok-confirm {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
  box-shadow: 0 3px 10px rgba(22,163,74,0.3);
}
.btn-ok-confirm:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(22,163,74,0.35); }

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--green-dark);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  z-index: 3000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }
.toast.error { background: #c0392b; }

/* === MOBILE === */
@media (max-width: 560px) {
  .main-container { padding: 1rem 0.6rem 3rem; }
  .form-card { padding: 1.2rem 0.85rem; }

  /* Hide table-style header on mobile — labels shown inline */
  .books-header { display: none; }

  /* Each book row stacks vertically */
  .book-row {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.9rem 0.85rem;
    border-bottom: 2px solid var(--green-light);
    position: relative;
  }

  /* Book search takes full width */
  .book-select-wrap { width: 100%; }
  .book-search-input {
    font-size: 0.95rem;
    padding: 0.65rem 0.85rem;
    width: 100%;
  }

  /* Dropdown gets generous height and scrolls smoothly */
  .book-dropdown-list {
    max-height: 260px;
    -webkit-overflow-scrolling: touch;
  }
  .book-option {
    padding: 0.65rem 0.9rem;
    font-size: 0.9rem;
  }

  /* Qty + Amount row side by side, Remove button on right */
  .book-row-bottom {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  /* Show mini labels on mobile */
  .field-mini-label { display: block; }

  /* Qty/Amount with inline label */
  .book-row .qty-wrap,
  .book-row .amt-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
  }
  .book-row .field-mini-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-left: 2px;
  }
  .book-row input[type="number"] {
    font-size: 0.95rem;
    padding: 0.6rem 0.5rem;
    width: 100%;
    text-align: left;
  }

  .btn-remove {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
    flex-shrink: 0;
    align-self: flex-end;
  }

  .field-label { min-width: 66px; font-size: 0.92rem; }
  .form-actions { flex-direction: column; }
  .form-actions button { flex: none; width: 100%; padding: 0.85rem 1rem; font-size: 1rem; }
  .loader-card { padding: 1.8rem 1.4rem; }
}

/* === SUMMARY BAR === */
.summary-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-top: 1rem;
  background: linear-gradient(135deg, #052e16 0%, #14532d 50%, #166534 100%);
  border-radius: var(--radius-sm);
  padding: 1rem 1.4rem;
  box-shadow:
    0 4px 20px rgba(22,163,74,0.25),
    0 1px 4px rgba(0,0,0,0.15),
    inset 0 1px 0 rgba(255,255,255,0.08);
  position: relative;
  overflow: hidden;
}
/* subtle shimmer line at top */
.summary-bar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #86efac, #fcd34d, #86efac, transparent);
}
.summary-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  justify-content: center;
}
.summary-icon {
  font-size: 1.6rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}
.summary-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.summary-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #86efac;
  line-height: 1;
}
.summary-value {
  font-family: 'Cinzel', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
  transition: all 0.3s ease;
  text-shadow: 0 1px 6px rgba(0,0,0,0.3);
}
.summary-value.bump {
  transform: scale(1.15);
  color: #fcd34d;
}
.summary-divider {
  width: 1px;
  height: 44px;
  background: linear-gradient(to bottom, transparent, rgba(134,239,172,0.4), transparent);
  margin: 0 0.5rem;
  flex-shrink: 0;
}

@media (max-width: 560px) {
  .summary-bar { padding: 0.9rem 1rem; gap: 0; }
  .summary-icon { font-size: 1.35rem; }
  .summary-value { font-size: 1.2rem; }
  .summary-label { font-size: 0.68rem; }
}