:root,
[data-theme="light"] {
  color-scheme: light;

  --brand-blue: #1d4482;
  --brand-blue-dark: #163566;
  --brand-orange: #f5851f;
  --brand-green: #00a74b;

  --bg: #eef3f9;
  --surface: #ffffff;
  --text: #0f1f3d;
  --text-muted: #5c6b82;
  --text-nav: #2d3f58;
  --border: #d5deea;
  --primary: var(--brand-blue);
  --primary-hover: var(--brand-blue-dark);
  --primary-soft: rgba(29, 68, 130, 0.1);
  --shadow: 0 16px 40px rgba(15, 31, 61, 0.1);
  --shadow-sm: 0 1px 2px rgba(15, 31, 61, 0.04);
  --toggle-bg: #ffffff;
  --toggle-border: #d5deea;
  --success: var(--brand-green);
  --error: #dc2626;
  --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0a1018;
  --surface: #131c2b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-nav: #cbd5e1;
  --border: #243044;
  --primary: #5b8fd4;
  --primary-hover: #7aa8e0;
  --primary-soft: rgba(91, 143, 212, 0.15);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --toggle-bg: #131c2b;
  --toggle-border: #334155;
  --success: #34d399;
  --error: #f87171;
}

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

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

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

body.nav-locked {
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html.theme-switching *,
  html.theme-switching *::before,
  html.theme-switching *::after {
    transition:
      background-color 0.45s ease,
      color 0.45s ease,
      border-color 0.45s ease,
      box-shadow 0.45s ease,
      fill 0.45s ease,
      stroke 0.45s ease !important;
  }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.55s;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  }

  ::view-transition-old(root) {
    z-index: 1;
  }

  ::view-transition-new(root) {
    z-index: 9999;
    animation-name: theme-circle-in;
  }

  @keyframes theme-circle-in {
    from {
      clip-path: circle(0 at var(--theme-x, 100%) var(--theme-y, 0%));
    }
    to {
      clip-path: circle(150vmax at var(--theme-x, 100%) var(--theme-y, 0%));
    }
  }
}

.theme-toggle .material-symbols-outlined {
  transition: transform 0.35s ease, opacity 0.35s ease;
}

.theme-toggle:active .material-symbols-outlined {
  transform: rotate(-20deg) scale(0.9);
}

.page {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding:
    calc(0.75rem + env(safe-area-inset-top))
    calc(0.75rem + env(safe-area-inset-right))
    calc(0.75rem + env(safe-area-inset-bottom))
    calc(0.75rem + env(safe-area-inset-left));
}

.page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(29, 68, 130, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 68, 130, 0.07) 1px, transparent 1px);
  background-size: 2rem 2rem;
  mask-image: radial-gradient(ellipse 85% 75% at 50% 45%, #000 15%, transparent 72%);
  pointer-events: none;
}

.page::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 12% 88%, rgba(245, 133, 31, 0.14), transparent 32%),
    radial-gradient(circle at 92% 10%, rgba(29, 68, 130, 0.16), transparent 38%),
    radial-gradient(circle at 78% 72%, rgba(0, 167, 75, 0.1), transparent 28%),
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(29, 68, 130, 0.08), transparent 55%);
  pointer-events: none;
}

[data-theme="dark"] .page::before {
  background-image:
    linear-gradient(rgba(91, 143, 212, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 143, 212, 0.09) 1px, transparent 1px);
}

[data-theme="dark"] .page::after {
  background:
    radial-gradient(circle at 12% 88%, rgba(245, 133, 31, 0.1), transparent 32%),
    radial-gradient(circle at 92% 10%, rgba(91, 143, 212, 0.14), transparent 38%),
    radial-gradient(circle at 78% 72%, rgba(0, 167, 75, 0.08), transparent 28%),
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(91, 143, 212, 0.06), transparent 55%);
}

.main {
  position: relative;
  z-index: 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 3rem 0 1rem;
}

.topbar {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top));
  right: calc(0.75rem + env(safe-area-inset-right));
  z-index: 100;
  margin: 0;
  padding: 0;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.375rem;
  height: 2.375rem;
  border: 1px solid var(--toggle-border);
  border-radius: 0.625rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease;
}

.theme-toggle:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 25%, var(--border));
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.icon-dark {
  display: none;
}

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

[data-theme="dark"] .icon-dark {
  display: inline;
}

.auth-shell {
  width: 100%;
  max-width: 26rem;
}

.auth-card {
  width: 100%;
  padding: 2rem 1.75rem 1.75rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.4) inset;
}

[data-theme="dark"] .auth-card {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

.auth-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.auth-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-bottom: 0;
}

.auth-logo .logo {
  height: 2.75rem;
  width: auto;
}

.logo-wrap {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
}

.logo {
  height: 2.125rem;
  width: auto;
  max-width: 100%;
}

.card-header,
.card-heading {
  display: none;
}

.logo-for-light {
  display: block;
}

.logo-for-dark {
  display: none;
}

[data-theme="dark"] .logo-for-light {
  display: none;
}

[data-theme="dark"] .logo-for-dark {
  display: block;
}

.platform-label {
  display: none;
}

.auth-panel.hidden {
  display: none;
}

.title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
  text-align: right;
  flex-shrink: 0;
}

.subtitle {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text-muted);
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 1.375rem;
  margin-bottom: 0.5rem;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.field-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.text-link {
  padding: 0;
  border: none;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
}

.text-link:hover {
  color: var(--brand-orange);
  text-decoration: underline;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 3rem;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  background: var(--bg);
  box-shadow: inset 0 1px 2px rgba(15, 31, 61, 0.04);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.input-group:focus-within {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow:
    inset 0 1px 2px rgba(15, 31, 61, 0.02),
    0 0 0 3px var(--primary-soft);
}

.input-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

.input-icon .material-symbols-outlined {
  font-size: 1.125rem;
  opacity: 0.7;
}

.input-group:focus-within .input-icon {
  color: var(--primary);
}

.input-group:focus-within .input-icon .material-symbols-outlined {
  opacity: 1;
}

.input-group input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0.8125rem 0.875rem 0.8125rem 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  min-height: 2.875rem;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

.input-group input::placeholder {
  color: var(--text-muted);
  opacity: 0.55;
}

.input-group input.has-toggle {
  padding-right: 0.25rem;
}

.input-group input:focus {
  outline: none;
}

.password-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  margin-right: 0.25rem;
  padding: 0;
  border: none;
  border-radius: 0.4375rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}

.password-toggle .material-symbols-outlined {
  font-size: 1.125rem;
}

.password-toggle:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.password-toggle .icon-hide {
  display: none;
}

.password-toggle.is-visible .icon-show {
  display: none;
}

.password-toggle.is-visible .icon-hide {
  display: inline;
}

.btn-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.625rem;
  margin-top: 0.5rem;
}

.btn-row .primary-btn,
.btn-row .secondary-btn {
  flex: 1;
  width: auto;
  min-width: 0;
  margin-top: 0;
  min-height: 3rem;
  font-size: 0.875rem;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  width: 100%;
  margin-top: 0;
  padding: 0.75rem 1.125rem;
  border: none;
  border-radius: 0.625rem;
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-blue-dark) 100%);
  color: #fff;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(29, 68, 130, 0.28);
  min-height: 3rem;
  touch-action: manipulation;
  transition:
    background 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.12s ease;
}

.primary-btn:hover {
  background: linear-gradient(135deg, #2563a8 0%, var(--brand-blue) 100%);
  box-shadow: 0 6px 20px rgba(29, 68, 130, 0.35);
}

[data-theme="dark"] .primary-btn {
  background: linear-gradient(135deg, #4a7fc4 0%, #3d6aad 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .primary-btn:hover {
  background: linear-gradient(135deg, #5b8fd4 0%, #4a7fc4 100%);
}

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

.primary-btn .material-symbols-outlined,
.secondary-btn .material-symbols-outlined {
  font-size: 1rem;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  width: 100%;
  padding: 0.75rem 1.125rem;
  border: 1.5px solid var(--border);
  border-radius: 0.625rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 3rem;
  touch-action: manipulation;
  box-shadow: var(--shadow-sm);
  transition:
    border-color 0.2s ease,
    background 0.2s ease,
    color 0.2s ease,
    transform 0.12s ease;
}

.secondary-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

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

.form-message {
  display: none;
}

/* Toast popup */
.toast-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 31, 61, 0.35);
  backdrop-filter: blur(2px);
  animation: toast-fade-in 0.2s ease;
}

.toast-overlay.hidden,
.toast-popup.hidden {
  display: none;
}

.toast-popup {
  position: fixed;
  z-index: 201;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  width: min(calc(100% - 2rem), 22rem);
  padding: 1.125rem 1rem 1.375rem;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(15, 31, 61, 0.18);
  animation: toast-slide-in 0.25s ease;
  overflow: hidden;
}

.toast-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
}

.toast-icon-success {
  background: rgba(0, 167, 75, 0.12);
  color: var(--success);
}

.toast-icon-error {
  background: rgba(220, 38, 38, 0.12);
  color: var(--error);
}

.toast-icon-info {
  background: var(--primary-soft);
  color: var(--primary);
}

.toast-content {
  flex: 1;
  min-width: 0;
  padding-top: 0.125rem;
  padding-right: 1.5rem;
}

.toast-title {
  margin: 0 0 0.25rem;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}

.toast-message {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.toast-close {
  position: absolute;
  top: 0.625rem;
  right: 0.625rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

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

.toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 3px;
  background: var(--border);
  transform-origin: left center;
}

.toast-success .toast-progress {
  background: linear-gradient(90deg, var(--success), rgba(0, 167, 75, 0.5));
}

.toast-error .toast-progress {
  background: linear-gradient(90deg, var(--error), rgba(220, 38, 38, 0.5));
}

.toast-info .toast-progress {
  background: linear-gradient(90deg, var(--primary), rgba(29, 68, 130, 0.4));
}

@keyframes toast-progress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

@keyframes toast-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes toast-slide-in {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 0.75rem));
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.footer {
  padding: 1rem 0 0.25rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer p {
  margin: 0;
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  vertical-align: middle;
}

/* Mobile */
@media (max-width: 480px) {
  .main {
    padding: 2.5rem 0 0.75rem;
  }

  .auth-card {
    padding: 1.5rem 1.25rem 1.25rem;
    border-radius: 0.875rem;
  }

  .auth-brand-row {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    gap: 0.75rem;
  }

  .auth-logo .logo {
    height: 2.5rem;
  }

  .title {
    font-size: 1.25rem;
  }

  .auth-form {
    gap: 1rem;
  }

  .primary-btn,
  .secondary-btn {
    min-height: 2.875rem;
    font-size: 0.875rem;
  }

  .btn-row .primary-btn,
  .btn-row .secondary-btn {
    min-height: 2.875rem;
  }

  .toast-popup {
    width: calc(100% - 1.5rem);
    padding: 1rem 0.875rem 1.25rem;
  }

  .footer {
    padding: 0.625rem 0 calc(0.25rem + env(safe-area-inset-bottom));
    font-size: 0.6875rem;
  }
}

@media (max-width: 360px) {
  .field-row {
    flex-wrap: wrap;
  }
}
