:root {
  --bg-base: #0f1117;
  --bg-surface: #181c27;
  --bg-card: #1e2233;
  --bg-input: #252a3a;
  --border: #2e3450;
  --border-focus: #4f6ef7;
  --text-primary: #eef0f8;
  --text-secondary: #9aa0bc;
  --text-muted: #5c6280;
  --accent: #4f6ef7;
  --accent-glow: rgba(79, 110, 247, .25);
  --accent-hover: #3a58e0;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, .12);
  --red: #f43f5e;
  --red-bg: rgba(244, 63, 94, .12);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, .12);
  --notes-color: #818cf8;
  --notes-bg: rgba(129, 140, 248, .1);
  --coins-color: #34d399;
  --coins-bg: rgba(52, 211, 153, .1);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, .4);
  --shadow-glow: 0 0 40px rgba(79, 110, 247, .15);
  --transition: .2s ease;
}

[data-theme="light"] {
  --bg-base: #f0f2fa;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f4f5fb;
  --border: #dde1f0;
  --border-focus: #4f6ef7;
  --text-primary: #1a1f36;
  --text-secondary: #5c6280;
  --text-muted: #9aa0bc;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, .08);
  --shadow-glow: 0 0 40px rgba(79, 110, 247, .08);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 17, 23, .85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

[data-theme="light"] .app-header {
  background: rgba(255, 255, 255, .85);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: .875rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 20px var(--accent-glow);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
  color: #fff;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.2;
}

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

.brand-tagline {
  font-size: .72rem;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.live-clock {
  font-family: 'JetBrains Mono', monospace;
  font-size: .85rem;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: .35rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

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

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.icon-sun {
  display: none;
}

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

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

.app-main {
  padding: 2rem 1.25rem 4rem;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: background var(--transition), border var(--transition);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.panel-header svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--accent);
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.panel-subtotal {
  font-family: 'JetBrains Mono', monospace;
  font-size: .9rem;
  font-weight: 600;
  padding: .3rem .75rem;
  border-radius: 99px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  transition: all .3s ease;
}

.panel-expected .panel-header svg {
  color: var(--amber);
}

.expected-body {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-start;
}

.input-group-expected {
  flex: 1;
  min-width: 220px;
}

.label-expected {
  display: block;
  font-size: .82rem;
  color: var(--text-secondary);
  margin-bottom: .5rem;
  font-weight: 500;
}

.currency-input-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--transition);
  background: var(--bg-input);
}

.currency-input-wrap:focus-within {
  border-color: var(--border-focus);
}

.currency-prefix {
  padding: 0 .75rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  height: 42px;
  display: flex;
  align-items: center;
}

.input-expected {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: .95rem;
  font-family: 'JetBrains Mono', monospace;
  padding: 0 .875rem;
  height: 42px;
}

.field-hint {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: .35rem;
}

.difference-display {
  flex: 1;
  min-width: 180px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  text-align: center;
  transition: all .3s ease;
}

.difference-display.surplus {
  background: var(--green-bg);
  border-color: rgba(34, 197, 94, .3);
}

.difference-display.deficit {
  background: var(--red-bg);
  border-color: rgba(244, 63, 94, .3);
}

.difference-display.exact {
  background: var(--green-bg);
  border-color: rgba(34, 197, 94, .3);
}

.diff-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: .25rem;
}

.diff-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
}

.difference-display.surplus .diff-value {
  color: var(--green);
}

.difference-display.deficit .diff-value {
  color: var(--red);
}

.difference-display.exact .diff-value {
  color: var(--green);
}

.diff-status {
  font-size: .78rem;
  color: var(--text-secondary);
  margin-top: .2rem;
}

.denomination-grid {
  padding: 1.25rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .75rem;
}

.denom-row {
  display: grid;
  grid-template-columns: 90px minmax(120px, 1fr) 110px;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1rem;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.denom-row:hover {
  border-color: var(--border-focus);
}

.denom-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.denom-label strong {
  display: block;
  font-size: 1rem;
  color: var(--text-primary);
}

.panel-notes .denom-label strong {
  color: var(--notes-color);
}

.panel-coins .denom-label strong {
  color: var(--coins-color);
}

.stepper-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.stepper-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.stepper-wrap.stepper-active {
  border-color: var(--accent);
}

.stepper-btn {
  flex-shrink: 0;
  width: 36px;
  height: 38px;
  background: var(--bg-input);
  border: none;
  color: var(--text-secondary);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), transform .1s ease;
  user-select: none;
  -webkit-user-select: none;
}

.stepper-btn:hover {
  background: var(--border-focus);
  color: #fff;
}

.stepper-btn:active {
  transform: scale(.9);
}

.stepper-dec {
  border-right: 1px solid var(--border);
}

.stepper-inc {
  border-left: 1px solid var(--border);
}

.denom-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  padding: .45rem .25rem;
  outline: none;
  -moz-appearance: textfield;
}

.denom-input::-webkit-outer-spin-button,
.denom-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.denom-input.invalid {
  color: var(--red);
  background: var(--red-bg);
}

.denom-subtotal {
  font-family: 'JetBrains Mono', monospace;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
  transition: color .3s ease;
}

.denom-subtotal.active {
  color: var(--text-primary);
}

.panel-total {
  background: linear-gradient(135deg, #1a2040 0%, #1e2a50 100%);
  border-color: rgba(79, 110, 247, .3);
  box-shadow: var(--shadow-card), var(--shadow-glow);
}

[data-theme="light"] .panel-total {
  background: linear-gradient(135deg, #eef1ff 0%, #e8edff 100%);
  border-color: rgba(79, 110, 247, .2);
}

.total-inner {
  padding: 2rem 2rem 1.75rem;
  text-align: center;
}

.total-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .75rem;
}

.total-label svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.total-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(2.2rem, 6vw, 3.5rem);
  font-weight: 800;
  background: linear-gradient(135deg, #818cf8, #4f6ef7, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  margin-bottom: 1rem;
  transition: transform .2s ease;
}

.total-value.bump {
  animation: bump .35s cubic-bezier(.36, .07, .19, .97);
}

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

  40% {
    transform: scale(1.06);
  }

  100% {
    transform: scale(1);
  }
}

.total-breakdown {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.breakdown-item {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .82rem;
  color: var(--text-secondary);
}

.breakdown-item strong {
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
}

.breakdown-sep {
  color: var(--text-muted);
  font-weight: 700;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-notes {
  background: var(--notes-color);
}

.dot-coins {
  background: var(--coins-color);
}

.actions-row {
  display: flex;
  gap: .875rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1.5rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'Inter', sans-serif;
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--red);
  color: var(--red);
}

.btn-text-sm {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: .78rem;
  cursor: pointer;
  padding: .2rem .5rem;
  border-radius: 4px;
  transition: color var(--transition);
  margin-left: auto;
  font-family: 'Inter', sans-serif;
}

.btn-text-sm:hover {
  color: var(--red);
}

.panel-history .panel-header svg {
  color: var(--text-secondary);
}

.history-list {
  list-style: none;
  padding: .75rem 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  gap: 1rem;
  flex-wrap: wrap;
  animation: slideIn .3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.history-date {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.history-total {
  font-family: 'JetBrains Mono', monospace;
  font-size: .95rem;
  font-weight: 700;
  color: var(--accent);
}

.history-diff {
  font-size: .78rem;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-weight: 600;
}

.history-diff.surplus {
  background: var(--green-bg);
  color: var(--green);
}

.history-diff.deficit {
  background: var(--red-bg);
  color: var(--red);
}

.history-diff.exact {
  background: var(--green-bg);
  color: var(--green);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: .75rem 1.5rem;
  border-radius: 99px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .3);
  z-index: 200;
  opacity: 0;
  transition: transform .4s cubic-bezier(.16, 1, .3, 1), opacity .4s ease;
  pointer-events: none;
  white-space: nowrap;
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn .2s ease;
}

.modal-overlay[hidden] {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
  animation: slideUp .3s cubic-bezier(.16, 1, .3, 1);
  overflow: hidden;
}

@keyframes slideUp {
  from {
    transform: translateY(24px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: 1.75rem 1.75rem 1rem;
  text-align: center;
}

.modal-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto .875rem;
}

.modal-icon.success {
  background: var(--green-bg);
  color: var(--green);
}

.modal-icon svg {
  width: 26px;
  height: 26px;
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-body {
  padding: 0 1.75rem 1.5rem;
  color: var(--text-secondary);
  font-size: .9rem;
  line-height: 1.8;
}

.modal-body .modal-row {
  display: flex;
  justify-content: space-between;
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
}

.modal-body .modal-row:last-child {
  border-bottom: none;
}

.modal-body .modal-row strong {
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
}

.modal-total-row {
  display: flex;
  justify-content: space-between;
  padding: .75rem 0 .35rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-total-row strong {
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
}

.modal-footer {
  padding: 1rem 1.75rem 1.5rem;
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
}

@media (max-width: 600px) {
  .header-inner {
    height: 58px;
  }

  .brand-tagline {
    display: none;
  }

  .live-clock {
    display: none;
  }

  .denomination-grid {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .denom-row {
    grid-template-columns: 80px 1fr 90px;
  }

  .actions-row {
    justify-content: stretch;
  }

  .actions-row .btn {
    flex: 1;
    justify-content: center;
  }

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

  .expected-body {
    flex-direction: column;
  }

  .difference-display {
    width: 100%;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
  }

  .app-header,
  .actions-row,
  .panel-history,
  .btn-icon {
    display: none;
  }

  .panel {
    box-shadow: none;
    border-color: #ddd;
  }

  .total-value {
    -webkit-text-fill-color: #000;
  }
}