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

.ico {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

html, body {
  margin: 0;
  padding: 0;
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
  background: linear-gradient(135deg, #d4e1c9 0%, #b8cfa6 100%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
input:focus, button:focus { outline: none; }
input:focus-visible { box-shadow: 0 0 0 2px #639922; }

.phone {
  width: 100%;
  max-width: 400px;
  height: 860px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  background: #E8F0E3;
  border-radius: 28px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 24px 60px rgba(23,52,4,0.18), 0 4px 12px rgba(23,52,4,0.08);
  display: flex;
  flex-direction: column;
}

/* Full-screen on mobile */
@media (max-width: 480px) {
  body {
    padding: 0;
    background: #E8F0E3;
  }
  .phone {
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }
}

.screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 96px;
  display: none;
}
.screen.active { display: block; }
.screen::-webkit-scrollbar { display: none; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
}
.topbar h1 {
  font-size: 17px;
  font-weight: 500;
  color: #173404;
  margin: 0;
}
.topbar-btn {
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.6);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #173404;
  transition: transform 0.15s;
}
.topbar-btn:active { transform: scale(0.92); }
.topbar-btn svg.ico { font-size: 20px; }
.topbar-spacer { width: 36px; }

/* Balance pill */
.balance {
  background: #FAC775;
  border: 1px solid #EF9F27;
  border-radius: 100px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
  transition: background 0.3s, border 0.3s;
}
.balance svg.ico { font-size: 20px; color: #633806; }
.balance span { font-size: 20px; font-weight: 500; color: #412402; }
.balance.zero { background: rgba(255,255,255,0.85); border-color: rgba(23,52,4,0.08); }
.balance.zero svg.ico { color: #5F5E5A; }
.balance.zero span { color: #444441; }
.balance.negative { background: #FCEBEB; border-color: #F09595; }
.balance.negative svg.ico { color: #791F1F; }
.balance.negative span { color: #501313; }

/* Search */
.search {
  position: relative;
  margin-bottom: 18px;
}
.search svg.ico {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: #5F5E5A;
  pointer-events: none;
}
.search input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 12px;
  font-size: 14px;
  color: #173404;
}

/* Section labels */
.label-section {
  font-size: 15px;
  font-weight: 500;
  color: #173404;
  margin: 0 4px 4px;
}
.label-sub {
  font-size: 11px;
  font-weight: 500;
  color: #5F5E5A;
  margin: 0 4px 12px;
  letter-spacing: 0.5px;
}
.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 4px 10px;
}
.label-row p { margin: 0; }

/* Likely actions */
.likely-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}
.likely-card {
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(23,52,4,0.06);
  border-radius: 16px;
  padding: 16px 8px 12px;
  text-align: center;
  transition: transform 0.15s;
  min-height: 86px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.likely-card:active { transform: scale(0.97); }
.likely-card .name {
  font-size: 12px;
  font-weight: 500;
  color: #173404;
  margin: 0 0 4px;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.likely-card .cost {
  font-size: 10px;
  color: #5F5E5A;
  margin: 0 0 10px;
}
.likely-card button {
  width: 100%;
  height: 26px;
  background: #C0DD97;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: background 0.15s;
}
.likely-card button:active { background: #97C459; }
.likely-card button svg.ico { font-size: 14px; color: #173404; }

/* List items */
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.list-item {
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(23,52,4,0.06);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-body .row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.list-item-name {
  font-size: 14px;
  font-weight: 500;
  color: #173404;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item-meta {
  font-size: 12px;
  color: #5F5E5A;
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.list-item-meta svg.ico { font-size: 13px; color: #BA7517; }
.badge {
  font-size: 10px;
  padding: 1px 6px;
  background: #FAEEDA;
  color: #854F0B;
  border-radius: 10px;
  font-weight: 500;
}
.check-btn {
  width: 30px; height: 30px;
  padding: 0;
  background: #C0DD97;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, background 0.15s;
}
.check-btn:active { transform: scale(0.92); background: #97C459; }
.check-btn svg.ico { font-size: 16px; color: #173404; }
.check-btn.calc { padding: 0 8px; width: auto; gap: 3px; }
.check-btn.calc .pencil { font-size: 12px; }
.take-btn {
  height: 30px;
  padding: 0 14px;
  background: #FAC775;
  border: 1px solid #EF9F27;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: #412402;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.15s;
}
.take-btn:active { transform: scale(0.96); }
.take-btn:disabled {
  background: rgba(23,52,4,0.08);
  border-color: rgba(23,52,4,0.12);
  color: rgba(23,52,4,0.4);
}
.take-btn svg.ico { font-size: 12px; }

.item-tap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: #5F5E5A;
  background: rgba(255,255,255,0.5);
  border-radius: 14px;
  border: 1px dashed rgba(23,52,4,0.15);
}
.empty svg.ico {
  font-size: 36px;
  color: #888780;
  margin-bottom: 8px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.empty p {
  font-size: 13px;
  margin: 0;
}

/* Add FAB */
.fab {
  position: absolute;
  bottom: 90px;
  right: 16px;
  width: 52px;
  height: 52px;
  background: #173404;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 16px rgba(23,52,4,0.3);
  z-index: 10;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }
.fab svg.ico { font-size: 24px; }

/* Bottom nav */
.bottomnav {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(23,52,4,0.08);
  padding: 10px 0 calc(14px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  z-index: 5;
}
.nav-tab {
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #5F5E5A;
  padding: 4px;
}
.nav-tab svg.ico { font-size: 22px; }
.nav-tab span { font-size: 11px; }
.nav-tab.active { color: #3B6D11; }
.nav-tab.active span { font-weight: 500; }

/* Form elements */
.form-label {
  font-size: 11px;
  font-weight: 500;
  color: #5F5E5A;
  margin: 0 4px 8px;
  letter-spacing: 0.5px;
}
.form-input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 12px;
  font-size: 15px;
  color: #173404;
  margin-bottom: 18px;
}
.stepper {
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}
.stepper .coin { font-size: 22px; color: #BA7517; flex-shrink: 0; }
.stepper .value {
  font-size: 22px;
  font-weight: 500;
  color: #173404;
  flex: 1;
}
.stepper-controls { display: flex; gap: 6px; flex-shrink: 0; }
.stepper-btn {
  width: 32px; height: 32px;
  padding: 0;
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.stepper-btn:active { transform: scale(0.9); }
.stepper-btn svg.ico { font-size: 16px; color: #173404; }
.stepper-btn.minus { background: #E8F0E3; }
.stepper-btn.plus { background: #C0DD97; }
.stepper-btn.plus-warm { background: #FAC775; border-color: #EF9F27; }
.stepper-btn.plus-warm svg.ico { color: #412402; }

.chips {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.chip {
  padding: 6px 12px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 100px;
  font-size: 12px;
  color: #173404;
  transition: transform 0.1s;
}
.chip:active { transform: scale(0.95); }
.chip.active {
  background: #FAC775;
  border-color: #EF9F27;
  color: #412402;
  font-weight: 500;
}

/* Segmented control */
.segmented {
  background: rgba(23,52,4,0.06);
  border-radius: 12px;
  padding: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 18px;
}
.segmented button {
  padding: 10px 8px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  color: #5F5E5A;
  transition: background 0.15s, color 0.15s;
}
.segmented button.active {
  background: rgba(255,255,255,0.95);
  color: #173404;
  font-weight: 500;
}

/* Toggle row */
.toggle-row {
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.toggle-row > svg.ico { font-size: 22px; color: #639922; flex-shrink: 0; }
.toggle-row .body { flex: 1; min-width: 0; }
.toggle-row .body .name {
  font-size: 14px;
  font-weight: 500;
  color: #173404;
  margin: 0 0 2px;
}
.toggle-row .body .desc {
  font-size: 12px;
  color: #5F5E5A;
  margin: 0;
  line-height: 1.4;
}
.toggle {
  width: 44px; height: 26px;
  background: rgba(23,52,4,0.12);
  border-radius: 100px;
  position: relative;
  flex-shrink: 0;
  border: none;
  padding: 0;
  transition: background 0.2s;
}
.toggle .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle.on { background: #639922; }
.toggle.on .knob { transform: translateX(18px); }

/* Action row (profile screen) */
.action-row {
  width: 100%;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  text-align: left;
  transition: transform 0.1s;
}
.action-row:active { transform: scale(0.98); }
.action-row > svg.ico { font-size: 22px; color: #3B6D11; flex-shrink: 0; }
.action-row-body { flex: 1; min-width: 0; }
.action-row-body .name {
  font-size: 14px;
  font-weight: 500;
  color: #173404;
  margin: 0 0 2px;
}
.action-row-body .desc {
  font-size: 12px;
  color: #5F5E5A;
  margin: 0;
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: #173404;
  border: none;
  border-radius: 14px;
  color: white;
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 8px;
  transition: transform 0.15s;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
  background: rgba(23,52,4,0.2);
  color: rgba(255,255,255,0.7);
}
.btn-ghost {
  width: 100%;
  padding: 14px;
  background: transparent;
  border: none;
  color: #5F5E5A;
  font-size: 14px;
}
.btn-danger {
  width: 100%;
  padding: 14px;
  background: transparent;
  border: 1px solid #F09595;
  border-radius: 14px;
  color: #791F1F;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-danger:active { background: #FCEBEB; }
.btn-danger svg.ico { font-size: 16px; }

.stats-card {
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(23,52,4,0.06);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.stats-card svg.ico { font-size: 18px; flex-shrink: 0; }
.stats-card p {
  font-size: 12px;
  color: #5F5E5A;
  margin: 0;
}
.stats-card strong {
  color: #173404;
  font-weight: 500;
}

/* Preview */
.preview {
  background: #C0DD97;
  border: 1px solid #639922;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.preview svg.ico { font-size: 18px; color: #173404; flex-shrink: 0; }
.preview p {
  font-size: 13px;
  color: #173404;
  margin: 0;
  line-height: 1.4;
}
.preview .formula {
  color: #3B6D11;
  font-weight: 500;
}

/* History */
.history-day { margin-bottom: 18px; }
.history-day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}
.history-day-header .title {
  font-size: 14px;
  font-weight: 500;
  color: #173404;
  margin: 0;
}
.history-day-header .totals {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.history-day-header .plus { color: #3B6D11; font-weight: 500; }
.history-day-header .minus { color: #A32D2D; font-weight: 500; }
.history-list {
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(23,52,4,0.06);
  border-radius: 14px;
  overflow: hidden;
}
.history-item {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.history-item:active { background: rgba(23,52,4,0.05); }
.history-item + .history-item {
  border-top: 1px solid rgba(23,52,4,0.06);
}
.history-item .body { flex: 1; min-width: 0; }
.history-item .name {
  font-size: 13px;
  font-weight: 500;
  color: #173404;
  margin: 0;
}
.history-item .time {
  font-size: 11px;
  color: #5F5E5A;
  margin: 0;
}
.history-item .amount {
  font-size: 13px;
  font-weight: 500;
}
.history-item .amount.plus { color: #3B6D11; }
.history-item .amount.minus { color: #A32D2D; }

/* Modal */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23,52,4,0.5);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}
.modal-backdrop.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal {
  background: #E8F0E3;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px 24px;
  width: 100%;
  animation: slideUp 0.25s ease-out;
  max-height: 80%;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.modal-header svg.ico { font-size: 22px; color: #639922; }
.modal-header .name {
  font-size: 16px;
  font-weight: 500;
  color: #173404;
  margin: 0;
}
.modal-formula {
  font-size: 12px;
  color: #5F5E5A;
  margin: 0 0 18px;
}
.big-stepper {
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.big-stepper button {
  width: 36px; height: 36px;
  padding: 0;
  border: 1px solid rgba(23,52,4,0.08);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s;
}
.big-stepper button:active { transform: scale(0.92); }
.big-stepper button svg.ico { font-size: 18px; color: #173404; }
.big-stepper .minus { background: #E8F0E3; }
.big-stepper .plus { background: #C0DD97; }
.big-stepper .value {
  font-size: 28px;
  font-weight: 500;
  color: #173404;
  flex: 1;
  text-align: center;
}
.calc-result {
  background: #FAC775;
  border: 1px solid #EF9F27;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.calc-result .formula {
  font-size: 13px;
  color: #633806;
}
.calc-result .total {
  font-size: 18px;
  font-weight: 500;
  color: #412402;
  display: flex;
  align-items: center;
  gap: 6px;
}
.calc-result .total svg.ico { font-size: 18px; }

/* Toast */
.toast {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #173404;
  color: white;
  padding: 10px 18px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(23,52,4,0.3);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast svg.ico { font-size: 16px; }
.toast.minus { background: #791F1F; }

/* Confirm dialog */
.confirm-modal {
  background: #E8F0E3;
  border-radius: 20px;
  padding: 20px 18px;
  width: 90%;
  max-width: 320px;
  margin: auto;
}
.modal-backdrop.center { align-items: center; }
.confirm-modal h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 500;
  color: #173404;
}
.confirm-modal p {
  margin: 0 0 18px;
  font-size: 13px;
  color: #5F5E5A;
  line-height: 1.4;
}

/* Login screen */
#screen-login.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}
.login-wrap {
  width: 100%;
}
.login-title {
  font-size: 24px;
  font-weight: 500;
  color: #173404;
  text-align: center;
  margin: 0 0 28px;
}
.login-error {
  color: #791F1F;
  font-size: 13px;
  margin: 8px 4px 0;
  text-align: center;
}
