/* ============================================================
   styles.css — OurCart orange/black · warm light
   ============================================================ */

:root {
  --accent:       #ff6a00;
  --accent-hover: #f04f00;
  --accent-rgb:   255,106,0;
  --accent-glow:  rgba(255,106,0,0.18);
  --accent-ring:  rgba(255,106,0,0.28);
  --green:        #22c55e;
  --red:          #ef4444;
  --chat-keyboard-offset: 0px;
}
html.dark {
  --accent:       #ff6a00;
  --accent-hover: #ff4d00;
  --accent-rgb:   255,106,0;
  --accent-glow:  rgba(255,106,0,0.16);
  --accent-ring:  rgba(255,106,0,0.3);
}

/* Fill status-bar area with app background (PWA iPhone notch fix) */
html            { background: #fff8f2; }
html.dark       { background: #050505; }
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

*, *::before, *::after {
  transition: background-color 0.22s ease, border-color 0.22s ease,
              color 0.15s ease, box-shadow 0.22s ease;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  /* Push all content below the iPhone status bar / Dynamic Island */
  padding-top: constant(safe-area-inset-top);
  padding-top: env(safe-area-inset-top, 0px);
}
.app-chrome {
  background: inherit;
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 32rem;
  z-index: 40;
}
#mainScroll {
  padding-top: var(--app-chrome-height, 116px);
}
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border-radius: 9999px; background: #4a4a4a; }
html:not(.dark) ::-webkit-scrollbar-thumb { background: #fed7aa; }

/* ── Glass card ─────────────────────────────────────────────── */
.glass-card {
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(251,146,60,0.24);
  box-shadow: 0 2px 16px rgba(255,106,0,0.06);
}
.glass-card:hover {
  background: rgba(255,255,255,0.88);
  border-color: rgba(251,146,60,0.42);
}

.payment-card {
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(251,146,60,0.24);
  border-radius: 20px;
  box-shadow: 0 10px 32px rgba(255,106,0,0.08);
}
html.dark .payment-card {
  background: rgba(18,18,18,0.94);
  border-color: rgba(38,38,38,1);
  box-shadow: none;
}
.payment-details {
  background: rgba(255,247,237,0.74);
  border: 1px solid rgba(251,146,60,0.22);
  font-size: 13px;
}
html.dark .payment-details {
  background: rgba(12,12,12,0.9);
  border-color: rgba(36,36,36,1);
}
.payment-review-card {
  border: 1px solid rgba(251,146,60,0.22);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255,255,255,0.64);
}
html.dark .payment-review-card {
  border-color: rgba(38,38,38,1);
  background: rgba(14,14,14,0.9);
}
html.dark .glass-card {
  background: rgba(18,18,18,0.88);
  backdrop-filter: none;
  border: 1px solid rgba(38,38,38,1);
  box-shadow: none;
}
html.dark .glass-card:hover {
  border-color: rgba(255,106,0,0.22);
  background: rgba(24,24,24,0.98);
}

.glass-card-faded {
  background: rgba(255,247,237,0.5);
  border: 1px solid rgba(251,146,60,0.18);
}
html.dark .glass-card-faded {
  background: rgba(14,14,14,0.75);
  border: 1px solid rgba(30,30,30,1);
}

.smart-card {
  background: rgba(255,255,255,0.68);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(251,146,60,0.22);
  border-radius: 20px;
  overflow: hidden;
}
html.dark .smart-card {
  background: rgba(16,16,16,0.92);
  backdrop-filter: none;
  border: 1px solid rgba(35,35,35,1);
}

/* ── Accent button ──────────────────────────────────────────── */
.btn-accent {
  background: var(--accent);
  box-shadow: 0 3px 18px var(--accent-glow);
  color: #fff;
  font-weight: 600;
}
.btn-accent:hover  { background: var(--accent-hover); }
.btn-accent:active { filter: brightness(0.88); }
.btn-accent:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

@keyframes glowPulse {
  0%,100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50%      { box-shadow: 0 0 0 9px transparent; }
}
#addBtn:not(:disabled) { animation: glowPulse 2.8s ease-in-out infinite; }
#addBtn:hover, #addBtn:active { animation: none; }

/* ── Input wrap ─────────────────────────────────────────────── */
.input-wrap {
  border: 1.5px solid;
  transition: border-color 0.2s, box-shadow 0.2s;
  border-radius: 9999px;
}
.input-wrap:focus-within {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
html:not(.dark) .input-wrap {
  background: rgba(255,255,255,0.82);
  border-color: rgba(251,146,60,0.55);
}
html.dark .input-wrap {
  background: rgba(16,16,16,0.92);
  border-color: rgba(42,42,42,1);
}

/* ── Price input (inline in bills) ─────────────────────────── */
.price-input-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid;
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.price-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-ring);
}
html:not(.dark) .price-input-wrap {
  background: rgba(255,255,255,0.9);
  border-color: rgba(251,146,60,0.5);
}
html.dark .price-input-wrap {
  background: rgba(22,22,22,1);
  border-color: rgba(45,45,45,1);
}

.price-input-wrap span {
  font-weight: 700;
  font-size: 14px;
  padding: 0 6px 0 10px;
  color: var(--accent);
  user-select: none;
}
.price-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 10px 8px 0;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}
html:not(.dark) .price-input-wrap input { color: #0f172a; }
html.dark .price-input-wrap input { color: #f1f5f9; }

/* ── Tab active indicator ───────────────────────────────────── */
.tab-active {
  position: relative;
  color: var(--accent) !important;
}
.tab-active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px;
  border-radius: 9999px;
  background: var(--accent);
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.item-enter { animation: slideIn 0.24s ease forwards; }

@keyframes buyCheck {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.18); }
  60%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.item-buying { animation: buyCheck 0.35s ease; }

@keyframes slideOut {
  from { opacity: 1; transform: translateX(0) scale(1); max-height: 80px; }
  to   { opacity: 0; transform: translateX(60px) scale(0.95); max-height: 0; padding: 0; margin: 0; }
}
.item-exit { animation: slideOut 0.32s ease forwards; pointer-events: none; overflow: hidden; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up            { animation: fadeUp 0.28s ease forwards; }
.fade-up-delay-1    { animation: fadeUp 0.28s 0.06s ease both; }
.fade-up-delay-2    { animation: fadeUp 0.28s 0.12s ease both; }
.fade-up-delay-3    { animation: fadeUp 0.28s 0.18s ease both; }
.fade-up-delay-4    { animation: fadeUp 0.28s 0.24s ease both; }

@keyframes shake {
  0%,100%{ transform:translateX(0); }
  20%    { transform:translateX(-6px); }
  40%    { transform:translateX(6px); }
  60%    { transform:translateX(-4px); }
  80%    { transform:translateX(4px); }
}
.shake { animation: shake 0.35s ease; }

/* ── Skeleton ───────────────────────────────────────────────── */
@keyframes skelPulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.skeleton {
  background: rgba(251,146,60,0.22);
  animation: skelPulse 1.4s ease-in-out infinite;
  border-radius: 16px;
}
html.dark .skeleton { background: rgba(28,28,28,0.9); }

/* ── Toast ──────────────────────────────────────────────────── */
#toast { transition: opacity 0.28s ease, transform 0.28s ease; }
#toast.show { opacity:1; transform:translateY(0) translateX(-50%); }
#toast.hide { opacity:0; transform:translateY(-14px) translateX(-50%); }
#toast.has-action { pointer-events: auto; }
#toastAction {
  background: rgba(255,255,255,0.2);
  color: inherit;
  pointer-events: auto;
}

/* ── Spinner ────────────────────────────────────────────────── */
@keyframes spin { to { transform:rotate(360deg); } }
.spinner {
  width:18px; height:18px;
  border:2px solid transparent;
  border-top-color: currentColor;
  border-radius:50%;
  animation: spin 0.7s linear infinite;
  display:inline-block;
}

/* ── Code font ──────────────────────────────────────────────── */
.code-font { font-family:'SF Mono','Fira Code',monospace; letter-spacing:.18em; }
.input-bar {
  width: 100%;
  max-width: min(32rem, 100vw);
  box-sizing: border-box;
  padding-bottom: env(safe-area-inset-bottom,0px);
  will-change: transform;
  transition: transform 0.18s ease;
}
#itemInput,
#chatInput {
  font-size: 16px;
  line-height: 1.4;
}
@media (min-width: 640px) {
  #itemInput,
  #chatInput {
    font-size: 14px;
  }
}
.modal-backdrop { backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px); }
.settings-card {
  max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
}
.settings-scroll {
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}
.notification-settings button {
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}
.chat-compose-row {
  min-width: 0;
}
.chat-icon-btn {
  width: 44px;
  height: 44px;
}
@media (max-width: 380px) {
  .chat-compose-row { gap: 0.4rem; }
  .chat-icon-btn {
    width: 40px;
    height: 40px;
  }
  #chatInputWrapper .bottom-bar {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  #chatInputWrapper .input-wrap {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* ── Chat ───────────────────────────────────────────────────── */
.chat-bubble {
  max-width: 82%;
  border-radius: 18px;
  padding: 9px 12px 7px;
  word-break: break-word;
  touch-action: pan-y;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.chat-row.reply-armed .chat-bubble {
  transform: translateX(46px);
  box-shadow: 0 0 0 2px var(--accent-ring);
}
.chat-panel {
  padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px) + var(--chat-keyboard-offset));
  overflow-x: hidden;
}
.chat-history-loader {
  width: fit-content;
  max-width: 86%;
  margin: 0 auto 10px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  color: #64748b;
  background: rgba(255,255,255,0.68);
  border: 1px solid rgba(251,146,60,0.45);
}
html.dark .chat-history-loader {
  color: #9ca3af;
  background: rgba(20,20,20,0.92);
  border-color: rgba(42,42,42,1);
}
.chat-mine {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.chat-theirs {
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(251,146,60,0.5);
  color: #0f172a;
  border-bottom-left-radius: 6px;
}
html.dark .chat-theirs {
  background: rgba(22,22,22,0.96);
  border-color: rgba(40,40,40,1);
  color: #f1f5f9;
}
.chat-sender {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}
.chat-body {
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
}
.chat-photo {
  display: block;
  width: min(260px, 68vw);
  max-height: 320px;
  object-fit: cover;
  border-radius: 14px;
  margin: 2px 0 7px;
  background: rgba(255,255,255,0.14);
  cursor: zoom-in;
}
.chat-photo.loading {
  min-height: 160px;
}
.chat-photo-caption {
  margin-top: 2px;
}
.chat-meta {
  font-size: 10px;
  opacity: 0.66;
  margin-top: 4px;
  text-align: right;
}
.quoted-message {
  border-left: 3px solid rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.16);
  border-radius: 10px;
  padding: 6px 8px;
  margin-bottom: 6px;
}
.chat-theirs .quoted-message {
  border-left-color: var(--accent);
  background: rgba(255,106,0,0.08);
}
html.dark .chat-theirs .quoted-message {
  background: rgba(255,106,0,0.08);
}
.quoted-name {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  margin-bottom: 1px;
}
.quoted-body {
  font-size: 11px;
  opacity: 0.8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-preview {
  border-radius: 14px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(251,146,60,0.55);
}
.photo-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 14px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(251,146,60,0.55);
}
.photo-preview.hidden {
  display: none;
}
.photo-preview img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
}
html.dark .reply-preview,
html.dark .photo-preview {
  background: rgba(18,18,18,0.96);
  border-color: rgba(42,42,42,1);
}
.reply-accent {
  width: 3px;
  align-self: stretch;
  border-radius: 999px;
  background: var(--accent);
}
#replyPreviewName { color: var(--accent); }
#replyPreviewText { color: #64748b; }
html.dark #replyPreviewText { color: #9ca3af; }
#photoPreviewMeta { color: #64748b; }
html.dark #photoPreviewMeta { color: #9ca3af; }
.reply-close {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #64748b;
  font-size: 18px;
  line-height: 1;
}
html.dark .reply-close { color: #9ca3af; }
.photo-picker-sheet {
  background: rgba(255,250,245,0.98);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid rgba(251,146,60,0.5);
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
html.dark .photo-picker-sheet {
  background: rgba(10,10,10,0.99);
  border-top-color: rgba(30,30,30,1);
}
.photo-picker-option,
.photo-picker-cancel {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  font-weight: 700;
}
.photo-picker-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(251,146,60,0.55);
}
html.dark .photo-picker-option {
  background: rgba(18,18,18,0.96);
  border-color: rgba(42,42,42,1);
}
.photo-picker-cancel {
  color: var(--accent);
}
.photo-viewer {
  background: rgba(0,0,0,0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 14px calc(18px + env(safe-area-inset-bottom, 0px));
}
.photo-viewer.hidden {
  display: none;
}
.photo-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 12px;
}
.photo-viewer-close {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  color: white;
  font-size: 30px;
  line-height: 1;
  z-index: 1;
}

/* ── Unpriced item row ──────────────────────────────────────── */
.unpriced-row {
  padding: 10px 0;
  border-bottom: 1px solid;
}
html:not(.dark) .unpriced-row { border-color: rgba(251,146,60,0.3); }
html.dark .unpriced-row { border-color: rgba(35,35,35,1); }
.unpriced-row:last-child { border-bottom: none; }

/* ── Compact field inputs (qty/unit/rate in bills) ─────────────── */
.field-input {
  border: 1.5px solid;
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 13px;
  text-align: center;
  min-width: 0;
  background: transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}
html:not(.dark) .field-input { border-color: rgba(251,146,60,0.5); color: #0f172a; }
html.dark .field-input { border-color: rgba(50,50,50,1); color: #f1f5f9; }
.field-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); outline: none; }

/* ── Running total bar ──────────────────────────────────────── */
.total-bar {
  border-top: 1.5px solid;
  margin-top: 4px;
  padding-top: 12px;
}
html:not(.dark) .total-bar { border-color: rgba(251,146,60,0.4); }
html.dark .total-bar { border-color: rgba(45,45,45,1); }

/* ── Chart bars ─────────────────────────────────────────────── */
.bar-track {
  height: 7px; border-radius: 9999px; overflow: hidden;
  background: rgba(251,146,60,0.25);
}
html.dark .bar-track { background: rgba(40,40,40,1); }
.bar-fill {
  height: 100%; border-radius: 9999px; background: var(--accent);
  transition: width 0.9s cubic-bezier(0.34,1.56,0.64,1);
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge-due   { background: rgba(255,106,0,0.12); color: #f04f00; border: 1px solid rgba(255,106,0,0.25); }
.badge-good  { background: rgba(34,197,94,0.12);  color: #16a34a; border: 1px solid rgba(34,197,94,0.25); }
.badge-info  { background: rgba(255,106,0,0.12); color: #f04f00; border: 1px solid rgba(255,106,0,0.25); }
html.dark .badge-due   { color: #fb923c; }
html.dark .badge-good  { color: #4ade80; }
html.dark .badge-info  { color: #60a5fa; }

.section-header {
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #64748b; padding: 0 4px; margin-bottom: 8px;
}
html.dark .section-header { color: #4b5563; }

.price-tag {
  font-size: 13px; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.store-chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 9999px;
  background: rgba(255,106,0,0.1); color: #ff6a00; border: 1px solid rgba(255,106,0,0.2);
}
html.dark .store-chip {
  background: rgba(255,106,0,0.1); color: #ff6a00; border-color: rgba(255,106,0,0.2);
}

.divider { height: 1px; background: rgba(251,146,60,0.3); margin: 6px 0; }
html.dark .divider { background: rgba(35,35,35,1); }

.add-mini-btn {
  font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 9999px;
  border: 1.5px solid var(--accent); color: var(--accent); background: transparent;
  transition: all 0.18s; white-space: nowrap; flex-shrink: 0;
}
.add-mini-btn:hover { background: var(--accent); color: #fff; }

.day-header {
  font-size: 12px; font-weight: 700; padding: 12px 4px 6px; color: #64748b;
  display: flex; align-items: center; justify-content: space-between;
}
html.dark .day-header { color: #4b5563; }

.total-chip {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 9999px;
  background: rgba(34,197,94,0.1); color: #16a34a; border: 1px solid rgba(34,197,94,0.2);
}
html.dark .total-chip { color: #4ade80; border-color: rgba(74,222,128,0.2); background: rgba(74,222,128,0.08); }

.summary-bar {
  background: rgba(255,255,255,0.6); border: 1px solid rgba(251,146,60,0.4);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
html.dark .summary-bar { background: rgba(18,18,18,0.9); border-color: rgba(35,35,35,1); }

input:focus { outline: none; }

/* ── Mobile-first bill fixes ────────────────────────────────────── */

/* Summary bar: stack on very small screens */
@media (max-width: 360px) {
  .summary-bar { flex-direction: column; gap: 8px; }
  .summary-bar .w-px { display: none; }
}

/* Bill edit button: always visible on touch, fade on desktop */
.bill-edit-btn {
  opacity: 0.35;
  transition: opacity 0.18s;
}
.bill-edit-btn:hover,
.bill-edit-btn:active { opacity: 1; }
@media (hover: hover) {
  .bill-item-row .bill-edit-btn { opacity: 0; }
  .bill-item-row:hover .bill-edit-btn { opacity: 1; }
}

/* Bill edit form: tighter on small screens */
.bill-edit-form-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.bill-edit-label {
  width: 36px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
}
html.dark .bill-edit-label { color: #4b5563; }

/* Rate total preview */
.rate-total-preview {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 0;
}

/* Truncate meta line in bill history */
.bill-meta { 
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
