/* ── Reset & base ───────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e94560;
  --accent2: #0f3460;
  --text: #e0e0e0;
  --text-dim: #8888aa;
  --border: #2a2a4a;
  --radius: 16px;
  --input-h: 54px;
  font-size: 16px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    "Cairo",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* ── App shell ──────────────────────────────────────────────────────────────── */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.header {
  position: relative;
  text-align: center;
  padding: 16px 0 4px;
}

.header__settings {
  position: absolute;
  inset-inline-start: 0;
  top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition:
    color 0.15s,
    background 0.15s,
    transform 0.4s;
  -webkit-tap-highlight-color: transparent;
}

.header__settings:hover {
  color: var(--text);
}
.header__settings:active {
  transform: scale(0.92);
}
.header__settings[aria-expanded="true"] {
  color: var(--accent);
  transform: rotate(60deg);
}

.header__title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 30%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header__updated {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ── Converter fields ───────────────────────────────────────────────────────── */
.converter {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  position: relative;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px 8px;
  transition: border-color 0.15s;
}

.field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.field__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
  user-select: none;
}

.field__tag {
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 100px;
  font-weight: 700;
}

.field__tag--alt {
  background: #555;
}

.field__input {
  width: 100%;
  height: var(--input-h);
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding-inline-end: 56px; /* room for currency label */
  /* Hide number spinners */
  -moz-appearance: textfield;
}

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

.field__input::placeholder {
  color: var(--border);
}

.field__currency {
  position: absolute;
  inset-inline-end: 16px;
  bottom: 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* ── Clear-all button ───────────────────────────────────────────────────────── */
.clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  align-self: center;
  padding: 8px 20px;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

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

.clear-btn:active {
  transform: scale(0.95);
}

/* ── Rates info bar ─────────────────────────────────────────────────────────── */
.rates-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.rates-info__sep {
  opacity: 0.4;
}

.rates-info strong {
  color: var(--text);
  font-weight: 700;
}

/* ── Offline banner ─────────────────────────────────────────────────────────── */
.offline-banner {
  text-align: center;
  background: #3a2a00;
  border: 1px solid #a07000;
  color: #f0c040;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ── Admin page styles ──────────────────────────────────────────────────────── */
.admin-app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 60px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.admin-header {
  text-align: center;
}

.admin-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group input[type="password"] {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 600;
  padding: 12px 14px;
  outline: none;
  width: 100%;
  -moz-appearance: textfield;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

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

.btn {
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    opacity 0.15s,
    transform 0.1s;
}

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

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-label {
  font-size: 0.95rem;
  font-weight: 600;
}

.toggle {
  position: relative;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle__track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle input:checked + .toggle__track {
  background: var(--accent);
}

.toggle__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle__track::after {
  transform: translateX(24px);
}

/* Status messages */
.status-msg {
  font-size: 0.85rem;
  padding: 10px 14px;
  border-radius: 10px;
  text-align: center;
  display: none;
}

.status-msg.success {
  background: #0a3a1a;
  color: #4caf50;
  display: block;
}
.status-msg.error {
  background: #3a0a0a;
  color: #f44336;
  display: block;
}

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-box h2 {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
}

/* ── Settings drawer (mobile-first bottom sheet) ────────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.drawer-backdrop.is-open {
  opacity: 1;
}

.drawer {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 50;
  background: var(--surface);
  border-top: 1.5px solid var(--border);
  border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Hidden by default: slid fully below the viewport. */
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}

.drawer.is-open {
  transform: translateY(0);
}

/* Grab handle hint at the top of the sheet. */
.drawer__handle {
  width: 40px;
  height: 4px;
  border-radius: 100px;
  background: var(--border);
  margin: 8px auto 4px;
  flex-shrink: 0;
}

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 12px;
  flex-shrink: 0;
}

.drawer__title {
  font-size: 1.1rem;
  font-weight: 700;
}

.drawer__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  transition:
    color 0.15s,
    transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.drawer__close:hover {
  color: var(--text);
}
.drawer__close:active {
  transform: scale(0.92);
}

.drawer__body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding-bottom: 4px;
}

/* A group of related settings. */
.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-section__title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-section__hint {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-dim);
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* One tappable settings row (label + toggle). */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.settings-row__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  -webkit-user-select: none;
  user-select: none;
}

.settings-row__code {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 100px;
  letter-spacing: 0.04em;
}

/* ── PWA install prompt (mobile bottom sheet) ───────────────────────────────── */
.install-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.install-backdrop.is-open {
  opacity: 1;
}

.install {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 70;
  background: var(--surface);
  border-top: 1.5px solid var(--border);
  border-radius: 22px 22px 0 0;
  padding: 28px 24px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  /* Hidden by default: slid fully below the viewport. */
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}

.install.is-open {
  transform: translateY(0);
}

.install__close {
  position: absolute;
  top: 14px;
  inset-inline-start: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  transition:
    color 0.15s,
    transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.install__close:hover {
  color: var(--text);
}
.install__close:active {
  transform: scale(0.92);
}

.install__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  margin-top: 4px;
}

.install__icon img {
  border-radius: 12px;
}

.install__title {
  font-size: 1.15rem;
  font-weight: 700;
}

.install__desc {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-dim);
  max-width: 340px;
}

.install__btn {
  width: 100%;
  max-width: 340px;
  margin-top: 4px;
}

.install__steps {
  list-style: none;
  counter-reset: step;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
  text-align: start;
}

.install__steps li {
  position: relative;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px 12px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  counter-increment: step;
}

.install__step-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--bg);
  color: var(--accent);
}

.install__later {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 12px;
  margin-top: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

/* ── Responsive tweaks ──────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  .app,
  .admin-app {
    padding-top: 40px;
  }
  .header__title {
    font-size: 1.9rem;
  }

  /* On larger screens, present the drawer as a centered modal card instead
     of a bottom sheet. */
  .drawer {
    inset-inline: auto;
    inset-inline-end: 50%;
    transform: translate(50%, calc(100% + 24px));
    bottom: auto;
    top: 50%;
    margin-top: 0;
    width: min(420px, calc(100vw - 32px));
    max-height: 80dvh;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
  }

  .drawer.is-open {
    transform: translate(50%, -50%);
  }

  .drawer__handle {
    display: none;
  }

  /* Install prompt as a centered modal card on larger screens. */
  .install {
    inset-inline: auto;
    inset-inline-end: 50%;
    transform: translate(50%, calc(100% + 24px));
    bottom: auto;
    top: 50%;
    width: min(400px, calc(100vw - 32px));
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
  }

  .install.is-open {
    transform: translate(50%, -50%);
  }
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .drawer,
  .drawer-backdrop,
  .header__settings,
  .install,
  .install-backdrop {
    transition: none;
  }
}
