:root {
  --bg: #0a0b14;
  --bg-soft: #0f1120;
  --card: #121528;
  --text: #e8ecf1;
  --muted: #a5afc3;
  --primary: #7c5cff;
  --primary-2: #3ad1ff;
  --accent: #00ffb3;
  --danger: #ff476f;
  --glow: 0 0 24px rgba(124, 92, 255, 0.4);
}

/* Light theme variables */
.theme-light {
  --bg: #f5f7fb;
  --bg-soft: #eef2fb;
  --card: #ffffff;
  --text: #0e1117;
  --muted: #5b6b8a;
  --primary: #6a5cff;
  --primary-2: #02a1ff;
  --accent: #00c896;
  --danger: #ff3b61;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; min-height: 100vh; width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(1200px 800px at 20% 10%, rgba(124,92,255,0.15), transparent 60%),
              radial-gradient(1000px 700px at 80% 30%, rgba(58,209,255,0.12), transparent 60%),
              var(--bg);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-text-size-adjust: 100%;
}

#bg-canvas { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

.app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; width: 100%; max-width: 100vw; overflow-x: hidden; }

.app-header {
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 14px 20px; backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: linear-gradient(180deg, rgba(0,0,0,0.35), transparent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 20px; color: var(--primary-2); filter: drop-shadow(0 0 8px rgba(58,209,255,0.6)); }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: 0.4px; }

.nav { display: flex; gap: 8px; flex-wrap: wrap; }
.nav-btn {
  background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.12);
  padding: 8px 12px; border-radius: 10px; cursor: pointer; font-size: 14px;
}
.nav-btn.active, .nav-btn:hover { border-color: var(--primary); box-shadow: var(--glow); }

.hamburger { display: none; flex-direction: column; gap: 4px; background: transparent; border: none; cursor: pointer; padding: 8px; }
.hamburger span { display: block; width: 24px; height: 2px; background: var(--text); transition: 0.3s; border-radius: 2px; }
.hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(7px, -6px); }

.auth-area { display: flex; align-items: center; gap: 8px; position: relative; }

.user-menu { position: relative; }
.user-menu-btn { cursor: pointer; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--card); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; padding: 12px; min-width: 200px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  opacity: 0; visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  z-index: 100;
  pointer-events: none;
}
.user-menu:hover .user-dropdown {
  opacity: 1; visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}
.user-email {
  color: var(--text); font-size: 13px; padding: 8px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 8px; word-break: break-word;
}
.user-dropdown .btn { width: 100%; justify-content: center; }

.view { padding: 20px; max-width: 1200px; margin: 0 auto; width: 100%; flex: 1; box-sizing: border-box; overflow-x: hidden; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 18px; flex-wrap: wrap; }
.section-header h2 { margin: 0; font-size: 22px; color: var(--text); }
.section-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid.one { display: grid; grid-template-columns: 1fr; gap: 16px; }

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.08); border-radius: 16px; padding: 20px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset, 0 10px 40px rgba(0,0,0,0.25);
}
.auth-card { width: min(360px, 94vw); }
.card h3 { margin: 0 0 14px 0; font-size: 16px; color: var(--primary-2); }

.btn { background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.16); padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.btn.primary { background: linear-gradient(90deg, var(--primary), var(--primary-2)); border: none; box-shadow: var(--glow); }
.btn.ghost { border: 1px dashed rgba(255,255,255,0.2); }
.btn.icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; font-size: 18px; padding: 0; }

.form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; }
label > span { font-weight: 600; font-size: 13px; color: var(--text); opacity: 0.9; }
input, select { background: var(--bg-soft); color: var(--text); border: 1px solid rgba(255,255,255,0.12); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.row { display: flex; align-items: center; }
.row.g { gap: 8px; }
.muted { color: var(--muted); }

.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; padding: 14px; text-align: center; }
.stat span { color: var(--primary-2); font-size: 11px; display: block; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; margin-bottom: 6px; }
.stat strong { font-size: 20px; color: var(--text); display: block; }

.scroll { max-height: 380px; overflow-y: auto; overflow-x: hidden; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.summary { display: grid; gap: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 10px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.table th { position: sticky; top: 0; background: var(--card); z-index: 1; }

.route { display: none; }
.route.active { display: block; animation: fadeIn 300ms ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.app-footer { padding: 14px 20px; color: var(--muted); border-top: 1px solid rgba(255,255,255,0.06); backdrop-filter: blur(8px); background: linear-gradient(0deg, rgba(0,0,0,0.35), transparent); }

/* Calculator */
.calculator { max-width: 420px; }
.calc-display { width: 100%; font-size: 24px; padding: 12px; background: var(--bg-soft); border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; margin-bottom: 10px; text-align: right; }
.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.calc-grid button { padding: 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.14); background: rgba(255,255,255,0.03); color: var(--text); font-size: 16px; cursor: pointer; }
.calc-grid button.op { background: linear-gradient(90deg, rgba(124,92,255,0.25), rgba(58,209,255,0.25)); border: none; }
.calc-grid button.equals { background: linear-gradient(90deg, var(--accent), var(--primary-2)); color: #002216; border: none; }

/* Dialog */
dialog::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
dialog { 
  border: none; 
  background: transparent; 
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}
dialog .card h2 { color: var(--text); margin: 0 0 8px 0; }
dialog .card h3 { color: var(--text); margin: 0 0 16px 0; }
dialog .card .muted { color: var(--muted); margin-bottom: 16px; }

/* Custom dialogs */
.custom-dialog::backdrop { background: rgba(0,0,0,0.7); backdrop-filter: blur(6px); }
.custom-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}
.dialog-card { max-width: 420px; min-width: 300px; margin: auto; }
.dialog-message { color: var(--text); line-height: 1.6; margin: 0 0 16px 0; }
.dialog-input {
  width: 100%; background: var(--bg-soft); color: var(--text);
  border: 1px solid rgba(255,255,255,0.12); padding: 10px 12px;
  border-radius: 10px; margin-bottom: 16px; font-size: 14px;
}
.dialog-input:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Toast notifications */
#notif-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
  background: var(--card); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; padding: 12px 16px; min-width: 200px; max-width: 350px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  opacity: 0; transform: translateX(100px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-info { border-left: 3px solid var(--primary-2); }
.toast-success { border-left: 3px solid var(--accent); }
.toast-error { border-left: 3px solid var(--danger); }

.payment-card { max-width: 420px; }
.payment-instructions { 
  background: linear-gradient(135deg, rgba(124,92,255,0.1), rgba(58,209,255,0.1));
  border: 1px solid rgba(124,92,255,0.3);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.payment-label { color: var(--muted); font-size: 13px; margin: 0 0 12px 0; }
.payment-details { 
  background: rgba(0,0,0,0.2); border-radius: 8px; padding: 12px;
  margin-bottom: 12px; text-align: center;
}
.payment-name { 
  color: var(--primary-2); font-size: 18px; font-weight: 600;
  margin-bottom: 6px;
}
.payment-upi { 
  color: var(--text); font-size: 14px; font-family: monospace;
  background: rgba(255,255,255,0.05); padding: 8px 12px;
  border-radius: 6px; margin-bottom: 8px; word-break: break-all;
}
.payment-amount-display {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-top: 1px solid rgba(255,255,255,0.1);
}
.payment-amount-display span { color: var(--muted); font-size: 13px; }
.payment-amount-display strong { color: var(--accent); font-size: 20px; }

/* Responsive */
@media (max-width: 920px) {
  .grid.two { grid-template-columns: 1fr; }
  .results { grid-template-columns: 1fr; }
  .nav { flex: 1; overflow: auto; }
  .card { padding: 16px; }
  .view { padding: 16px; }
}

@media (max-width: 640px) {
  body { font-size: 11px; }
  
  .app-header { 
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-rows: auto auto;
    gap: 4px;
    padding: 6px 8px;
  }
  .brand { grid-column: 1; grid-row: 1; }
  .brand h1 { font-size: 12px; }
  .brand .logo { font-size: 16px; }
  
  .hamburger { 
    display: flex;
    grid-column: 2;
    grid-row: 1;
  }
  
  .auth-area { 
    grid-column: 3;
    grid-row: 1;
    gap: 6px;
  }
  
  .nav {
    grid-column: 1 / -1;
    grid-row: 2;
    background: linear-gradient(180deg, rgba(0,0,0,0.2), transparent);
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-direction: column;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin: 0 -8px;
    padding: 0;
  }
  .nav.active { max-height: 240px; padding: 4px 0; }
  .nav-btn { 
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    border-radius: 0;
    padding: 10px 12px;
    text-align: left;
    font-size: 12px;
  }
  .nav-btn:hover, .nav-btn.active { 
    background: rgba(124,92,255,0.1);
    box-shadow: none;
  }
  
  .user-dropdown { right: -10px; min-width: 160px; }
  .view { padding: 4px; width: 100%; max-width: 100vw; box-sizing: border-box; }
  .section-header { margin: 0 0 4px; width: 100%; }
  .section-header h2 { font-size: 12px; }
  .section-header .actions { width: 100%; }
  .btn { font-size: 10px; padding: 4px 6px; white-space: nowrap; }
  .stat { padding: 4px; }
  .stat span { font-size: 9px; margin-bottom: 3px; }
  .stat strong { font-size: 12px; }
  .results { gap: 4px; grid-template-columns: repeat(3, 1fr); }
  .table { font-size: 9px; width: 100%; }
  .table th, .table td { padding: 4px 2px; white-space: normal; word-break: break-word; max-width: 80px; }
  .table th:first-child, .table td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
  .calculator { width: 100%; max-width: 100%; box-sizing: border-box; }
  .calc-grid button { padding: 8px; font-size: 12px; }
  .calc-grid { gap: 4px; width: 100%; }
  .calc-display { font-size: 18px; padding: 8px; margin-bottom: 6px; width: 100%; box-sizing: border-box; word-break: break-all; }
  .scroll { max-height: 140px; overflow-y: auto; overflow-x: hidden; }
  .scroll-x { max-width: 100vw; width: 100%; box-sizing: border-box; padding-right: 4px; }
  input, select { font-size: 13px; padding: 6px; }
  label > span { font-size: 11px; }
  label { gap: 4px; }
  .form { gap: 8px; width: 100%; }
  input, select { width: 100%; box-sizing: border-box; }
  .card { padding: 6px; margin-bottom: 6px; border-radius: 8px; width: 100%; box-sizing: border-box; }
  .card h3 { font-size: 12px; margin-bottom: 6px; }
  .grid.two { grid-template-columns: 1fr; gap: 6px; }
  .grid.one { gap: 6px; }
  .summary { gap: 6px; }
  .auth-card { padding: 12px; }
  .payment-card { padding: 10px; }
  .dialog-card { padding: 10px; min-width: 260px; }
  body { font-size: 13px; }
}
