:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --red: #dc2626;
  --red-dark: #b91c1c;
  --red-soft: #fef2f2;
  --red-border: #fecaca;
  --green: #16a34a;
  --green-dark: #15803d;
  --green-soft: #f0fdf4;
  --green-border: #bbf7d0;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --blue-border: #bfdbfe;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --amber-border: #fde68a;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Sticky Header */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  padding-top: env(safe-area-inset-top, 0px);
}

.header-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 14px 10px;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  min-width: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.brand-title-row h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}

.sync-dot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--green-dark);
  background: var(--green-soft);
  border: 1px solid var(--green-border);
  padding: 1px 6px;
  border-radius: 999px;
}

.sync-dot .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.sync-dot.syncing {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: var(--amber-border);
}

.sync-dot.syncing .dot {
  background: var(--amber);
  animation: pulse 0.9s infinite;
}

.sync-dot.offline {
  color: var(--red-dark);
  background: var(--red-soft);
  border-color: var(--red-border);
}

.sync-dot.offline .dot {
  background: var(--red);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Actor Segmented Control */
.actor-switch {
  display: inline-flex;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
  flex-shrink: 0;
}

.actor-btn {
  border: none;
  background: transparent;
  padding: 6px 10px;
  min-height: 32px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.actor-btn.active {
  background: var(--surface);
  color: var(--red);
  box-shadow: var(--shadow-sm);
}

/* Countdown Tiles */
.countdown-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.stat-tile {
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--bg);
}

.stat-tile.stat-left {
  background: var(--red-soft);
  border-color: var(--red-border);
}

.stat-tile.stat-given {
  background: var(--green-soft);
  border-color: var(--green-border);
}

.stat-tile.stat-spares {
  background: #f8fafc;
  border-color: var(--border);
}

.stat-tile.stat-spares.over {
  background: var(--red-soft);
  border-color: var(--red-border);
}

.stat-num {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-left .stat-num {
  color: var(--red);
}

.stat-given .stat-num {
  color: var(--green-dark);
}

.stat-spares .stat-num {
  color: var(--text);
}

.stat-spares.over .stat-num {
  color: var(--red);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-sub {
  font-weight: 500;
  opacity: 0.85;
}

/* Progress Bar */
.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-track {
  position: relative;
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-alloc {
  position: absolute;
  inset: 0 auto 0 0;
  background: #fca5a5;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-given {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.stock-link {
  border: none;
  background: transparent;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: pointer;
}

/* Main Content */
.main-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px calc(92px + env(safe-area-inset-bottom, 0px));
}

.controls-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.filter-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.filter-pills::-webkit-scrollbar {
  display: none;
}

.pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-count {
  font-size: 11px;
  font-weight: 700;
  background: #f1f5f9;
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.pill.active {
  background: var(--text);
  border-color: var(--text);
  color: #ffffff;
}

.pill.active .pill-count {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* Search Bar */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 38px 10px 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  outline: none;
  box-shadow: var(--shadow-sm);
}

.search-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.search-clear {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  background: #f1f5f9;
  color: var(--text-muted);
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* Error Banner */
.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--red-soft);
  border: 1px solid var(--red-border);
  color: var(--red-dark);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.retry-btn {
  border: 1px solid var(--red-border);
  background: #ffffff;
  color: var(--red-dark);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Client Cards */
.list-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.loading-state,
.empty-state {
  text-align: center;
  padding: 36px 18px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s, background 0.15s;
}

.client-card.is-given {
  background: #f8fff9;
  border-color: var(--green-border);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-title-group {
  min-width: 0;
  flex: 1;
}

.client-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.015em;
  line-height: 1.25;
  word-break: break-word;
}

.client-card.is-given .client-name {
  color: #1e293b;
}

.card-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.spend-pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  background: #f1f5f9;
  padding: 2px 7px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.spare-pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #92400e;
  background: var(--amber-soft);
  border: 1px solid var(--amber-border);
  padding: 1px 7px;
  border-radius: 6px;
}

.contact-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 6px;
}

.owner-badge {
  flex-shrink: 0;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.1s ease;
}

.owner-badge:active {
  transform: scale(0.96);
}

.owner-badge.owner-Baruch {
  background: var(--red-soft);
  color: var(--red-dark);
  border-color: var(--red-border);
}

.owner-badge.owner-David {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: var(--blue-border);
}

/* Action Row: Qty Stepper + Mark Given */
.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 2px;
  flex-shrink: 0;
}

.qty-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: var(--surface);
  border-radius: 9px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.qty-btn:active {
  background: #f1f5f9;
}

.qty-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.qty-label {
  min-width: 66px;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
}

.given-btn {
  flex: 1;
  min-height: 44px;
  border-radius: 11px;
  border: 1.5px solid var(--red);
  background: var(--red);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.given-btn:active {
  transform: scale(0.98);
}

.given-btn.done {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
}

.given-stamp {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--green-dark);
  background: var(--green-soft);
  border: 1px solid var(--green-border);
  border-radius: 9px;
  padding: 5px 10px;
}

.undo-hint {
  font-size: 11px;
  font-weight: 500;
  color: var(--green-dark);
  opacity: 0.8;
}

/* Note Input */
.note-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.note-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 8px 60px 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
}

.note-input:focus {
  background: var(--surface);
  border-color: var(--border-strong);
}

.note-status {
  position: absolute;
  right: 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--green-dark);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.note-status.visible {
  opacity: 1;
}

.delete-spare-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
}

.delete-spare-btn:hover {
  color: var(--red);
  border-color: var(--red-border);
}

/* Floating Action Button */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  border: none;
  background: var(--text);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.24);
  cursor: pointer;
}

.fab:active {
  transform: scale(0.97);
}

.fab-plus {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

/* Modal Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: 20px;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.modal-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field input[type="text"] {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  font-size: 15px;
  outline: none;
}

.field input[type="text"]:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 3px;
  min-height: 44px;
}

.step-btn {
  width: 38px;
  height: 36px;
  border: none;
  background: #f1f5f9;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.step-val {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.owner-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  min-height: 44px;
}

.owner-opt {
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.owner-opt.active {
  background: var(--surface);
  color: var(--red);
  box-shadow: var(--shadow-sm);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  padding: 4px 0;
  cursor: pointer;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.primary-submit {
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: var(--red);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
}

.primary-submit:disabled {
  opacity: 0.6;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  background: var(--text);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}
