:root {
  --bg: #0f1115;
  --bg-soft: #171a21;
  --surface: #1c2029;
  --surface-hover: #232834;
  --border: #2a2f3a;

  --text: #eef0f4;
  --text-muted: #9aa1b1;

  --accent: #6c8cff;
  --accent-hover: #8aa2ff;
  --accent-soft: rgba(108, 140, 255, 0.12);

  --success: #34d399;
  --danger: #f87171;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);

  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  min-width: 340px;
  overflow-x: auto;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  min-width: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, rgba(108, 140, 255, 0.12), transparent 45%),
    radial-gradient(circle at 85% 100%, rgba(52, 211, 153, 0.08), transparent 45%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.app {
  width: 100%;
  max-width: 860px;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: clamp(14px, 3.5vw, 32px) clamp(12px, 3.5vw, 24px);
  gap: clamp(10px, 2vw, 18px);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  flex-shrink: 0;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.tab {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: clamp(7px, 1.4vw, 10px) clamp(12px, 2.2vw, 18px);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.tab:active {
  transform: scale(0.98);
}

.tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #5670e0);
  box-shadow: 0 4px 14px rgba(108, 140, 255, 0.35);
}

.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 3vw, 28px);
  box-shadow: var(--shadow);
  animation: fade-in 0.25s ease;
}

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

.content h1 {
  margin: 0 0 clamp(14px, 2.5vw, 24px);
  font-size: clamp(18px, 2.4vw, 22px);
  font-weight: 700;
}

.content h2 {
  margin: 0 0 clamp(10px, 2vw, 16px);
  font-size: clamp(14px, 1.6vw, 16px);
  font-weight: 600;
  color: var(--text-muted);
}

.content section + section {
  margin-top: 36px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.currency-table,
.rates-table {
  max-height: min(420px, 46dvh);
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: center;
  padding: 14px 18px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 14px 18px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: var(--surface-hover);
}

.currency-table tbody td:first-child {
  font-weight: 600;
  color: var(--accent-hover);
  letter-spacing: 0.03em;
}

.rate-edit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.rate-input {
  width: 100px;
  max-width: 100%;
  padding: 8px 10px;
  text-align: center;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-hover);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.rate-input:hover {
  border-color: var(--border);
}

.rate-input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.rate-save-btn {
  flex: 0 0 auto;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #5670e0);
  cursor: pointer;
  transition: opacity 0.2s ease, filter 0.15s ease, transform 0.15s ease;
}

.rate-save-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: none;
}

.rate-save-btn:not(:disabled):hover {
  filter: brightness(1.08);
}

.rate-save-btn:not(:disabled):active {
  transform: scale(0.95);
}

.rate-input--saved {
  animation: rate-saved-flash 0.6s ease;
}

@keyframes rate-saved-flash {
  0% {
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.5);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0);
  }
}

.content p {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  margin: 0 0 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.content p:last-child {
  margin-bottom: 0;
}

form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.compact-form {
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: center;
}

.compact-form label,
.compact-form .field {
  flex: 1 1 120px;
  min-width: 0;
}

.compact-form input,
.compact-form select {
  width: 100%;
}

.compact-form button[type="submit"] {
  flex: 0 0 auto;
  align-self: flex-end;
}

@media (max-width: 640px) {
  .compact-form {
    flex-direction: column;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .compact-form label,
  .compact-form .field {
    flex: 0 0 auto;
  }

  .compact-form button[type="submit"] {
    align-self: center;
    margin-top: 4px;
  }
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.field {
  position: relative;
}

.field input {
  width: 100%;
  padding: 20px 14px 8px;
}

.field label {
  display: block;
  position: absolute;
  left: 14px;
  top: 50%;
  margin: 0;
  transform: translateY(-50%);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  pointer-events: none;
  transition: top 0.18s ease, transform 0.18s ease, font-size 0.18s ease,
    color 0.18s ease;
}

.field input:focus ~ label,
.field input:not(:placeholder-shown) ~ label {
  top: 9px;
  transform: translateY(0);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

input,
select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input::placeholder {
  color: var(--text-muted);
}

input:hover,
select:hover {
  border-color: #3a4152;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
  linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) center, calc(100% - 15px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

select option {
  background: var(--surface);
  color: var(--text);
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

button[type="submit"] {
  align-self: flex-start;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #5670e0);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(108, 140, 255, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

button[type="submit"]:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 18px rgba(108, 140, 255, 0.4);
}

button[type="submit"]:active {
  transform: translateY(1px) scale(0.98);
}

input:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#convert-result {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--success);
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.3);
}

#convert-result:disabled {
  opacity: 1;
  cursor: default;
}

.toast-container {
  position: fixed;
  left: 50%;
  bottom: clamp(16px, 4vw, 32px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  z-index: 1000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  pointer-events: auto;
  animation: toast-in 0.2s ease;
}

.toast--leaving {
  animation: toast-out 0.18s ease forwards;
}

.toast--error {
  border-color: rgba(248, 113, 113, 0.35);
  background: linear-gradient(0deg, rgba(248, 113, 113, 0.08), rgba(248, 113, 113, 0.08)),
    var(--surface);
}

.toast--success {
  border-color: rgba(52, 211, 153, 0.35);
  background: linear-gradient(0deg, rgba(52, 211, 153, 0.08), rgba(52, 211, 153, 0.08)),
    var(--surface);
}

.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.toast--error .toast-icon {
  background: var(--danger);
}

.toast--success .toast-icon {
  background: var(--success);
}

.toast-message {
  flex: 1;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease;
}

.toast-close:hover {
  color: var(--text);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

.field-error-text {
  font-size: 12px;
  color: var(--danger);
  margin-top: 2px;
}

input.input-error,
select.input-error {
  border-color: var(--danger);
}

input.input-error:focus,
select.input-error:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.2);
}

.load-error {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: clamp(24px, 6vw, 40px) 0;
}


@media (max-width: 480px) {
  .content section + section {
    margin-top: 24px;
    padding-top: 20px;
  }

  thead th,
  tbody td {
    padding: 10px 8px;
    font-size: 13px;
  }

  .rate-input {
    width: 84px;
  }

  .rate-save-btn {
    padding: 7px 12px;
  }
}