/* ============== RESET & VARIABLES ============== */

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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #f0f0f0;
  --muted: #8b949e;
  --green: #4ade80;
  --yellow: #facc15;
  --blue: #3b82f6;
  --red: #f87171;
}

/* ============== BASE ============== */

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

/* ============== HEADER ============== */

header {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.product-count {
  background: #1e2a3a;
  color: var(--green);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 3px 12px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.product-count:hover:not(.loading):not(.error) {
  border-color: var(--green);
  background: #1c3324;
}

.product-count::after {
  content: ' ▾';
  opacity: 0.6;
  font-size: 11px;
}

.product-count.loading::after,
.product-count.error::after {
  content: '';
}

/* ============== MAIN LAYOUT ============== */

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ============== MIC BUTTON ============== */

.mic-button {
  width: 120px;
  height: 120px;
  background: var(--green);
  color: #000;
  font-size: 48px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: block;
  margin: 40px auto;
  transition: transform 0.15s ease, background 0.15s ease;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4);
  line-height: 1;
}

.mic-button:hover {
  transform: scale(1.05);
}

.mic-button:active {
  transform: scale(0.97);
}

.mic-button.recording {
  animation: mic-pulse 1.5s infinite;
  background: #22c55e;
}

@keyframes mic-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4);
  }
  70% {
    box-shadow: 0 0 0 20px rgba(74, 222, 128, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
  }
}

/* ============== TRANSCRIPT ============== */

.transcript {
  min-height: 40px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 24px;
  text-align: center;
  font-style: italic;
}

/* ============== UTILITY ============== */

.hidden {
  display: none !important;
}

/* ============== BATCH ITEMS ============== */

.batch-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.batch-item .status-icon {
  width: 24px;
  font-size: 18px;
  flex-shrink: 0;
  text-align: center;
}

.batch-item .info {
  flex: 1;
  min-width: 0;
}

.batch-item .product-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.batch-item .price-change {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.batch-item .price-change .old-price {
  text-decoration: line-through;
}

.batch-item .price-change .arrow {
  margin: 0 4px;
}

.batch-item .price-change .new-price {
  color: var(--green);
  font-weight: 600;
}

/* Status variants */
.batch-item.status-ambiguous {
  border-color: var(--yellow);
}

.batch-item.status-ambiguous .status-icon {
  color: var(--yellow);
}

.batch-item.status-ready .status-icon {
  color: var(--green);
}

.batch-item.status-editing {
  border-color: var(--blue);
}

.batch-item.status-error {
  border-color: var(--red);
}

.batch-item.status-error .status-icon {
  color: var(--red);
}

.batch-item.status-done {
  opacity: 0.6;
}

/* ============== PRODUCT CHIPS ============== */

.product-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  padding: 3px 10px;
  border-radius: 12px;
  background: #1e293b;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  transition: border-color 0.15s, color 0.15s;
}

.chip:hover,
.chip.selected {
  border-color: var(--green);
  color: var(--green);
}

/* ============== ACTION BUTTONS ============== */

.action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.action-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

/* ============== INLINE EDIT ============== */

.inline-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.inline-edit input {
  width: 80px;
  background: var(--surface);
  border: 1px solid var(--blue);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
}

.inline-edit input:focus {
  border-color: var(--green);
}

.inline-edit .ok-btn {
  background: var(--blue);
  border: none;
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.inline-edit .ok-btn:hover {
  background: #2563eb;
}

/* ============== BOTTOM BAR ============== */

#bottom-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

#add-more-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.15s;
  white-space: nowrap;
}

#add-more-btn:hover {
  border-color: var(--green);
}

#confirm-btn {
  background: var(--green);
  border: none;
  color: #000;
  padding: 10px 24px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  flex: 1;
  transition: background 0.15s;
}

#confirm-btn:hover:not(:disabled) {
  background: #22c55e;
}

#confirm-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

/* ============== TOAST ============== */

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}

.toast.success {
  background: #166534;
  color: #4ade80;
  border: 1px solid #4ade80;
}

.toast.error {
  background: #7f1d1d;
  color: #f87171;
  border: 1px solid #f87171;
}

.toast.info {
  background: #1e3a5f;
  color: #93c5fd;
  border: 1px solid #3b82f6;
}

/* ============== PRODUCT COUNT STATES ============== */

.product-count.loading {
  color: var(--muted);
  animation: badge-pulse 1s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.product-count.error {
  color: var(--red);
  background: rgba(248, 113, 113, 0.08);
}

.retry-btn {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 1px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  margin-left: 6px;
  transition: background 0.15s;
}

.retry-btn:hover {
  background: rgba(248, 113, 113, 0.15);
}

/* ============== MIC DISABLED STATE ============== */

.mic-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: var(--border);
  box-shadow: none;
  animation: none !important;
}

/* ============== REGISTER PRODUCT FORM ============== */

.create-product-prompt {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-top: 24px;
  text-align: center;
}

.create-product-prompt p {
  color: var(--text);
  margin-bottom: 16px;
  font-size: 15px;
}

.create-product-prompt .btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-sim {
  background: var(--green);
  color: #000;
  border: none;
  padding: 8px 24px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

.btn-sim:hover { background: #22c55e; }

.btn-nao {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.15s;
}

.btn-nao:hover { border-color: var(--text); color: var(--text); }

.create-product-form {
  background: var(--surface);
  border: 1px solid var(--blue);
  border-radius: 12px;
  padding: 20px;
  margin-top: 24px;
}

.create-product-form h3 {
  color: var(--text);
  font-size: 15px;
  margin-bottom: 16px;
}

.create-product-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.create-product-form input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  margin-bottom: 12px;
}

.create-product-form input:focus {
  border-color: var(--blue);
}

.create-product-form .btn-confirmar {
  width: 100%;
  background: var(--green);
  color: #000;
  border: none;
  padding: 10px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s;
}

.create-product-form .btn-confirmar:hover { background: #22c55e; }
.create-product-form .btn-confirmar:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

/* ============== PRODUCT LIST OVERLAY ============== */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 16px;
}

.overlay-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.overlay-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.close-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}

.close-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

#product-search {
  margin: 12px 16px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  flex-shrink: 0;
}

#product-search:focus {
  border-color: var(--green);
}

.sort-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 16px 8px;
  flex-shrink: 0;
}

.sort-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.sort-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

.sort-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #000;
  font-weight: 600;
}

.results-count {
  padding: 4px 16px 6px;
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.product-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
}

.product-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}

.product-row:last-child { border-bottom: none; }

.product-row-info {
  flex: 1;
  min-width: 0;
}

.product-row-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-row-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-row-price {
  color: var(--green);
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.product-row-stock-low {
  color: var(--yellow);
  margin-left: 6px;
}

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

@media (max-width: 480px) {
  .overlay { padding: 0; }
  .overlay-content { border-radius: 0; max-width: none; }
}

/* ============== CONFIRMATION MODAL ============== */

.confirm-card {
  max-width: 460px;
  align-self: center;
  margin: auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--green);
  border-radius: 16px;
}

.confirm-card h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 16px;
}

#confirm-product-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
}

.confirm-product-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.confirm-product-prices {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
}

.confirm-product-prices .old-price {
  color: var(--muted);
  text-decoration: line-through;
}

.confirm-product-prices .arrow { color: var(--muted); }

.confirm-product-prices .new-price {
  color: var(--green);
  font-weight: 700;
  font-size: 20px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.btn-confirm-yes {
  flex: 1;
  background: var(--green);
  color: #000;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-confirm-yes:hover { background: #22c55e; }

.btn-confirm-no {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.btn-confirm-no:hover { border-color: var(--text); color: var(--text); }

.confirm-hint {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

/* AI thinking indicator in transcript area */
.transcript.thinking::after {
  content: ' 🧠';
  animation: badge-pulse 1s ease-in-out infinite;
}

/* ============== ITEM SPINNER ============== */

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

/* ============== RESPONSIVE ============== */

@media (max-width: 480px) {
  .mic-button {
    width: 90px;
    height: 90px;
    font-size: 36px;
  }

  main {
    padding: 16px 12px;
  }

  #bottom-bar {
    flex-direction: column;
  }

  #add-more-btn {
    width: 100%;
    text-align: center;
  }

  #confirm-btn {
    width: 100%;
  }
}

/* PIN dialog */
#pin-form { padding: 20px; gap: 10px; }
#pin-form h2 { text-align: center; }
#pin-input {
  width: 100%;
  padding: 12px;
  font-size: 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg, #0d1117);
  color: var(--text);
}

/* Stock lines in the review screen / confirm modal */
.stock-change { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.stock-delta { color: var(--muted); font-size: 13px; }
.stock-warning { color: var(--red); font-size: 13px; margin-top: 4px; }
