:root {
  --green-900: #0d2118;
  --green-800: #1a3c2e;
  --green-700: #245240;
  --green-600: #2e6b52;
  --green-500: #3a8a6a;
  --green-400: #4eab87;
  --green-200: #a8dcc8;
  --green-100: #d4f0e4;
  --green-50:  #edfaf4;
  --amber-500: #d97706;
  --amber-100: #fef3c7;
  --amber-50:  #fffbeb;
  --red-500:   #dc2626;
  --red-100:   #fee2e2;
  --blue-500:  #2563eb;
  --blue-100:  #dbeafe;
  --purple-500:#7c3aed;
  --purple-100:#ede9fe;
  --text-main: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --surface: #ffffff;
  --surface-1: #f9fafb;
  --surface-2: #f3f4f6;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  color: var(--text-main);
  background: var(--surface-1);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.screen { height: 100%; }

/* AUTH */
.auth-wrap {
  max-width: 380px;
  margin: 0 auto;
  padding: 3rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100vh;
  justify-content: center;
}
.auth-logo { font-size: 48px; text-align: center; }
.auth-title { font-size: 26px; font-weight: 700; text-align: center; color: var(--green-800); }
.auth-sub { font-size: 14px; color: var(--text-secondary); text-align: center; margin-bottom: 8px; }
.auth-error { background: var(--red-100); color: var(--red-500); padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }

/* LAYOUT */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}
.topbar {
  background: var(--green-800);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: 54px;
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top);
}
.topbar-title { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; }
.icon-btn { background: none; border: none; color: rgba(255,255,255,0.8); cursor: pointer; padding: 6px; border-radius: 8px; display: flex; align-items: center; }
.icon-btn:active { background: rgba(255,255,255,0.15); }

.main-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  padding-bottom: 2rem;
}

.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s;
}
.nav-item.active { color: var(--green-600); }
.nav-item svg { transition: stroke 0.15s; }

/* TYPOGRAPHY */
.page-title { font-size: 20px; font-weight: 700; color: var(--green-800); margin-bottom: 1rem; }
.section-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 1.25rem 0 0.5rem; }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-row {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.card-row:last-child { border-bottom: none; padding-bottom: 0; }
.card-row:first-child { padding-top: 0; }

/* SUMMARY GRID */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 1rem;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow);
}
.summary-card .val { font-size: 22px; font-weight: 700; line-height: 1; }
.summary-card .lbl { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.val-green { color: var(--green-600); }
.val-red { color: var(--red-500); }
.val-amber { color: var(--amber-500); }

/* OPS GRID */
.ops-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.op-tile {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.op-tile:active { background: var(--surface-2); }
.op-tile.done { border-color: var(--green-400); background: var(--green-50); }
.op-tile .op-emoji { font-size: 22px; margin-bottom: 6px; display: block; }
.op-tile .op-name { font-size: 13px; font-weight: 600; color: var(--text-main); }
.op-tile .op-count { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.op-tile.done .op-name { color: var(--green-700); }
.op-tile.done .op-count { color: var(--green-500); }

/* FORMS */
.field { margin-bottom: 12px; }
label { font-size: 13px; font-weight: 500; color: var(--text-secondary); display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-main);
  font-size: 15px;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--green-500); }
textarea { resize: vertical; min-height: 70px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* BUTTONS */
.btn-primary {
  background: var(--green-600);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: var(--green-700); }
.btn-ghost {
  background: transparent;
  color: var(--green-600);
  border: 1.5px solid var(--green-400);
  border-radius: var(--radius);
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}
.btn-ghost:active { background: var(--green-50); }
.btn-sm {
  background: var(--surface-2);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.full { width: 100%; }

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green  { background: var(--green-100);  color: var(--green-700); }
.badge-amber  { background: var(--amber-100);  color: var(--amber-500); }
.badge-red    { background: var(--red-100);    color: var(--red-500); }
.badge-blue   { background: var(--blue-100);   color: var(--blue-500); }
.badge-purple { background: var(--purple-100); color: var(--purple-500); }

/* ALERTS */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 10px;
}
.alert-warning { background: var(--amber-50); color: var(--amber-500); border: 1px solid #fde68a; }
.alert-danger  { background: var(--red-100);  color: var(--red-500);   border: 1px solid #fca5a5; }

/* LOG ENTRIES */
.log-entry {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.log-entry:last-child { border-bottom: none; }
.log-entry .meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* LEDGER */
.ledger-row {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  font-size: 13px;
}
.ledger-row:last-child { border-bottom: none; }
.ledger-desc { flex: 1; }
.ledger-amt { font-weight: 600; white-space: nowrap; }
.income { color: var(--green-600); }
.expense { color: var(--red-500); }

/* STOCK ROW */
.stock-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.stock-row:last-child { border-bottom: none; }
.stock-name { flex: 1; font-size: 14px; font-weight: 500; }
.stock-qty { font-size: 14px; font-weight: 700; color: var(--green-700); }
.stock-unit { font-size: 12px; color: var(--text-muted); min-width: 36px; }

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto 1rem;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 1rem; color: var(--green-800); }
.modal-footer { display: flex; gap: 8px; margin-top: 1rem; }
.modal-footer .btn-ghost { flex: 1; }
.modal-footer .btn-primary { flex: 2; }

/* INNER TABS */
.inner-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 1rem;
}
.inner-tab-btn {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1.5px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
}
.inner-tab-btn.active { color: var(--green-600); border-bottom-color: var(--green-500); }

/* DATE PICKER ROW */
.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.date-row input[type=date] {
  width: auto;
  padding: 8px 10px;
  font-size: 14px;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom) + 12px);
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--green-600);
  color: #fff;
  border: none;
  font-size: 26px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  -webkit-tap-highlight-color: transparent;
}
.fab:active { background: var(--green-700); transform: scale(0.96); }

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--green-800);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 300;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: 14px;
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 8px; }

/* LOADING */
.loading { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 14px; }

/* SPINNER */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* SYNC INDICATOR */
.sync-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green-400);
  display: inline-block;
  margin-left: 6px;
}
.sync-dot.syncing { background: var(--amber-500); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
