:root {
  --lab-bg: #f5f7fb;
  --lab-surface: #ffffff;
  --lab-border: #dfe7f3;
  --lab-accent: #0ea5e9;
  --lab-accent-strong: #0284c7;
  --lab-text: #1f2933;
  --lab-text-muted: #5f6b7c;
  --lab-positive: #0f9d58;
  --lab-negative: #d93025;
  --accent-emerald: #10b981;
}

body.lab-page {
  font-family: 'Inter', 'Segoe UI', sans-serif;
  background: var(--lab-bg);
  margin: 0;
  color: var(--lab-text);
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.lab-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 60px;
}

.lab-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.lab-header h1 {
  margin: 0;
  font-size: 1.85rem;
}

.lab-header p {
  margin: 6px 0 0 0;
  color: var(--lab-text-muted);
}

.lab-header-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.lab-status {
  display: flex;
  gap: 12px;
  align-items: center;
}

.lab-refresh {
  border: 1px solid var(--lab-border);
  background: var(--lab-surface);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--lab-accent);
  transition: all 0.2s ease;
}

.lab-refresh:hover {
  background: var(--lab-accent);
  color: #fff;
  border-color: var(--lab-accent);
}

.lab-refresh.spinning {
  opacity: 0.6;
  pointer-events: none;
}

.lab-refresh.spinning i {
  animation: lab-spin 0.9s linear infinite;
}

@keyframes lab-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.lab-auth #user-info {
  display: flex;
  gap: 8px;
  align-items: center;
}

#user-photo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
}

#logout-btn,
#edit-preferences-btn {
  border: none;
  background: var(--lab-border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}

#logout-btn:hover,
#edit-preferences-btn:hover {
  background: var(--lab-accent);
  color: #fff;
}

.lab-loader,
.lab-login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 10, 29, 0.05);
  z-index: 999;
}

.lab-loader-card,
.lab-login-card {
  background: var(--lab-surface);
  padding: 40px 60px;
  border-radius: 20px;
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.15);
  text-align: center;
}

.lab-calculator .calculator-header {
  background: var(--lab-surface);
  border: 1px solid var(--lab-border);
  border-radius: 18px 18px 0 0;
  padding: 20px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.calculator-header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.lab-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.15);
  color: var(--lab-accent-strong);
  font-size: 0.9rem;
}

.lab-chip.ghost {
  background: rgba(148, 163, 184, 0.18);
  color: var(--lab-text-muted);
}

.lab-grid {
  position: relative;
  border: 1px solid var(--lab-border);
  border-top: none;
  border-radius: 0 0 18px 18px;
  padding: 28px 32px;
  background: #fbfdff;
  display: grid;
  column-gap: 35px;
  row-gap: 10px;
  grid-template-columns: 90px minmax(350px, 420px) 70px minmax(350px, 420px);
  grid-template-rows: auto auto auto auto;
  grid-template-areas:
    ". switch switch switch"
    "amount left swap right"
    "result result result result"
    "live live live live";
  align-items: start;
  justify-content: center;
  max-width: 100%;
  margin: 0 auto;
}

.grid-item {
  background: var(--lab-surface);
  border: 1px solid var(--lab-border);
  border-radius: 16px;
  padding: 0px;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
}

.grid-item[data-area="amount"] {
  grid-area: amount;
  align-self: start;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 12px 0 18px;
  position: relative;
}
.grid-item[data-area="left"] { grid-area: left; }
.grid-item[data-area="swap"] {
  grid-area: swap;
  align-self: start;
  justify-self: center;
  margin-top: 55px;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
}

.swap-button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--accent-emerald);
  background: #ffffff;
  color: var(--accent-emerald);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18), 0 0 0 4px rgba(16, 185, 129, 0.15);
  font-size: 1.2rem;
  z-index: 100;
  position: relative;
  left: -6px;
}

.swap-button:hover {
  background: var(--accent-emerald);
  color: #fff;
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(16, 185, 129, 0.3);
}

.swap-button:active {
  transform: scale(0.95);
}

.swap-button i {
  transition: transform 0.3s ease;
}

.swap-button.swapping i {
  animation: rotate180 0.4s ease-in-out;
}

.grid-item[data-area="right"] { grid-area: right; }
.grid-item[data-area="switch"] {
  grid-area: switch;
  align-self: center;
  background: transparent;
  border: none;
  box-shadow: none;
  display: flex;
  justify-content: center;
}
.grid-item[data-area="result"] { grid-area: result; display: flex; flex-direction: column; gap: 12px; }
.grid-item[data-area="result"] {
  background: #effff6;
  border: 1px solid #b3f1cb;
  text-align: center;
}
.grid-item[data-area="live"] {
  grid-area: live;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  align-items: center;
}

.amount-input-wrapper {
  position: relative;
  width: 100%;
  text-align: center;
  padding-top: 2px;
}

.amount-box label {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -60%);
  display: inline-block;
  text-align: center;
  font-weight: 600;
  font-size: 0.85rem;
  background: #fbfdff;
  padding: 0 10px;
  color: var(--lab-text-muted);
}

#calculator-amount {
  width: 100%;
  border: 2px solid var(--lab-accent);
  border-radius: 12px;
  padding: 10px 8px;
  font-size: 1.1rem;
  text-align: center;
  background: #f0f9ff;
  color: var(--lab-text);
  box-sizing: border-box;
  margin-top: 0;
}

.currency-box {
  background: #fdfefe;
  border: 0px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  padding: 14px 18px 22px;
  max-width: 100%;
  margin: 0 -6px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.currency-select {
  width: 100%;
  border: 1.5px solid rgba(14, 165, 233, 0.35);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  background: #fff;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.currency-select:focus {
  outline: none;
  border-color: var(--lab-accent-strong);
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
}

.current-rate-inline {
  margin: 10px 0 4px;
  display: grid;
  grid-template-columns: 95px 50px 1fr;
  align-items: center;
  gap: 6px;
  padding-left: 6px;
}

.current-rate-label {
  color: var(--lab-text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
}

.rate-rows {
  margin: 20px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rate-row,
.rate-adjust-group {
  display: grid;
  grid-template-columns: 100px 40px auto 40px 1fr;
  align-items: center;
  gap: 6px;
  padding-left: 6px;
}

.rate-adjust-placeholder {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-block;
  visibility: hidden;
}

.rate-percentage-placeholder {
  visibility: hidden;
  min-height: 1.2rem;
  display: inline-block;
}

.current-rate-inline .current-rate-display,
.rate-row-current .current-rate-display {
  justify-self: flex-start;
  text-align: left;
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--lab-text);
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  min-width: 0;
}

.current-rate-inline .current-rate-display {
  grid-column: 2 / 4;
}

.rate-row-current .current-rate-display {
  grid-column: 3;
}

.lab-calculator #left-current-rate,
.lab-calculator #right-current-rate {
  grid-column: 3;
}

.rate-row-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--lab-text-muted);
  margin: 0;
  align-self: center;
  text-align: left;
}

.rate-adjust-group {
  margin-top: 6px;
}

.rate-percentage-inline {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--lab-text-muted);
  min-width: 30px;
  text-align: left;
  padding-left: 0px;
}

.rate-percentage-inline.positive {
  color: var(--lab-positive);
}

.rate-percentage-inline.negative {
  color: var(--lab-negative);
}

.rate-adjust {
  border: none;
  background: #e0f2ff;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  color: var(--lab-accent-strong);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.rate-adjust:hover {
  transform: translateY(-1px);
}

.rate-display {
  font-size: 1.4rem;
  font-weight: 700;
  justify-self: flex-start;
  text-align: left;
}

.rate-type-switch {
  background: #eef2ff;
  border-radius: 12px;
  padding: 6px;
}

.center-box .rate-type-switch {
  margin: 0 auto;
  max-width: 260px;
  box-shadow: 0 2px 6px rgba(15,23,42,0.08);
}

#calculator-result {
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.4;
  color: #0f5132;
}

.current-rates-row .current-rate-display {
  font-weight: 600;
  text-align: center;
}
.current-rate-display,
.rate-display {
  min-width: 55px;
  text-align: right;
}

.current-rate-timestamp {
  font-size: 0.9rem;
  color: var(--lab-text-muted);
}

.currency-input-wrapper {
  position: relative;
  width: 100%;
}

.currency-input-display {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  pointer-events: none;
  color: var(--lab-text);
  font-weight: 600;
}

.currency-input-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.currency-input-display .currency-code {
  font-weight: 700;
}

.currency-input-display .currency-symbol {
  color: var(--lab-text-muted);
  font-weight: 500;
  margin-right: 4px;
}

.currency-input-display .currency-name {
  font-weight: 500;
  color: var(--lab-text);
}

.cross-calc-warning {
  align-self: center;
  width: auto;
  max-width: 100%;
  max-height: 0;
  overflow: hidden;
  margin-top: 0;
  padding: 0 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--lab-negative);
  background: #fdecea;
  border-radius: 10px;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(217, 48, 37, 0.15);
  opacity: 0;
  transition: max-height 0.2s ease, margin-top 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}

.cross-calc-warning.visible {
  max-height: 80px;
  margin-top: 12px;
  padding: 8px 14px;
  opacity: 1;
}

.cross-calc-warning.visible:empty {
  padding: 0;
}

.cross-calc-warning:empty {
  font-size: 0.9rem;
  max-height: 0;
  margin-top: 0;
  padding: 0;
}

.lab-error {
  margin-top: 18px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 14px 18px;
  border-radius: 10px;
}

@media (max-width: 1220px) {
  .lab-grid {
    grid-template-columns: 120px minmax(0, 1fr);
    grid-template-areas:
      "switch switch"
      "amount left"
      "amount right"
      "swap swap"
      "result result"
      "live live";
  }

  .grid-item[data-area="swap"] {
    grid-column: 1 / -1;
    grid-row: auto;
    align-self: center;
    margin-top: 0;
  }
  .grid-item[data-area="switch"] {
    grid-column: 1 / -1;
  }
  .swap-button {
    left: 0;
  }
}

@media (max-width: 720px) {
  .lab-header {
    flex-direction: column;
  }
  .lab-header-right {
    align-items: flex-start;
  }
  .lab-grid {
    grid-template-columns: repeat(1, 1fr);
    grid-template-areas:
      "amount"
      "switch"
      "left"
      "right"
      "swap"
      "result"
      "live";
  }
  .grid-item[data-area="swap"] {
    grid-column: 1 / -1;
    grid-row: auto;
    align-self: center;
    margin-top: 0;
    width: 54px;
    height: 54px;
  }
  .grid-item[data-area="switch"] {
    grid-column: 1 / -1;
  }
  .grid-item[data-area="amount"] {
    margin-bottom: 12px;
  }
  .amount-input-wrapper {
    padding-top: 0;
    text-align: left;
  }
  .amount-box label {
    position: static;
    transform: none;
    background: transparent;
    padding: 0;
    margin-bottom: 6px;
    display: block;
    text-align: left;
    color: var(--lab-text);
  }
  .swap-button {
    left: 0;
  }
}
