/* ===================================================
   GST CALCULATOR — Premium Design System
   Dark / Light mode, Mobile-first, Glassmorphism
   =================================================== */

/* ---------- Google Fonts already loaded via HTML ---------- */

/* ===================== CSS VARIABLES ===================== */
:root {
  /* Brand */
  --accent:        #6366f1;
  --accent-light:  #818cf8;
  --accent-glow:   rgba(99, 102, 241, 0.35);
  --accent-subtle: rgba(99, 102, 241, 0.08);

  /* Orange */
  --orange:        #f97316;
  --orange-subtle: rgba(249, 115, 22, 0.12);

  /* Purple */
  --purple:        #a855f7;
  --purple-subtle: rgba(168, 85, 247, 0.12);

  /* Teal */
  --teal:          #14b8a6;
  --teal-subtle:   rgba(20, 184, 166, 0.12);

  /* Success */
  --success:       #22c55e;
  --danger:        #ef4444;

  /* === DARK MODE (default) === */
  --bg:            #0a0f1a;
  --bg-surface:    #0f1629;
  --bg-card:       rgba(15, 22, 41, 0.85);
  --bg-card-solid: #111827;
  --bg-input:      rgba(255, 255, 255, 0.04);
  --bg-input-focus:rgba(255, 255, 255, 0.07);
  --bg-chip:       rgba(255, 255, 255, 0.05);
  --bg-chip-hover: rgba(255, 255, 255, 0.09);

  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-accent: rgba(99, 102, 241, 0.4);

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --text-invert:   #0f172a;

  --shadow-sm:     0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:     0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:     0 12px 40px rgba(0,0,0,0.6);
  --shadow-accent: 0 0 40px rgba(99,102,241,0.18);

  /* Sizing */
  --radius-sm:  10px;
  --radius-md:  14px;
  --radius-lg:  20px;
  --radius-xl:  28px;
  --radius-full:9999px;

  /* Transitions */
  --ease:       cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast:   150ms;
  --dur-normal: 250ms;
  --dur-slow:   400ms;
}

/* ===== LIGHT MODE ===== */
[data-theme="light"] {
  --bg:            #f0f4ff;
  --bg-surface:    #e8eef9;
  --bg-card:       rgba(255, 255, 255, 0.92);
  --bg-card-solid: #ffffff;
  --bg-input:      rgba(0, 0, 0, 0.04);
  --bg-input-focus:rgba(0, 0, 0, 0.06);
  --bg-chip:       rgba(0, 0, 0, 0.04);
  --bg-chip-hover: rgba(0, 0, 0, 0.07);

  --border:        rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --border-accent: rgba(99, 102, 241, 0.35);

  --text-primary:  #0f172a;
  --text-secondary:#475569;
  --text-muted:    #94a3b8;
  --text-invert:   #f1f5f9;

  --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg:     0 12px 40px rgba(0,0,0,0.14);
  --shadow-accent: 0 0 40px rgba(99,102,241,0.12);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  transition: background var(--dur-normal) var(--ease),
              color var(--dur-normal) var(--ease);
  overflow-x: hidden;
}

/* ===================== ANIMATED BACKGROUND ===================== */
.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.25;
  animation: float 12s ease-in-out infinite;
}

.orb-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #6366f1, transparent 70%);
  top: -150px;
  right: -100px;
  animation-delay: 0s;
}

.orb-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #a855f7, transparent 70%);
  bottom: -100px;
  left: -80px;
  animation-delay: -4s;
}

.orb-3 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #14b8a6, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -8s;
}

[data-theme="light"] .orb { opacity: 0.12; }

@keyframes float {
  0%, 100% { transform: translateY(0px) scale(1); }
  33%       { transform: translateY(-30px) scale(1.05); }
  66%       { transform: translateY(15px) scale(0.97); }
}

/* ===================== APP SHELL ===================== */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===================== TOPBAR ===================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  background: rgba(10, 15, 26, 0.75);
  border-bottom: 1px solid var(--border);
  transition: background var(--dur-normal) var(--ease);
}

[data-theme="light"] .topbar {
  background: rgba(240, 244, 255, 0.80);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-dot {
  color: var(--accent);
}

.brand-badge {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: white;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  align-self: flex-start;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--dur-fast) var(--ease);
  position: relative;
}

.icon-btn:hover {
  background: var(--bg-chip-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.icon-moon { display: block; }
.icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: block; }

.history-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  background: var(--accent);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  transition: transform var(--dur-fast) var(--ease);
}

.history-badge.bump {
  animation: bump 0.3s var(--ease);
}

@keyframes bump {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); }
  100% { transform: scale(1); }
}

/* ===================== MAIN LAYOUT ===================== */
.main-layout {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 40px 20px 60px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

/* ===================== CALCULATOR PANEL ===================== */
.calculator-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 12px 0 4px;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-subtle);
  border: 1px solid var(--border-accent);
  color: var(--accent-light);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  margin-bottom: 18px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  50%       { opacity: 0.8; box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}

.hero-title {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--text-primary) 40%, var(--accent-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.65;
}

/* ---------- Calc Card ---------- */
.calc-card {
  background: var(--bg-card);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-lg), var(--shadow-accent);
  transition: all var(--dur-normal) var(--ease);
}

/* ---------- Field Groups ---------- */
.field-group {
  margin-bottom: 22px;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.field-input {
  width: 100%;
  height: 52px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  padding: 0 44px 0 46px;
  outline: none;
  transition: all var(--dur-fast) var(--ease);
  -webkit-appearance: none;
}

.field-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.field-input:focus {
  background: var(--bg-input-focus);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field-input.error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.2);
}

/* Remove number spinners */
.field-input[type="number"]::-webkit-inner-spin-button,
.field-input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
.field-input[type="number"] { -moz-appearance: textfield; }

.input-prefix,
.input-suffix {
  position: absolute;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
  user-select: none;
}

.input-prefix { left: 16px; }
.input-suffix { right: 16px; }

.field-input:not(:placeholder-shown) ~ .input-suffix,
.field-input:focus ~ .input-suffix {
  color: var(--accent-light);
}

.input-clear {
  position: absolute;
  right: 12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--dur-fast) var(--ease);
}

.input-clear:hover {
  background: var(--danger);
  color: white;
}

/* Custom rate: smaller prefix/suffix area */
#customRate { padding-right: 40px; padding-left: 16px; }

.field-hint {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--danger);
  min-height: 16px;
  transition: all var(--dur-fast) var(--ease);
}

/* ---------- Rate Grid ---------- */
.rate-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.rate-chip {
  background: var(--bg-chip);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  text-align: center;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 60px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.rate-chip:hover {
  background: var(--bg-chip-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.rate-chip.active {
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}

.rate-chip-pct {
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1;
}

.rate-chip-label {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  opacity: 0.75;
  text-transform: uppercase;
}

.rate-chip.active .rate-chip-label {
  opacity: 0.85;
}

/* ---------- 2-col row ---------- */
.row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ---------- Mode Toggle ---------- */
.mode-toggle {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.mode-btn {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* allow wrapping on very narrow screens */
  padding: 6px 4px;
}

.mode-btn:hover {
  color: var(--text-primary);
  background: var(--bg-chip-hover);
}

.mode-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: white;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* ---------- Actions ---------- */
.actions-row {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  border-radius: var(--radius-md);
  font-family: 'Outfit', sans-serif;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--dur-fast) var(--ease);
  /* no white-space: nowrap — allow text to breathe on small screens */
  padding: 0 16px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: white;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px var(--accent-glow);
  filter: brightness(1.1);
}

.btn-primary:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.btn-ghost {
  padding: 0 22px;
  background: var(--bg-chip);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.btn-ghost:hover {
  background: var(--bg-chip-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ---------- Results Section ---------- */
.results-section {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  animation: fadeSlideUp var(--dur-normal) var(--ease);
}

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

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.results-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  background: var(--bg-chip);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-family: 'Outfit', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}

.copy-btn:hover {
  background: var(--accent-subtle);
  border-color: var(--border-accent);
  color: var(--accent-light);
}

.copy-btn.copied {
  background: rgba(34,197,94,0.1);
  border-color: rgba(34,197,94,0.3);
  color: var(--success);
}

/* ---------- Result Tiles ---------- */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.result-tile {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all var(--dur-fast) var(--ease);
  position: relative;
  overflow: hidden;
}

.result-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease);
}

.result-tile.has-value::before {
  opacity: 1;
}

.result-tile-icon {
  width: 30px;
  height: 30px;
  background: var(--accent-subtle);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-light);
  margin-bottom: 2px;
  flex-shrink: 0;
}

.result-tile-icon.accent-orange { background: var(--orange-subtle); color: var(--orange); }
.result-tile-icon.accent-purple { background: var(--purple-subtle); color: var(--purple); }
.result-tile-icon.accent-teal   { background: var(--teal-subtle);   color: var(--teal); }

.result-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.result-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  transition: all var(--dur-normal) var(--ease);
}

.result-rate-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.mono {
  font-family: 'JetBrains Mono', 'Outfit', monospace;
}

/* Value pop animation */
@keyframes valuePop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.result-value.pop {
  animation: valuePop 0.3s var(--ease);
}

/* ---------- Total Banner ---------- */
.total-banner {
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(168,85,247,0.10));
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: all var(--dur-normal) var(--ease);
}

[data-theme="light"] .total-banner {
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(168,85,247,0.06));
}

.total-banner-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.total-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.total-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.total-sublabel {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.total-value {
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-light), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

/* ---------- Info Strip ---------- */
.info-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(12px);
  transition: all var(--dur-fast) var(--ease);
}

.info-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.info-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.info-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.info-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===================== HISTORY PANEL ===================== */
.history-panel {
  background: var(--bg-card);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.text-btn {
  font-family: 'Outfit', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all var(--dur-fast) var(--ease);
}

.text-btn.danger {
  color: var(--danger);
}

.text-btn.danger:hover {
  background: rgba(239,68,68,0.1);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.history-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.history-empty-icon {
  font-size: 2rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.history-empty p {
  font-size: 0.875rem;
  font-weight: 500;
}

.history-empty-sub {
  font-size: 0.75rem;
  margin-top: 4px;
  opacity: 0.7;
}

/* History Item */
.history-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  animation: fadeSlideUp var(--dur-fast) var(--ease);
}

.history-item:hover {
  background: var(--bg-chip-hover);
  border-color: var(--border-strong);
  transform: translateX(-2px);
}

.history-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.history-item-amount {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.history-item-rate {
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.history-item-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.8;
}

.history-item-row span:last-child {
  font-weight: 600;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
}

.history-item-total {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item-total-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-item-total-value {
  font-size: 0.875rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-family: 'JetBrains Mono', monospace;
}

.history-item-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===================== FOOTER ===================== */
.footer {
  border-top: 1px solid var(--border);
  padding: 20px;
  background: transparent;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

.footer-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 580px;
  margin: 0 auto 8px;
  line-height: 1.6;
}

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

.footer-dot { opacity: 0.4; }

/* ===================== TOAST ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: var(--text-invert);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  z-index: 999;
  transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ===================== DRAWER OVERLAY (Mobile) ===================== */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease);
}

.drawer-overlay.visible {
  opacity: 1;
}

/* ===================== RESPONSIVE ===================== */

/* --- Tablet --- */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: 28px 16px 48px;
  }

  .history-panel {
    position: fixed;
    inset-y: 0;
    right: -100%;
    width: min(380px, 90vw);
    border-radius: 0;
    border-left: 1px solid var(--border);
    top: 0;
    max-height: 100vh;
    max-height: 100dvh;
    z-index: 45;
    transition: right var(--dur-slow) var(--ease);
    box-shadow: var(--shadow-lg);
  }

  .history-panel.open {
    right: 0;
  }

  .drawer-overlay {
    display: block;
  }

  .info-strip {
    grid-template-columns: 1fr;
  }

  #historyToggle { display: flex; }
}

/* --- Mobile Large --- */
@media (max-width: 640px) {
  .topbar-inner {
    padding: 0 16px;
  }

  .brand-badge {
    display: none;
  }

  .calc-card {
    padding: 20px 16px;
    border-radius: var(--radius-lg);
  }

  /* Rate grid: 2 wide on mobile */
  .rate-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .rate-chip {
    padding: 14px 8px;
    min-height: 64px;
  }

  /* Stack the custom-rate + mode-toggle vertically */
  .row-2col {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* Results: single column */
  .results-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Result tiles: horizontal layout on mobile for compactness */
  .result-tile {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
  }

  .result-tile-icon {
    flex-shrink: 0;
  }

  .result-tile > .result-label {
    flex: 1;
    margin-bottom: 0;
  }

  .result-tile > .result-value {
    font-size: 1rem;
    text-align: right;
  }

  .result-tile > .result-rate-badge {
    display: none;
  }

  /* Total banner: keep horizontal but shrink padding */
  .total-banner {
    padding: 16px;
    gap: 12px;
  }

  .total-value {
    font-size: 1.375rem;
    flex-shrink: 0;
  }

  /* Actions: Stack Calculate on top full-width, Reset below */
  .actions-row {
    flex-direction: column;
    gap: 10px;
  }

  .btn-primary {
    width: 100%;
    height: 56px;
    font-size: 1rem;
    flex: unset;
  }

  .btn-ghost {
    width: 100%;
    height: 48px;
    padding: 0 16px;
    flex: unset;
  }

  .info-strip {
    display: none;
  }

  .hero-pill {
    font-size: 0.68rem;
  }

  .hero-subtitle {
    font-size: 0.875rem;
  }

  /* Mode toggle: taller tap targets on mobile */
  .mode-toggle {
    padding: 4px;
  }

  .mode-btn {
    min-height: 48px;
    font-size: 0.875rem;
  }

  /* Copy button: bigger tap target */
  .copy-btn {
    height: 36px;
    padding: 0 14px;
    font-size: 0.8rem;
  }

  /* Input fields: larger on mobile */
  .field-input {
    height: 54px;
    font-size: 1.0625rem;
  }
}

/* --- Mobile Small --- */
@media (max-width: 380px) {
  .main-layout {
    padding: 16px 10px 40px;
  }

  .calc-card {
    padding: 16px 12px;
  }

  .rate-chip {
    padding: 12px 4px;
    min-height: 60px;
  }

  .rate-chip-pct {
    font-size: 0.9375rem;
  }

  .rate-chip-label {
    font-size: 0.6rem;
  }

  .total-value {
    font-size: 1.25rem;
  }

  .hero-title {
    font-size: 1.75rem;
  }

  .btn-primary {
    height: 52px;
    font-size: 0.9375rem;
  }
}

/* ===================== UTILITY ===================== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}