/* ============================================================
   GST Calculator — CodeByRushi
   Production Android calculator UI

   Layout strategy
   ───────────────
   • Body is a flex column that fills exactly 100dvh.
   • The keypad is a flex child with flex-shrink: 0 and a
     vertical gap, so it NEVER gets pushed off screen — the
     content above it shrinks instead.
   • The main area (header + display + rates + results) uses
     flex: 1 1 0 + min-height: 0 so it can shrink when needed
     without pushing the keypad out.
   • No fixed pixel heights anywhere. Every section uses clamp(),
     min(), or dvh units.
   • Padding-bottom uses max(12px, env(safe-area-inset-bottom))
     to work on both gesture navigation and classic 3-button nav.
   • Padding-top uses env(safe-area-inset-top) for notched phones.
   • Fluid typography with clamp(18px, 4vw, 34px) etc.
   ============================================================ */

/* ────────────── Reset ────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  height: 100%;
}

body {
  font-family: "SamsungOne", system-ui, -apple-system, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  overflow: hidden;            /* never scroll on the calculator surface */
  min-height: 100vh;           /* fallback */
  min-height: 100dvh;          /* preferred */
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus { outline: none; }
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   THEME TOKENS
   ============================================================ */
:root,
[data-theme="dark"] {
  --bg:           #0F1115;
  --surface-1:    #1A1D24;
  --surface-2:    #22262F;
  --surface-3:    #2D323D;
  --surface-soft: rgba(255, 255, 255, 0.04);

  --text:         #F2F4F8;
  --text-muted:   #9AA3B2;
  --text-faint:   #5C6473;

  --accent:       #7C5CFF;
  --accent-deep:  #6446E0;
  --accent-soft:  rgba(124, 92, 255, 0.18);
  --accent-glow:  rgba(124, 92, 255, 0.35);

  --separator:    rgba(255, 255, 255, 0.06);
  --shadow-card:  0 1px 0 rgba(255, 255, 255, 0.04) inset,
                 0 4px 18px rgba(0, 0, 0, 0.35);
  --shadow-hero:  0 8px 32px rgba(124, 92, 255, 0.25);
  --shadow-key:   0 1px 0 rgba(255, 255, 255, 0.04) inset,
                 0 2px 6px rgba(0, 0, 0, 0.25);

  --meta-theme:   #0F1115;
}

[data-theme="light"] {
  --bg:           #F4F6FB;
  --surface-1:    #FFFFFF;
  --surface-2:    #ECEEF4;
  --surface-3:    #DDE1EB;
  --surface-soft: rgba(15, 17, 21, 0.04);

  --text:         #0F1115;
  --text-muted:   #5C6473;
  --text-faint:   #94A0B0;

  --accent:       #5840E6;
  --accent-deep:  #3F2BC0;
  --accent-soft:  rgba(88, 64, 230, 0.10);
  --accent-glow:  rgba(88, 64, 230, 0.22);

  --separator:    rgba(15, 17, 21, 0.07);
  --shadow-card:  0 1px 2px rgba(15, 17, 21, 0.04),
                 0 4px 14px rgba(15, 17, 21, 0.06);
  --shadow-hero:  0 8px 28px rgba(88, 64, 230, 0.18);
  --shadow-key:   0 1px 2px rgba(15, 17, 21, 0.04);

  --meta-theme:   #F4F6FB;
}

/* Design tokens */
:root {
  --radius-sm:   10px;
  --radius-md:   14px;
  --radius-lg:   18px;
  --radius-xl:   22px;
  --radius-pill: 999px;

  --ease:        cubic-bezier(0.16, 1, 0.3, 1);
  --ease-quick:  cubic-bezier(0.4, 0, 0.2, 1);

  /* Drawer width — also referenced by JS to set --drawer-w for the
     segIndicator transform math, so keep this in sync. */
  --drawer-w:    78%;
  --drawer-max:  320px;
}

/* Smooth theme switching on color-bearing properties */
body,
.app,
.card,
.key,
.rate-btn,
.icon-btn,
.breakdown,
.breakdown-body,
.display,
.segmented,
.drawer,
.drawer-item,
.modal-card,
.modal-scrim {
  transition: background-color 0.3s var(--ease),
              color 0.3s var(--ease),
              border-color 0.3s var(--ease),
              box-shadow 0.3s var(--ease);
}

/* ============================================================
   APP SHELL — fills 100dvh, never overflows
   ============================================================ */
.app {
  height: 100vh;          /* fallback */
  height: 100dvh;         /* preferred */
  display: flex;
  flex-direction: column;
  background: var(--bg);
  width: 100%;
  max-width: 440px;        /* desktop preview centered */
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  /* When the drawer is open, push the app surface to the right */
  transition: transform 0.32s var(--ease);
}

/* Desktop: subtle background bleed around the phone-shaped card */
@media (min-width: 481px) {
  body {
    background:
      radial-gradient(1200px 800px at 50% -20%, rgba(124, 92, 255, 0.18), transparent 60%),
      radial-gradient(900px 700px at 50% 120%, rgba(124, 92, 255, 0.12), transparent 60%),
      #0a0c10;
  }
  body:has([data-theme="light"]) {
    background: #E9ECF3;
  }
  .app {
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  }
}

/* ============================================================
   SCRIM — overlay behind the drawer
   ============================================================ */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  z-index: 50;
  transition: background-color 0.3s var(--ease);
}

body.drawer-open .scrim {
  background: rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

/* ============================================================
   DRAWER — Material 3 navigation drawer (modal style)
   Slides from the left. Pinned at the top of the stacking
   context (above the scrim) so taps on it never go through.
   ============================================================ */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100dvh;
  width: var(--drawer-w);
  max-width: var(--drawer-max);
  background: var(--surface-1);
  color: var(--text);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(-105%);
  transition: transform 0.32s var(--ease);
  box-shadow: 0 0 0 0 transparent;
  will-change: transform;
  border-top-right-radius: var(--radius-xl);
  border-bottom-right-radius: var(--radius-xl);
  overflow: hidden;
}

body.drawer-open .drawer {
  transform: translateX(0);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.drawer-header {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2.5vw, 14px);
  padding:
    max(env(safe-area-inset-top, 0px), 18px)
    clamp(16px, 4vw, 22px)
    clamp(16px, 4vw, 22px);
  background:
    linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.drawer-header::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 60%;
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0));
  pointer-events: none;
}

.drawer-avatar {
  width: clamp(40px, 10vw, 48px);
  height: clamp(40px, 10vw, 48px);
  border-radius: clamp(12px, 3vw, 16px);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.drawer-titles { min-width: 0; position: relative; z-index: 1; }
.drawer-title  {
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-subtitle {
  font-size: clamp(11px, 2.8vw, 13px);
  font-weight: 500;
  opacity: 0.9;
  margin-top: 2px;
  letter-spacing: 0.2px;
}

.drawer-nav {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: clamp(8px, 2vw, 12px) clamp(6px, 1.5vw, 10px);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: clamp(12px, 3vw, 16px);
  width: 100%;
  padding: clamp(11px, 2.6vw, 14px) clamp(12px, 3vw, 16px);
  border-radius: var(--radius-pill);
  color: var(--text);
  font-size: clamp(13px, 3.4vw, 15px);
  font-weight: 500;
  letter-spacing: 0.1px;
  text-align: left;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.drawer-item:active {
  background: var(--surface-soft);
}

.drawer-item-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.drawer-item-icon svg {
  width: 20px;
  height: 20px;
}

.drawer-item-label {
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-item-chev {
  display: grid;
  place-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.25s var(--ease);
}

.drawer-item-expandable.expanded .drawer-item-chev {
  transform: rotate(180deg);
}

.drawer-sep {
  height: 1px;
  background: var(--separator);
  margin: clamp(4px, 1vw, 8px) clamp(12px, 3vw, 18px);
}

.drawer-footer {
  padding: clamp(8px, 2vw, 12px) clamp(16px, 4vw, 22px) max(env(safe-area-inset-bottom, 0px), 12px);
  border-top: 1px solid var(--separator);
}

.drawer-version {
  font-size: clamp(10px, 2.5vw, 12px);
  color: var(--text-faint);
  text-align: center;
  font-weight: 500;
  letter-spacing: 0.4px;
}

/* Theme submenu — collapses to 0 height via grid trick */
.drawer-submenu {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s var(--ease),
              margin-top 0.28s var(--ease);
  margin-left: clamp(36px, 9vw, 40px);   /* indent under the icon column */
  margin-right: clamp(8px, 2vw, 10px);
  margin-top: 0;
  overflow: hidden;
}

.drawer-item-expandable.expanded .drawer-submenu {
  grid-template-rows: 1fr;
  margin-top: 4px;
}

.drawer-submenu > * {
  min-height: 0;
}

.drawer-subitem {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2.5vw, 12px);
  width: 100%;
  padding: clamp(8px, 2vw, 10px) clamp(10px, 2.5vw, 12px);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: clamp(12px, 3vw, 14px);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.drawer-subitem:active {
  background: var(--surface-soft);
}

.drawer-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--text-faint);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color 0.2s var(--ease),
              background 0.2s var(--ease);
  position: relative;
}

.drawer-radio::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  transition: transform 0.2s var(--ease);
}

.drawer-subitem[aria-checked="true"] .drawer-radio {
  border-color: var(--accent);
}

.drawer-subitem[aria-checked="true"] .drawer-radio::after {
  transform: scale(1);
}

.drawer-subitem[aria-checked="true"] {
  color: var(--accent);
  font-weight: 600;
}

/* ============================================================
   ABOUT MODAL
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 24px);
}

.modal.open {
  display: flex;
  animation: modalIn 0.22s var(--ease);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 0;
  animation: scrimIn 0.22s var(--ease);
}

@keyframes scrimIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  position: relative;
  z-index: 1;
  background: var(--surface-1);
  color: var(--text);
  border-radius: var(--radius-xl);
  padding: clamp(18px, 4.5vw, 24px);
  max-width: 360px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 2vw, 10px);
}

.modal-title {
  font-size: clamp(18px, 4.5vw, 22px);
  font-weight: 700;
  letter-spacing: -0.4px;
  margin: 0;
}

.modal-version {
  font-size: clamp(11px, 2.8vw, 13px);
  color: var(--text-muted);
  font-weight: 500;
  margin: 0;
}

.modal-developer {
  font-size: clamp(12px, 3vw, 14px);
  color: var(--text);
  margin: 0;
}

.modal-body {
  font-size: clamp(12px, 3vw, 14px);
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.modal-btn {
  margin-top: clamp(8px, 2vw, 12px);
  align-self: flex-end;
  padding: clamp(9px, 2.2vw, 11px) clamp(18px, 4.5vw, 22px);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-pill);
  font-size: clamp(12px, 3vw, 14px);
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: background 0.15s var(--ease-quick),
              transform 0.1s var(--ease-quick);
}

.modal-btn:active {
  background: var(--accent-deep);
  transform: scale(0.97);
}

/* ============================================================
   BREAKDOWN-OPEN STATE
   When the user opens the tax breakdown, hide the keypad and
   let .app-main grow to fill the freed space. The summary
   row is also hidden so the breakdown owns the full results
   area and shows all three rows + the back button.
   ============================================================ */
body.breakdown-open .keypad {
  display: none;
}

body.breakdown-open .breakdown-summary {
  display: none;
}

body.breakdown-open .app-main {
  flex: 1 1 0;
  overflow: hidden;     /* keep the grid trick contained */
}

body.breakdown-open .results {
  flex: 1 1 0;
}

body.breakdown-open .breakdown {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

body.breakdown-open .breakdown-body {
  flex: 1 1 0;
}

.keypad {
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

body.breakdown-open .keypad {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

/* ============================================================
   HEADER — slim, fixed-height content
   ============================================================ */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding:
    max(env(safe-area-inset-top, 0px), 8px)
    clamp(12px, 3vw, 18px)
    clamp(6px, 1.5vw, 10px);
  gap: clamp(8px, 2vw, 12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 12px);
  min-width: 0;
}

.brand-mark {
  width: clamp(32px, 8vw, 40px);
  height: clamp(32px, 8vw, 40px);
  border-radius: clamp(8px, 2vw, 12px);
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-mark svg {
  width: clamp(18px, 4.5vw, 22px);
  height: clamp(18px, 4.5vw, 22px);
}

.header-titles {
  min-width: 0;
}

.app-title {
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-subtitle {
  font-size: clamp(10px, 2.5vw, 12px);
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
  letter-spacing: 0.2px;
}

/* Icon button (hamburger) — replaces the old theme-toggle pill */
.icon-btn {
  width: clamp(36px, 9vw, 42px);
  height: clamp(36px, 9vw, 42px);
  border-radius: 50%;
  background: var(--surface-1);
  color: var(--text);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-key);
  cursor: pointer;
  transition: background 0.2s var(--ease),
              transform 0.1s var(--ease-quick);
}

.icon-btn:active {
  transform: scale(0.92);
  background: var(--surface-2);
}

.icon-btn svg {
  width: clamp(18px, 4.5vw, 22px);
  height: clamp(18px, 4.5vw, 22px);
}

/* ============================================================
   RIPPLE — shared Material-style ripple effect.
   Triggered by adding a .ripple <span> inside the button on click.
   .ripple is removed automatically by the JS once the animation ends.
   ============================================================ */
.ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  background: currentColor;
  opacity: 0.35;
  pointer-events: none;
  animation: rippleOut 0.55s var(--ease) forwards;
}

@keyframes rippleOut {
  to {
    transform: scale(2.4);
    opacity: 0;
  }
}

/* ============================================================
   MAIN — flexible, can shrink, but never overflows
   ============================================================ */
.app-main {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.5vw, 12px);
  padding: 0 clamp(12px, 3vw, 16px) clamp(8px, 2vw, 12px);
  overflow: hidden;
}

/* ============================================================
   GST MODE TOGGLE — animated segmented control
   ============================================================ */
.gst-mode {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(4px, 1vw, 6px);
}

.gst-mode-label {
  font-size: clamp(9px, 2.2vw, 11px);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: clamp(0.4px, 0.1vw, 0.8px);
  padding-left: 4px;
}

.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 3px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18);
  isolation: isolate;
  overflow: hidden;
}

.seg-btn {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vw, 6px);
  padding: clamp(7px, 1.8vw, 9px) clamp(8px, 2vw, 12px);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-size: clamp(12px, 3.2vw, 14px);
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  overflow: hidden;
  transition: color 0.25s var(--ease),
              transform 0.1s var(--ease-quick);
  -webkit-user-select: none;
  user-select: none;
}

.seg-btn:active { transform: scale(0.97); }

.seg-btn.active { color: #fff; }

.seg-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  font-size: clamp(14px, 3.5vw, 16px);
  font-weight: 800;
  line-height: 1;
}

.seg-indicator {
  position: absolute;
  z-index: 0;
  top: 3px;
  left: 3px;
  bottom: 3px;
  width: calc(50% - 3px);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  border-radius: var(--radius-pill);
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform 0.32s var(--ease);
  will-change: transform;
}

/* JS sets --seg-translate on the indicator when the user switches
   segments. We translate the indicator element itself so the
   spring-style timing function produces a fluid slide. */
.seg-indicator {
  transform: translateX(var(--seg-translate, 0));
}

/* ============================================================
   DISPLAY — flexible height, large fluid number
   ============================================================ */
.display {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vw, 16px) clamp(10px, 3vw, 16px);
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  text-align: center;
  gap: clamp(2px, 0.5vw, 4px);
  min-height: 0;
}

.display-label {
  font-size: clamp(9px, 2.2vw, 11px);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: clamp(0.4px, 0.1vw, 0.8px);
}

.display-amount {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: clamp(2px, 0.5vw, 4px);
  width: 100%;
  min-width: 0;
  line-height: 1;
}

.currency-symbol {
  font-size: clamp(16px, 4.2vw, 22px);
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.amount-value {
  /* Fluid font that never breaks the layout on small screens */
  font-size: clamp(28px, 8.5vw, 44px);
  font-weight: 700;
  letter-spacing: -1.2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.display-tag {
  font-size: clamp(9px, 2.2vw, 11px);
  color: var(--text-faint);
  letter-spacing: 0.2px;
  font-weight: 500;
}

/* ============================================================
   RATE PILLS
   ============================================================ */
.rates {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(6px, 1.5vw, 8px);
}

.rate-btn {
  height: clamp(36px, 8vw, 44px);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--text);
  font-size: clamp(13px, 3.5vw, 15px);
  font-weight: 600;
  letter-spacing: -0.2px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s var(--ease-quick),
              background 0.2s var(--ease),
              color 0.2s var(--ease),
              box-shadow 0.25s var(--ease);
}

.rate-btn:active {
  transform: scale(0.94);
  background: var(--surface-2);
}

.rate-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.rate-btn.active::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0) 50%);
  pointer-events: none;
}

/* ============================================================
   RESULTS — flexible, can shrink vertically
   ============================================================ */
.results {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.5vw, 8px);
}

/* ============================================================
   CARDS — auto height, no clipping
   ============================================================ */
.card {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  padding: clamp(10px, 2.4vw, 14px) clamp(12px, 3vw, 16px);
  box-shadow: var(--shadow-card);
  min-width: 0;
}

/* Hero card — auto height, never clips the value */
.card.hero {
  background:
    linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
  padding: clamp(10px, 2.4vw, 16px) clamp(12px, 3vw, 18px);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-hero);
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
}

.card.hero::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0));
  pointer-events: none;
  border-radius: inherit;
}

.card-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: clamp(9px, 2.2vw, 11px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: clamp(0.4px, 0.1vw, 0.8px);
  opacity: 0.92;
  position: relative;
  z-index: 1;
}

.card-tag {
  font-size: clamp(8px, 2vw, 10px);
  font-weight: 600;
  padding: clamp(2px, 0.5vw, 3px) clamp(6px, 1.5vw, 8px);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.18);
  letter-spacing: 0.4px;
}

.card-value {
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 700;
  letter-spacing: -0.8px;
  margin-top: clamp(2px, 0.5vw, 4px);
  font-variant-numeric: tabular-nums;
  position: relative;
  z-index: 1;
  word-break: break-all;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.card.hero .card-value,
.hero-value {
  font-size: clamp(22px, 6.5vw, 30px);
  letter-spacing: -0.8px;
  line-height: 1.1;
}

.card-row {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(6px, 1.5vw, 10px);
}

.card-label-sm {
  font-size: clamp(9px, 2.2vw, 10px);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: clamp(2px, 0.5vw, 4px);
}

.card-value-sm {
  font-size: clamp(15px, 4.2vw, 19px);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  overflow-wrap: anywhere;
  line-height: 1.15;
}

@keyframes valuePulse {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.025); }
  100% { transform: scale(1); }
}

.value-changed {
  animation: valuePulse 0.32s var(--ease);
}

/* ============================================================
   CGST/SGST/IGST BREAKDOWN — polished M3 appearance
   ============================================================ */
.breakdown {
  flex: 0 0 auto;
  background: var(--surface-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.breakdown-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(8px, 2vw, 11px) clamp(12px, 3vw, 14px);
  font-size: clamp(11px, 3vw, 13px);
  font-weight: 600;
  color: var(--text);
  user-select: none;
  gap: 8px;
}

.breakdown-summary::-webkit-details-marker { display: none; }

.breakdown-summary .chev {
  transition: transform 0.3s var(--ease);
  color: var(--accent);
  flex-shrink: 0;
}

.breakdown[open] .breakdown-summary .chev {
  transform: rotate(180deg);
}

/* We use the grid 0fr → 1fr trick to animate the open/close. */
.breakdown-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.32s var(--ease);
  padding: 0 clamp(12px, 3vw, 14px);
}

.breakdown[open] .breakdown-body {
  grid-template-rows: 1fr;
  padding: 0 clamp(12px, 3vw, 14px) clamp(10px, 2.5vw, 14px);
}

.breakdown-inner {
  min-height: 0;
  overflow: hidden;
}

.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(6px, 1.4vw, 8px) 0;
  border-top: 1px solid var(--separator);
  font-size: clamp(12px, 3vw, 14px);
  color: var(--text);
  overflow: hidden;
  gap: 8px;
}

.breakdown-row:first-child {
  border-top: none;
}

.breakdown-label {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breakdown-label em {
  color: var(--text-faint);
  font-style: normal;
  font-weight: 500;
  margin-left: 4px;
}

.breakdown-amount {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
  flex-shrink: 0;
}

.breakdown-back {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.5vw, 8px);
  width: 100%;
  margin-top: clamp(10px, 2.5vw, 14px);
  padding: clamp(10px, 2.5vw, 12px);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: clamp(12px, 3vw, 14px);
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: background 0.15s var(--ease-quick),
              transform 0.1s var(--ease-quick);
}

.breakdown-back:active {
  background: var(--accent-deep);
  transform: scale(0.97);
}

.breakdown-back svg {
  flex-shrink: 0;
}

/* ============================================================
   HIDDEN INPUT
   ============================================================ */
.hidden-input {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: 0;
  padding: 0;
  margin: 0;
}

/* ============================================================
   NUMERIC KEYPAD — smaller / more compact
   New key order:
       1 2 3
       4 5 6
       7 8 9
       0 ⌫ .
   00 + CLEAR are now in the secondary row.
   ============================================================ */
.keypad {
  flex: 0 0 auto;
  padding:
    clamp(6px, 1.5vw, 10px)
    clamp(12px, 3vw, 16px)
    max(env(safe-area-inset-bottom, 0px), clamp(8px, 2vw, 12px));
  background: var(--bg);
  border-top: 1px solid var(--separator);
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1vw, 6px);   /* tighter vertical gap */
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(5px, 1.2vw, 8px);
}

.key {
  /* Slightly smaller than before — comfortable but compact. */
  height: clamp(40px, 9.5dvh, 54px);
  min-height: 40px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: clamp(17px, 4.6vw, 22px);
  font-weight: 600;
  letter-spacing: -0.4px;
  font-variant-numeric: tabular-nums;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-key);
  transition: background 0.12s var(--ease-quick),
              transform 0.1s var(--ease-quick),
              color 0.2s var(--ease);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.key:active {
  background: var(--surface-3);
  transform: scale(0.96);
}

.key-backspace {
  color: var(--accent);
}

.key-backspace svg {
  width: clamp(18px, 4.6vw, 22px);
  height: clamp(18px, 4.6vw, 22px);
}

.keypad-secondary {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: clamp(5px, 1.2vw, 8px);
}

.key-double {
  background: var(--surface-2);
  font-size: clamp(15px, 4vw, 20px);
}

.key-clear {
  background: var(--accent);
  color: #fff;
  font-size: clamp(11px, 3vw, 14px);
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.key-clear:active {
  background: var(--accent-deep);
  transform: scale(0.97);
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   VERY SHORT SCREENS — extra tightening
   ============================================================ */
@media (max-height: 640px) {
  .app-header      { padding-top: 4px; padding-bottom: 4px; }
  .app-main        { gap: 6px; }
  .display         { padding: 6px 10px; }
  .amount-value    { font-size: clamp(24px, 7vw, 36px); }
  .card            { padding: 8px 12px; }
  .rate-btn        { height: 36px; }
  .key             { height: 40px; }
}

/* ============================================================
   UPDATE BANNER
   Shown when a new Service Worker is installed and waiting to take
   over. Sits above the keypad on mobile, anchored to the bottom on
   desktop, and respects iOS safe-area insets.
   ============================================================ */
.update-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
  display: none;                        /* hidden until .show is set */
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, #1A2230 0%, #151B25 100%);
  color: var(--text, #E6E8EE);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 14px;
  line-height: 1.3;
  transform: translateY(20px);
  opacity: 0;
  transition: transform 220ms ease, opacity 220ms ease;
}

.update-banner.show {
  display: flex;
  transform: translateY(0);
  opacity: 1;
}

.update-banner-text {
  flex: 1 1 auto;
  min-width: 0;
}

.update-banner-btn {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #0B0D12;
  background: #6EE7B7;                  /* accent — high contrast on dark */
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.update-banner-btn:hover  { background: #86efac; }
.update-banner-btn:active { transform: scale(0.97); }
.update-banner-btn:focus-visible {
  outline: 2px solid #6EE7B7;
  outline-offset: 2px;
}

/* Light theme variant — keep the banner readable in light mode. */
[data-theme="light"] .update-banner {
  background: linear-gradient(180deg, #ffffff 0%, #f3f4f6 100%);
  color: #0F1115;
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .update-banner-btn { color: #0B0D12; background: #0EA972; }
[data-theme="light"] .update-banner-btn:hover { background: #10b981; }
[data-theme="light"] .update-banner-btn:focus-visible { outline-color: #0EA972; }

/* On very small screens, give the text a bit more breathing room. */
@media (max-width: 360px) {
  .update-banner     { font-size: 13px; padding: 10px 12px; }
  .update-banner-btn { padding: 7px 12px; font-size: 13px; }
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .update-banner { transition: none; }
}
