﻿:root {
  --paper: #F6F3EC;
  --ink: #22261F;
  --brand: #2F5233;
  --stamp: #B0402A;
  --muted: #8B8578;
  --line: #D8D2C2;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(transparent, transparent 27px, var(--line) 28px);
  background-attachment: local;
  overflow-x: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}

.bb-bg { background-color: var(--paper); }
.text-ink { color: var(--ink); }
.text-brand { color: var(--brand); }
.border-brand { border-color: var(--brand); }

.font-mono { font-family: 'Space Mono', monospace; }

.page-header {
  padding-top: var(--safe-top);
}

.page-main {
  padding-bottom: calc(2rem + var(--safe-bottom));
}

.stamp-mark {
  width: 34px; height: 34px;
  border-radius: 999px;
  border: 2px dashed var(--stamp);
  color: var(--stamp);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  transform: rotate(-8deg);
  flex-shrink: 0;
}

.tab-nav {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 8px 12px;
  border-radius: 4px;
  color: color-mix(in srgb, var(--ink) 55%, transparent);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color .15s ease, color .15s ease;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tab-btn:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.tab-btn.active {
  background: var(--ink);
  color: var(--paper);
}

.bb-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 0 var(--line);
}

.bb-label {
  display: block;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.bb-input {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 8px 2px;
  outline: none;
  font-family: 'Space Mono', monospace;
  font-size: 16px; /* prevents iOS zoom on focus */
}
.bb-input:focus { border-color: var(--brand); }

select.bb-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238B8578' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  padding-right: 20px;
}

.bb-btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand);
  color: #fff;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 12px 16px;
  border-radius: 6px;
  transition: filter .15s ease;
  border: none;
  cursor: pointer;
  min-height: 44px;
  text-align: center;
}
.bb-btn-primary:hover { filter: brightness(1.12); }
.bb-btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.bb-btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(26, 26, 26, 0.2);
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 12px 16px;
  border-radius: 6px;
  transition: border-color .15s ease, background .15s ease;
  cursor: pointer;
  min-height: 44px;
  text-align: center;
}
.bb-btn-secondary:hover {
  border-color: var(--brand);
  background: rgba(47, 82, 51, 0.05);
}

.bb-chip {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  background: transparent;
  min-height: 36px;
}
.bb-chip.selected {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.dropzone {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.dropzone.dragover {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 6%, transparent);
}

.receipt-preview {
  clip-path: polygon(
    0% 2%, 3% 0%, 6% 2%, 9% 0%, 12% 2%, 15% 0%, 18% 2%, 21% 0%, 24% 2%, 27% 0%,
    30% 2%, 33% 0%, 36% 2%, 39% 0%, 42% 2%, 45% 0%, 48% 2%, 51% 0%, 54% 2%, 57% 0%,
    60% 2%, 63% 0%, 66% 2%, 69% 0%, 72% 2%, 75% 0%, 78% 2%, 81% 0%, 84% 2%, 87% 0%,
    90% 2%, 93% 0%, 96% 2%, 100% 0%,
    100% 98%, 96% 100%, 93% 98%, 90% 100%, 87% 98%, 84% 100%, 81% 98%, 78% 100%,
    75% 98%, 72% 100%, 69% 98%, 66% 100%, 63% 98%, 60% 100%, 57% 98%, 54% 100%,
    51% 98%, 48% 100%, 45% 98%, 42% 100%, 39% 98%, 36% 100%, 33% 98%, 30% 100%,
    27% 98%, 24% 100%, 21% 98%, 18% 100%, 15% 98%, 12% 100%, 9% 98%, 6% 100%, 3% 98%, 0% 100%
  );
  max-height: 320px;
  object-fit: contain;
}

.tag-vlm { color: var(--brand); border-color: var(--brand); }
.tag-stub { color: var(--muted); border-color: var(--muted); }
.tag-manual { color: var(--ink); border-color: rgba(26, 26, 26, 0.25); }
.tag-error { color: var(--stamp); border-color: var(--stamp); }

.status-active { color: var(--brand); border-color: var(--brand); }
.status-settled { color: var(--stamp); border-color: var(--stamp); }

.balance-positive { color: var(--brand); }
.balance-negative { color: var(--stamp); }

.auth-card {
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}

.auth-toggle {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  cursor: pointer;
}
.auth-toggle:hover { color: var(--brand); }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(34, 38, 31, 0.45);
  padding: 20px;
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
}
.modal-overlay.hidden { display: none; }
.modal-card {
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
}
.group-card {
  transition: box-shadow .15s ease;
}
.group-card:hover {
  box-shadow: 0 4px 12px rgba(34, 38, 31, 0.08);
}

/* Settings toggles */
.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  padding: 0.75rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 6%, transparent);
}
.settings-toggle:last-child { border-bottom: none; }
.settings-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.settings-toggle-label {
  display: block;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--ink);
}
.settings-toggle-hint {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
}
.settings-switch {
  position: relative;
  width: 44px;
  height: 26px;
  background: var(--line);
  border-radius: 999px;
  flex-shrink: 0;
  transition: background .2s ease;
}
.settings-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.settings-toggle input:checked + .settings-switch {
  background: var(--brand);
}
.settings-toggle input:checked + .settings-switch::after {
  transform: translateX(18px);
}
.settings-toggle input:focus-visible + .settings-switch {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.compact-list .bb-mobile-card,
.compact-list .bb-table-wrap table {
  font-size: 11px;
}
.compact-list .bb-mobile-card {
  padding: 10px;
  margin-bottom: 6px;
}

.period-bar {
  gap: 0.5rem 0.75rem;
}
.period-bar select {
  max-width: 100%;
  min-width: 120px;
}

.invite-email-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.invite-link-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.invite-link-row input {
  font-size: 12px;
  word-break: break-all;
}

.member-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 5%, transparent);
}
.member-row .member-email {
  display: block;
  word-break: break-all;
  font-size: 11px;
  color: color-mix(in srgb, var(--ink) 40%, transparent);
  margin-top: 2px;
}

.report-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 0;
}
.report-row .report-actions {
  display: flex;
  gap: 0.5rem;
}

.bb-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

.bb-mobile-list {
  display: none;
}

.bb-mobile-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  background: color-mix(in srgb, var(--paper) 30%, #fff);
}
.bb-mobile-card .card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 8px;
}
.bb-mobile-card .card-store {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
}
.bb-mobile-card .card-amount {
  font-weight: 700;
  white-space: nowrap;
}
.bb-mobile-card .card-meta {
  font-size: 12px;
  color: color-mix(in srgb, var(--ink) 50%, transparent);
  line-height: 1.5;
}
.bb-mobile-card .card-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
}

.balance-table-wrap,
.settlement-list {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
  .invite-email-row {
    flex-direction: row;
    align-items: stretch;
  }
  .invite-email-row .bb-btn-primary {
    flex-shrink: 0;
    width: auto;
  }
  .invite-link-row {
    flex-direction: row;
    align-items: stretch;
  }
  .invite-link-row .bb-btn-secondary {
    flex-shrink: 0;
  }
  .report-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .report-row .report-actions {
    flex-shrink: 0;
  }
}

@media (max-width: 767px) {
  .bb-table-wrap { display: none; }
  .bb-mobile-list { display: block; }

  .bb-card { padding: 16px; }
  .dropzone { padding: 36px 16px; min-height: 140px; }

  .grid-date-amount {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .header-actions .btn-label {
    display: none;
  }
  .page-title {
    font-size: 15px !important;
  }
}

@media (min-width: 768px) {
  .tab-btn { font-size: 12px; }
}
