:root {
  --bg: #FAFDFB;
  --surface: #FFFFFF;
  --surface-low: #F3F7F5;
  --surface-high: #E7EFEC;
  --primary: #0E6B66;
  --on-primary: #FFFFFF;
  --primary-container: #BCECE8;
  --on-primary-container: #00201E;
  --text: #171D1C;
  --text-muted: #52615E;
  --outline: #CFD8D6;
  --tick: #16A34A;
  --tick-bg: rgba(22, 163, 74, 0.15);
  --cross: #DC2626;
  --cross-bg: rgba(220, 38, 38, 0.15);
  --amber: #D97706;
  --amber-bg: rgba(245, 158, 11, 0.16);
  --cell-size: 64px;
  --name-col-width: 140px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1514;
    --surface: #17201E;
    --surface-low: #1C2624;
    --surface-high: #25312F;
    --primary: #54D6CE;
    --on-primary: #003734;
    --primary-container: #00504C;
    --on-primary-container: #BCECE8;
    --text: #E0E6E4;
    --text-muted: #9BA8A5;
    --outline: #32403E;
    --tick: #4ADE80;
    --tick-bg: rgba(74, 222, 128, 0.18);
    --cross: #F87171;
    --cross-bg: rgba(248, 113, 113, 0.18);
    --amber: #FBBF24;
    --amber-bg: rgba(251, 191, 36, 0.18);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea {
  user-select: text;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100dvh;
}

.hidden {
  display: none !important;
}

/* Fullscreen Gate Screens (Lock & Auth) */
.state-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.state-card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 26px;
  padding: 32px 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

.state-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.locked-icon {
  background: var(--cross-bg);
  color: var(--cross);
}

.auth-icon {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.state-card h1 {
  font-size: 1.4rem;
  margin: 0 0 10px;
  font-weight: 800;
}

.state-card p {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0 0 24px;
}

.text-input {
  width: 100%;
  height: 50px;
  border-radius: 14px;
  border: 1.5px solid var(--outline);
  background: var(--surface-low);
  color: var(--text);
  padding: 0 16px;
  font-size: 0.98rem;
  margin-bottom: 12px;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
}

.passcode-input {
  font-size: 1.35rem;
  letter-spacing: 6px;
  text-align: center;
  font-weight: 700;
}

.error-banner {
  background: var(--cross-bg);
  color: var(--cross);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.btn-primary {
  width: 100%;
  height: 52px;
  border: none;
  border-radius: 16px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Main Ledger Layout */
.ledger-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px 6px;
  background: linear-gradient(180deg, var(--primary-container) 0%, transparent 100%);
}

.top-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
}

.status-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}

.status-pill.online {
  background: var(--tick-bg);
  color: var(--tick);
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-tonal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-tonal:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Portal Mode Switcher (Weekly Ledger | Daily Stock-Out) */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 16px 6px;
  padding: 4px;
  background: var(--surface-low);
  border: 1px solid var(--outline);
  border-radius: 16px;
}

.mode-tab {
  height: 42px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-tab.active {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.tab-count-badge {
  background: var(--cross);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
}

/* Portal views (Weekly Ledger / Daily Stock-Out) fill the space between the tabs
   and the submit dock. min-height: 0 lets the inner areas scroll instead of being
   clipped by body { overflow: hidden }. */
.portal-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Days Bar */
.days-bar {
  margin: 2px 16px 4px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.days-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cal-icon {
  color: var(--primary);
}

.days-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.days-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.changes-badge {
  background: var(--primary-container);
  color: var(--on-primary-container);
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

/* Sticky Grid */
.grid-wrapper {
  flex: 1;
  padding: 4px 16px 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.grid-card {
  flex: 1;
  border: 1px solid var(--outline);
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.grid-header-row {
  display: flex;
  background: var(--surface-high);
  border-bottom: 1px solid var(--outline);
  height: 68px;
  flex-shrink: 0;
}

.sticky-name-header {
  flex: 1;
  min-width: 0;
  padding: 0 12px;
  display: flex;
  align-items: center;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-muted);
  border-right: 1px solid var(--outline);
}

.days-header-track {
  display: flex;
  flex-shrink: 0;
}
.days-header-track::-webkit-scrollbar {
  display: none;
}

.day-col-header {
  width: var(--cell-size);
  height: 68px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.day-col-header.today .day-pill {
  background: var(--primary);
  color: var(--on-primary);
}

.day-pill {
  width: 54px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.day-dow, .day-mon {
  font-size: 0.68rem;
  opacity: 0.85;
}

.day-num {
  font-size: 1rem;
  font-weight: 800;
}

.grid-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.item-row {
  display: flex;
  height: var(--cell-size);
  border-bottom: 1px solid var(--outline);
}

.item-row:nth-child(even) {
  background: var(--surface-low);
}

.item-name-cell {
  flex: 1;
  min-width: 0;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--outline);
}

.item-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-cells-track {
  display: flex;
  flex-shrink: 0;
}
.item-cells-track::-webkit-scrollbar {
  display: none;
}

.ledger-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.ledger-cell.highlighted {
  background: rgba(14, 107, 102, 0.06);
}

.ledger-cell.dirty::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #F59E0B;
}

.dot-empty {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--outline);
}

.badge-tick {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tick-bg);
  color: var(--tick);
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge-cross {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cross-bg);
  color: var(--cross);
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge-number {
  min-width: 38px;
  height: 32px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 800;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Daily Stock-Out View (Worker Market List) */
.stockout-wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stockout-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-chips-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-top: -2px;
  scrollbar-width: none;
}
.quick-chips-bar::-webkit-scrollbar {
  display: none;
}

.quick-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--outline);
  background: var(--surface-low);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.quick-chip:active {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.btn-add-stockout {
  height: 46px;
  margin-top: 2px;
}

.stockout-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-header-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 0 4px;
}

.stockout-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-remove-staged {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: var(--cross-bg);
  color: var(--cross);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.empty-stockout-note {
  text-align: center;
  padding: 20px 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: var(--surface-low);
  border-radius: 16px;
  border: 1px dashed var(--outline);
}

/* Bottom Submit Dock */
.submit-dock {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--outline);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dock-meta {
  display: flex;
  flex-direction: column;
}

#dock-summary {
  font-weight: 700;
  font-size: 0.9rem;
}

.dock-note {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.btn-submit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  padding: 0 20px;
  border-radius: 16px;
  border: none;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Bottom Sheet Number Pad */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.picker-sheet {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--outline);
  border-radius: 99px;
  margin: 0 auto 14px;
}

.sheet-title {
  margin: 0 0 14px;
  font-size: 1.2rem;
  font-weight: 800;
}

.sheet-status-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.choice-btn {
  height: 60px;
  border-radius: 18px;
  border: 1.5px solid var(--outline);
  background: var(--surface-low);
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.choice-tick.active {
  background: var(--tick);
  color: #fff;
  border-color: var(--tick);
}

.choice-cross.active {
  background: var(--cross);
  color: #fff;
  border-color: var(--cross);
}

.sheet-section-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.number-pad-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.num-btn {
  height: 52px;
  border-radius: 16px;
  border: 1px solid var(--outline);
  background: var(--surface-low);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
}

.num-btn.active {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-clear-cell {
  width: 100%;
  height: 48px;
  border: none;
  background: transparent;
  color: var(--cross);
  font-weight: 700;
  font-size: 0.95rem;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 0.88rem;
  z-index: 200;
}

/* Market List: mirrors the app's Market List screen */
.so-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 0;
}

.so-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
}

.btn-add-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 42px;
  padding: 0 16px 0 12px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

.stockout-item-card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 18px;
  padding: 12px 10px 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background-color 0.2s ease, opacity 0.25s ease, border-color 0.2s ease;
}

.so-ring {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--outline);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.stockout-item-card.staged {
  border-color: var(--amber);
  background: var(--amber-bg);
}

.stockout-item-card.staged .so-ring {
  border-color: var(--amber);
  border-style: dashed;
}

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

.stockout-item-title {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stockout-item-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Add-item sheet */
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-head .sheet-title {
  margin: 0;
}

.btn-icon-plain {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.picker-sheet {
  max-height: 92dvh;
  overflow-y: auto;
}

/* Cell entry dialog (tap a cell): tick / cross / typed quantity */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.entry-dialog {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border-radius: 28px;
  padding: 24px 20px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  animation: popIn 0.16s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

.dialog-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dialog-sub {
  margin: 2px 0 18px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.mark-row {
  display: flex;
  justify-content: space-evenly;
}

.mark-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.mark-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
}

.mark-tick .mark-circle { background: var(--tick-bg); color: var(--tick); }
.mark-cross .mark-circle { background: var(--cross-bg); color: var(--cross); }

.mark-tick.active .mark-circle { border-color: var(--tick); background: rgba(22, 163, 74, 0.26); }
.mark-cross.active .mark-circle { border-color: var(--cross); background: rgba(220, 38, 38, 0.26); }
.mark-tick.active .mark-label { color: var(--tick); font-weight: 800; }
.mark-cross.active .mark-label { color: var(--cross); font-weight: 800; }

.dialog-divider {
  border: none;
  border-top: 1px solid var(--outline);
  margin: 20px 0 16px;
}

.qty-input {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

/* The hint disappears as soon as the field is tapped. */
.qty-input:focus::placeholder {
  color: transparent;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.btn-text {
  height: 40px;
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-set {
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-text:disabled,
.btn-set:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
