:root {
  color-scheme: dark;
  --bg: #06070a;
  --panel: #11131a;
  --panel-2: #1a1d27;
  --text: #f5f7fb;
  --muted: #9aa2b2;
  --accent: #d72f2f;
  --accent-2: #ff5d5d;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #ff4d4d;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  background: radial-gradient(circle at top, #171a24, var(--bg));
  color: var(--text);
  min-height: 100vh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

.splash-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem;
  background: linear-gradient(135deg, #090a0e, #1b1520 70%, #0e1119);
}
.splash-logo {
  width: 140px;
  height: 140px;
  margin-bottom: 1rem;
  filter: drop-shadow(var(--shadow));
}
.logo-mark {
  width: 76px;
  height: 76px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent), #8c0f0f);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.4rem;
  margin: 0 auto 1rem;
  box-shadow: var(--shadow);
}
.splash-screen h1 { margin: 0 0 0.5rem; font-size: 1.8rem; }
.splash-screen p { margin: 0; color: var(--muted); }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.2rem;
}
.auth-card {
  width: min(100%, 480px);
  background: rgba(17, 19, 26, 0.94);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 28px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.auth-logo {
  width: 100px;
  height: 100px;
  margin: 0 auto 1rem;
  display: block;
}
.auth-card h2 { margin: 0 0 0.3rem; text-align: center; }
.auth-card p { color: var(--muted); text-align: center; }
form label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}
input, select {
  width: 100%;
  margin-top: 0.4rem;
  border: 1.5px solid rgba(215, 47, 47, 0.25);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  background: rgba(26, 29, 39, 0.5);
  color: var(--text);
  transition: all 200ms ease;
  font-size: 0.95rem;
}
input:hover, select:hover {
  border-color: rgba(215, 47, 47, 0.5);
  background: rgba(26, 29, 39, 0.7);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(215, 47, 47, 0.2);
  background: rgba(26, 29, 39, 0.8);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='%23ff5d5d' d='M5 8l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.2em;
  padding-right: 2.5rem;
  cursor: pointer;
}
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.primary-btn, .secondary-btn, .ghost-btn, .nav-item, .fab {
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1rem;
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}
.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  width: 100%;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(215, 47, 47, 0.25);
}
.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(215, 47, 47, 0.35);
}
.primary-btn:active {
  transform: translateY(0);
}
.secondary-btn { 
  width: 100%; 
  margin-top: 0.7rem; 
  background: linear-gradient(135deg, rgba(32, 35, 45, 0.8), rgba(26, 29, 39, 0.9));
  color: var(--text); 
  border: 1.5px solid rgba(215, 47, 47, 0.2);
  transition: all 200ms ease;
}
.secondary-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(215, 47, 47, 0.4);
  box-shadow: 0 4px 15px rgba(215, 47, 47, 0.15);
}
.ghost-btn { 
  background: transparent; 
  color: var(--muted); 
  padding: 0.5rem 0.7rem; 
  transition: all 200ms ease;
}
.ghost-btn:hover {
  color: var(--accent);
}
.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover, .nav-item:hover, .fab:hover { transform: translateY(-1px); }

.status-message { min-height: 1.2rem; color: #ff8f8f; margin-top: 0.8rem; text-align: center; }

.app-shell { min-height: 100vh; padding: 1rem 1rem 6rem; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.topbar-logo {
  width: 48px;
  height: 48px;
}
.topbar > div {
  flex: 1;
}
.eyebrow { margin: 0 0 0.2rem; color: var(--accent-2); font-size: 0.8rem; letter-spacing: 0.16em; text-transform: uppercase; }
.topbar h3 { margin: 0; }
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.3rem;
  padding: 0.32rem 0.6rem;
  border-radius: 999px;
  background: rgba(215, 47, 47, 0.15);
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 600;
}
.sync-badge.error {
  background: rgba(255, 77, 77, 0.18);
  color: #ffb0b0;
}

.view { display: none; }
.view.active { display: block; }

.card {
  background: linear-gradient(180deg, rgba(17,19,26,0.96), rgba(11,12,16,0.96));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  transition: all 200ms ease;
}
.card:hover {
  border-color: rgba(215, 47, 47, 0.15);
  box-shadow: 0 14px 40px rgba(215, 47, 47, 0.1);
}
.grid { display: grid; gap: 0.9rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.metric { display: flex; flex-direction: column; gap: 0.25rem; }
.metric strong { font-size: 1.2rem; }
.metric span { color: var(--muted); font-size: 0.8rem; }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.list-item:last-child { border-bottom: none; }
.badge { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.35rem 0.65rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge.healthy { background: rgba(46, 204, 113, 0.2); color: var(--green); }
.badge.medium { background: rgba(241, 196, 15, 0.2); color: var(--yellow); }
.badge.low { background: rgba(255, 77, 77, 0.2); color: var(--red); }

.quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0.7rem; }
.quick-actions button { 
  width: 100%; 
  background: linear-gradient(135deg, rgba(26, 29, 39, 0.7), rgba(17, 19, 26, 0.9));
  color: var(--text); 
  border: 1.5px solid rgba(215, 47, 47, 0.2);
  border-radius: 18px; 
  padding: 0.95rem; 
  text-align: center;
  font-weight: 600;
  transition: all 200ms ease;
  cursor: pointer;
}
.quick-actions button:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 15px rgba(215, 47, 47, 0.2);
  background: linear-gradient(135deg, rgba(26, 29, 39, 0.9), rgba(17, 19, 26, 1));
}
.quick-actions button:active {
  transform: translateY(0);
}

.form-grid { display: grid; gap: 0.9rem; }
.form-grid .row { display: grid; gap: 0.9rem; grid-template-columns: 1fr 1fr; }
.form-grid button { width: 100%; margin-top: 0.5rem; }

.chart-bars { display: flex; align-items: end; gap: 0.5rem; height: 120px; margin-top: 0.8rem; }
.chart-bars .bar { flex: 1; background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-radius: 10px 10px 0 0; min-height: 18px; }

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 1rem;
  display: flex;
  gap: 0.45rem;
  padding: 0.45rem;
  border-radius: 999px;
  background: rgba(17,19,26,0.95);
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  max-width: 90vw;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.bottom-nav::-webkit-scrollbar {
  height: 4px;
}
.bottom-nav::-webkit-scrollbar-track {
  background: transparent;
}
.bottom-nav::-webkit-scrollbar-thumb {
  background: rgba(215, 47, 47, 0.4);
  border-radius: 2px;
}
.bottom-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(215, 47, 47, 0.6);
}
.nav-item {
  background: transparent;
  color: var(--muted);
  padding: 0.7rem 0.95rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-item.active {
  color: white;
  background: linear-gradient(135deg, var(--accent), #7a1212);
}

.fab {
  position: fixed;
  right: 1rem;
  bottom: 5.2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 1.6rem;
  box-shadow: 0 6px 20px rgba(215, 47, 47, 0.35);
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.fab:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 8px 30px rgba(215, 47, 47, 0.45);
}
.fab:active {
  transform: scale(0.98);
}

.toast { position: fixed; left: 50%; bottom: 6.8rem; transform: translateX(-50%); background: rgba(20,22,28,0.95); color: white; padding: 0.75rem 1rem; border-radius: 999px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 180ms ease; }
.toast.show { opacity: 1; }

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: grid;
  place-items: center;
}
.modal.hidden {
  display: none;
}
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  z-index: 1001;
  width: min(100%, 600px);
  max-height: 80vh;
  background: linear-gradient(180deg, rgba(17,19,26,0.98), rgba(11,12,16,0.98));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 300ms ease;
}
@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, rgba(17,19,26,0.98), rgba(11,12,16,0.95));
}
.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  transition: all 200ms ease;
}
.modal-close:hover {
  color: var(--accent);
}
.sand-grid, .options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  padding: 1rem;
}
.sand-option, .selection-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, rgba(26, 29, 39, 0.6), rgba(17, 19, 26, 0.8));
  border: 2px solid rgba(215, 47, 47, 0.2);
  border-radius: 16px;
  cursor: pointer;
  transition: all 200ms ease;
  min-height: 120px;
  text-align: center;
}
.sand-option:active, .selection-option:active {
  transform: scale(0.95);
}
.sand-option:hover, .selection-option:hover {
  border-color: rgba(215, 47, 47, 0.5);
  background: linear-gradient(135deg, rgba(26, 29, 39, 0.8), rgba(17, 19, 26, 0.9));
  box-shadow: 0 4px 15px rgba(215, 47, 47, 0.15);
}
.sand-option.selected, .selection-option.selected {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(215, 47, 47, 0.2), rgba(215, 47, 47, 0.1));
  box-shadow: 0 0 0 3px rgba(215, 47, 47, 0.15);
}
.sand-option-name, .selection-option-name {
  font-weight: 600;
  font-size: 0.95rem;
}
.sand-option-stock, .selection-option-detail {
  font-size: 0.75rem;
  color: var(--muted);
}
.sand-picker-btn {
  width: 100%;
  border: 1.5px solid rgba(215, 47, 47, 0.25);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  background: rgba(26, 29, 39, 0.5);
  color: var(--text);
  cursor: pointer;
  transition: all 200ms ease;
  text-align: left;
  font-size: 0.95rem;
}
.sand-picker-btn:hover {
  border-color: rgba(215, 47, 47, 0.5);
  background: rgba(26, 29, 39, 0.7);
}
.sand-picker-btn:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(215, 47, 47, 0.2);
}

/* Transaction Success Effects */
.transaction-success {
  animation: successFlash 0.6s ease-out;
}

@keyframes successFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
  }
  50% {
    box-shadow: 0 0 0 15px rgba(46, 204, 113, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0);
  }
}

@keyframes screenFlash {
  0% {
    background-color: rgba(46, 204, 113, 0.15);
  }
  100% {
    background-color: rgba(6, 7, 10, 0);
  }
}

.screen-flash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  animation: screenFlash 0.5s ease-out;
  z-index: 999;
}

/* Particle/Confetti Effects */
.particle {
  position: fixed;
  pointer-events: none;
  z-index: 998;
}

@keyframes fall {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) rotate(360deg);
    opacity: 0;
  }
}

@keyframes bounce {
  0% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-40px) scale(1.1);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

.particle.confetti {
  animation: fall 2.5s ease-out forwards;
}

.particle.pop {
  animation: bounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Success Toast Enhanced */
.success-toast {
  position: fixed;
  left: 50%;
  bottom: 6.8rem;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(46, 204, 113, 0.2), rgba(26, 29, 39, 0.95));
  border: 1.5px solid rgba(46, 204, 113, 0.4);
  color: var(--green);
  padding: 1rem 1.5rem;
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(46, 204, 113, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 997;
  font-weight: 600;
  animation: slideInUp 0.4s ease-out forwards;
}

@keyframes slideInUp {
  from {
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}

.success-toast.show {
  opacity: 1;
}

@media (min-width: 760px) {
  .app-shell { padding: 1.4rem 1.4rem 6rem; }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bottom-nav { left: auto; right: 1.4rem; transform: none; }
}
