/* BillScan – mobile-first */

* {
  box-sizing: border-box;
}

/* Bootstrap Icons spacing */
.bi {
  margin-right: 0.35em;
  vertical-align: -0.15em;
}
.bi:last-child {
  margin-right: 0;
}
#logout-btn .bi {
  margin-right: 0.25em;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #1a1a1a;
  background: #f5f5f5;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-box {
  width: 100%;
  max-width: 320px;
  background: #fff;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.login-box h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.login-sub {
  margin: 0 0 1.25rem;
  color: #666;
  font-size: 0.9rem;
}

.login-box label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.login-box input {
  width: 100%;
  padding: 0.5rem 0.6rem;
  margin-top: 0.25rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

.login-box button {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.login-box button:active {
  background: #1d4ed8;
}

.login-box .error {
  margin-top: 0.75rem;
  color: #b91c1c;
  font-size: 0.9rem;
}

/* App header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: #1e3a5f;
  color: #fff;
}

.app-header .logo {
  font-weight: 700;
  font-size: 1.25rem;
}

.header-logout {
  margin-left: auto;
}

#logout-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 4px;
  cursor: pointer;
}

#logout-btn:hover {
  background: rgba(255,255,255,0.1);
}

/* Sections */
.section {
  padding: 1rem;
  margin-bottom: 0.5rem;
  background: #fff;
}

.section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: #374151;
}

/* Camera */
.camera-area {
  position: relative;
  background: #111;
  border-radius: 8px;
  overflow: hidden;
  min-height: 200px;
}

#camera-preview {
  display: block;
  width: 100%;
  min-height: 200px;
  max-height: 50vh;
  object-fit: cover;
  background: #000;
}

#camera-preview.visible {
  display: block;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
  font-size: 0.9rem;
  padding: 1rem;
  pointer-events: none;
}

.camera-area .camera-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  flex-wrap: wrap;
}

.camera-area button {
  padding: 0.6rem 1rem;
  font-size: 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.camera-area button:active {
  background: #1d4ed8;
}

.camera-area button.secondary {
  background: #6b7280;
}

.last-capture {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: #666;
}

/* Lists */
.screenshots-list,
.reviews-list,
.ready-list,
.qif-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.screenshots-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.75rem;
}

.screenshot-thumb {
  position: relative;
  padding: 0;
  border: none;
}

.screenshot-thumb-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  display: flex;
  gap: 4px;
}

.screenshot-analyze-btn,
.screenshot-delete-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.screenshot-analyze-btn .bi,
.screenshot-delete-btn .bi {
  margin: 0;
  font-size: 0.9rem;
}

.screenshot-analyze-btn {
  background: rgba(37, 99, 235, 0.9);
  color: #fff;
}

.screenshot-analyze-btn:hover {
  background: #2563eb;
}

.screenshot-thumb.analyzed .screenshot-analyze-btn {
  background: #6b7280;
}

.screenshot-thumb.analyzed .screenshot-analyze-btn:hover {
  background: #4b5563;
}

.screenshot-analyze-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.screenshot-delete-btn {
  background: rgba(185, 28, 28, 0.9);
  color: #fff;
}

.screenshot-delete-btn:hover {
  background: #b91c1c;
}

.screenshot-thumb-link {
  display: block;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: #eee;
}

.screenshot-thumb-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.screenshot-thumb-date {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: #666;
}

/* Analyzing overlay on thumbnail */
.screenshot-thumb.analyzing {
  pointer-events: none;
}

.screenshot-analyzing-overlay {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: rgba(30, 58, 95, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  z-index: 3;
}

.screenshot-analyzing-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: screenshot-spin 0.8s linear infinite;
}

.screenshot-analyzing-text {
  font-size: 0.7rem;
  color: #fff;
  font-weight: 500;
}

@keyframes screenshot-spin {
  to {
    transform: rotate(360deg);
  }
}

.screenshots-list li.empty-hint {
  grid-column: 1 / -1;
}

.reviews-list li,
.ready-list li,
.qif-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid #eee;
}

.reviews-list li .list-item-content,
.ready-list li .list-item-content,
.qif-list li .list-item-content {
  flex: 1;
  min-width: 0;
}

.reviews-list li {
  cursor: pointer;
}

.reviews-list .list-remove-btn,
.ready-list .list-remove-btn,
.qif-list .list-remove-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: #6b7280;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.ready-list .list-return-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: #6b7280;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.ready-list .list-return-btn:hover {
  background: #dbeafe;
  color: #2563eb;
}

.ready-list .list-return-btn .bi {
  margin: 0;
  font-size: 1rem;
}

.ready-list .list-exported-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: #059669;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.ready-list .list-exported-btn:hover {
  background: #d1fae5;
  color: #047857;
}

.ready-list .list-exported-btn .bi {
  margin: 0;
  font-size: 1rem;
}

.reviews-list .list-image-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: #6b7280;
  border-radius: 4px;
  text-decoration: none;
}

.reviews-list .list-image-btn:hover {
  background: #e5e7eb;
}

.reviews-list .list-remove-btn:hover,
.ready-list .list-remove-btn:hover,
.qif-list .list-remove-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.reviews-list .list-remove-btn .bi,
.ready-list .list-remove-btn .bi,
.qif-list .list-remove-btn .bi {
  margin: 0;
  font-size: 1rem;
}

.reviews-list li:last-child,
.ready-list li:last-child,
.qif-list li:last-child {
  border-bottom: none;
}

#export-qif-btn {
  margin-top: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  background: #059669;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#export-qif-btn:active {
  background: #047857;
}

.empty-hint {
  color: #888;
  font-size: 0.9rem;
}

/* Review modal */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-content-fullwidth {
  max-width: 100%;
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
}

.review-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
}

.review-form-field {
  flex: 1;
  min-width: 0;
}

.review-form-field label {
  margin-top: 0;
}

.review-form-field input,
.review-form-field select {
  margin-top: 0.25rem;
}

.review-items-label {
  display: block;
  margin-top: 1rem;
}

.review-items-table {
  width: 100%;
  margin-top: 0.5rem;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.review-items-table thead th {
  text-align: left;
  padding: 0.5rem 0.5rem 0.35rem;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
}

.review-items-table .col-amount {
  width: 100px;
}

.review-items-table .col-category {
  min-width: 180px;
}

.review-items-table .col-actions {
  width: 44px;
  text-align: right;
  padding-right: 0.25rem;
}

.review-items-table tbody td {
  padding: 0.35rem 0;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}

.review-items-table tbody .review-item-row input,
.review-items-table tbody .review-item-row select {
  width: 100%;
  margin: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}

/* Category autocomplete */
.autocomplete-wrap {
  position: relative;
  width: 100%;
}

.autocomplete-wrap .item-category {
  width: 100%;
  box-sizing: border-box;
}

.autocomplete-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 10;
  margin: 0;
  padding: 0;
  list-style: none;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.autocomplete-item {
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.autocomplete-item:hover,
.autocomplete-item:focus {
  background: #eff6ff;
  outline: none;
}

.review-items-table .col-amount input {
  text-align: right;
}

.modal-content h3 {
  margin: 0 0 1rem;
  font-size: 1.2rem;
}

.review-extraction-warning {
  margin: 0 0 1rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  white-space: pre-line;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  color: #6b7280;
}

.review-extraction-warning.review-extraction-warning-mismatch {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

.review-extraction-warning[hidden] {
  display: none !important;
}

.review-field-info {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: #6b7280;
  line-height: 1.35;
}

.review-field-info[hidden] {
  display: none !important;
}

.modal-content label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.modal-content input[type="text"],
.modal-content input[type="number"],
.modal-content select {
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.25rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

.review-item-row .remove-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  color: #6b7280;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.review-item-row .remove-item:hover {
  background: #fee2e2;
  color: #dc2626;
}

.review-item-row .remove-item .bi {
  margin: 0;
  font-size: 1.1rem;
}

#review-add-item {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  background: #6b7280;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #eee;
}

.modal-actions button {
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#review-save {
  background: #2563eb;
  color: #fff;
}

#review-reviewed {
  background: #059669;
  color: #fff;
}

#review-close {
  background: #6b7280;
  color: #fff;
}

/* Overlay popup (alert / confirm / prompt) */
.popup-overlay[hidden] {
  display: none !important;
}

.popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.popup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.popup-card {
  position: relative;
  width: 100%;
  max-width: 320px;
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.popup-message {
  margin: 0 0 1rem;
  font-size: 1rem;
  line-height: 1.45;
  color: #1a1a1a;
  white-space: pre-wrap;
  word-break: break-word;
}

.popup-input {
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
}

.popup-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.popup-btn {
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.popup-btn-ok {
  background: #2563eb;
  color: #fff;
}

.popup-btn-ok:hover {
  background: #1d4ed8;
}

.popup-btn-cancel {
  background: #e5e7eb;
  color: #374151;
}

.popup-btn-cancel:hover {
  background: #d1d5db;
}
