:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --background: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --secondary: #64748b;
  --border: #cbd5e1;
  --success: #22c55e;
  --danger: #ef4444;
  --focus: rgba(37, 99, 235, 0.24);
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  min-width: 320px;
  height: 100vh;
  margin: 0;
  overflow-x: hidden;
  overflow-y: hidden;
  background: var(--background);
  color: var(--text);
  font-family: "Inter", "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

a,
button {
  transition:
    color 250ms ease,
    background-color 250ms ease,
    border-color 250ms ease,
    box-shadow 250ms ease,
    transform 250ms ease;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* =========================================================
   AUTH LAYOUT
   ========================================================= */

.auth-shell {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;

  /* الصورة تظل دائمًا في الشمال */
  direction: ltr;

  background: var(--card);
}

.hero-panel {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  overflow: hidden;
  isolation: isolate;
  padding: 48px;
}

.hero-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  animation: heroFade 850ms ease both;
  z-index: -3;
}

.form-panel {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 48px;
  background: var(--card);

  /*
   * مهم:
   * لا نضع direction هنا.
   * الـHTML هو المسؤول عن RTL / LTR.
   */

  overflow: hidden;
}

/* =========================================================
   FORM CARD
   ========================================================= */

.form-card {
  width: min(100%, 450px);
  animation: slideUp 650ms ease both;
}

/* =========================================================
   BRAND
   ========================================================= */

.brand {
  margin-bottom: 22px;
  text-align: center;
}

.brand-mark {
  width: 70px;
  height: 70px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.brand-mark span {
  font-size: 2.05rem;
  font-weight: 700;
}

.app-name {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.6;
}

.app-subtitle {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.5;
}

/* =========================================================
   AUTH VIEW
   ========================================================= */

.auth-view {
  animation: slideUp 420ms ease both;
}

.auth-view[hidden] {
  display: none;
}

/* =========================================================
   HEADINGS
   ========================================================= */

.form-heading {
  margin-bottom: 26px;
  text-align: center;
}

.compact-heading {
  margin-bottom: 18px;
}

.form-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 700;
  line-height: 1.2;
}

.form-heading p {
  margin: 10px 0 0;
  color: var(--secondary);
  font-size: 0.98rem;
  line-height: 1.6;
}

/* =========================================================
   FORM
   ========================================================= */

.auth-form {
  display: grid;
  gap: 18px;
}

.compact-form {
  gap: 12px;
}

/* =========================================================
   FIELDS
   ========================================================= */

.field-group label:not(.check-row) {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;

  /*
   * يتحول تلقائيًا:
   * RTL -> right
   * LTR -> left
   */
  text-align: start;
}

.input-shell {
  position: relative;
  display: flex;
  align-items: center;
}

.input-shell input {
  width: 100%;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
  color: var(--text);

  /*
   * مساحة للأيقونة على بداية الـinput
   */
  padding-inline-start: 48px;
  padding-inline-end: 48px;

  font-size: 1rem;

  /*
   * يتحول تلقائيًا حسب dir
   */
  direction: inherit;
  text-align: start;

  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);

  transition:
    border-color 250ms ease,
    box-shadow 250ms ease,
    transform 250ms ease;
}

.input-shell input::placeholder {
  color: #94a3b8;
}

.input-shell input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus);
}

.field-group.is-invalid input {
  border-color: var(--danger);
}

/* =========================================================
   ICONS
   ========================================================= */

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

/*
 * بداية الـinput:
 * RTL -> right
 * LTR -> left
 */
.leading-icon {
  position: absolute;
  inset-inline-start: 16px;
  color: var(--secondary);
  pointer-events: none;
}

/*
 * نهاية الـinput:
 * RTL -> left
 * LTR -> right
 */
.icon-button {
  position: absolute;
  inset-inline-end: 10px;

  width: 40px;
  height: 40px;

  display: grid;
  place-items: center;

  border-radius: 10px;
  background: transparent;
  color: var(--secondary);
  cursor: pointer;
}

.icon-button:hover {
  background: #eff6ff;
  color: var(--primary);
}

/* =========================================================
   PASSWORD ICON
   ========================================================= */

.eye-closed,
.password-toggle.is-visible .eye-open {
  display: none;
}

.password-toggle.is-visible .eye-closed {
  display: block;
}

/* =========================================================
   ERROR
   ========================================================= */

.error-message {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 0.83rem;
  line-height: 1.4;

  /*
   * RTL -> right
   * LTR -> left
   */
  text-align: start;
}

/* =========================================================
   FORM ROW
   ========================================================= */

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--secondary);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
}

.check-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  accent-color: var(--primary);
}

.terms-row a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.terms-row a:hover {
  text-decoration: underline;
}

/* =========================================================
   LINKS
   ========================================================= */

.text-link {
  padding: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
}

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

/* =========================================================
   PRIMARY BUTTON
   ========================================================= */

.primary-button {
  position: relative;
  width: 100%;
  height: 52px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  border-radius: 12px;
  background: var(--primary);
  color: #ffffff;

  cursor: pointer;

  font-size: 1rem;
  font-weight: 700;

  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.28);
}

.primary-button:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

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

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.68;
  transform: none;
}

/* =========================================================
   BUTTON LOADER
   ========================================================= */

.button-loader {
  width: 18px;
  height: 18px;

  display: none;

  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #ffffff;
  border-radius: 50%;

  animation: spin 750ms linear infinite;
}

.primary-button.is-loading .button-loader {
  display: block;
}

/* =========================================================
   DIVIDER
   ========================================================= */

.divider {
  position: relative;
  display: grid;
  place-items: center;
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 700;
}

.plain-divider {
  min-height: 1px;
}

.divider::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  height: 1px;
  background: #e2e8f0;
}

.plain-divider span {
  display: none;
}

.divider span {
  position: relative;
  padding-inline: 14px;
  background: var(--card);
}

/* =========================================================
   SWITCH / REGISTER
   ========================================================= */

.switch-text {
  margin: 0;
  color: var(--secondary);
  text-align: center;
  font-size: 0.95rem;
}

.register-button-link {
  min-width: 170px;
  min-height: 44px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  /*
   * بدل margin-left / margin-right
   */
  margin-inline-start: 10px;

  padding-inline: 18px;

  border-radius: 8px;
  background: #062f6d;
  color: #ffffff;

  font-weight: 700;
}

.register-button-link:hover {
  background: #04285d;
  color: #ffffff;
}

.strong-link {
  font-weight: 700;
}

/* =========================================================
   SUCCESS STATE
   ========================================================= */

.success-state {
  padding: 22px;
  border: 1px solid rgba(34, 197, 94, 0.28);
  border-radius: 20px;
  background: #f0fdf4;
  text-align: center;
}

.success-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;

  display: grid;
  place-items: center;

  border-radius: 50%;
  background: var(--success);
  color: #ffffff;

  font-size: 1.6rem;
  font-weight: 700;
}

.success-state h3 {
  margin: 0;
  color: #166534;
  font-size: 1.12rem;
  font-weight: 700;
}

.success-state p {
  margin: 8px 0 0;
  color: #15803d;
  font-size: 0.92rem;
  line-height: 1.5;
}

/* =========================================================
   FOOTER
   ========================================================= */

.site-footer {
  margin-top: 28px;
  color: var(--secondary);
  font-size: 0.8rem;
  line-height: 1.7;
  text-align: center;
}

.site-footer a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* =========================================================
   ANIMATIONS
   ========================================================= */

@keyframes heroFade {
  from {
    opacity: 0;
    transform: scale(1.04);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================================================
   TABLET
   ========================================================= */

@media (max-width: 1024px) {
  .auth-shell {
    grid-template-columns: 40% 60%;
  }

  .hero-panel,
  .form-panel {
    padding: 40px;
  }
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 760px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    background: var(--card);
  }

  .auth-shell {
    height: auto;
    min-height: 100vh;
    display: block;
  }

  .hero-panel {
    min-height: 260px;
    padding: 24px;
  }

  .form-panel {
    height: auto;
    min-height: auto;
    padding: 28px 24px 32px;
    overflow: visible;
  }

  .brand {
    margin-bottom: 22px;
  }

  .brand-mark {
    width: 62px;
    height: 62px;
    border-radius: 18px;
  }

  .app-name {
    font-size: 28px;
  }

  .form-card {
    width: 100%;
  }

  .form-heading {
    margin-bottom: 22px;
  }

  .form-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .input-shell input,
  .primary-button {
    height: 52px;
  }
}

/* =========================================================
   SHORT DESKTOP SCREENS
   ========================================================= */

@media (max-height: 760px) and (min-width: 761px) {
  .form-panel {
    padding-top: 28px;
    padding-bottom: 28px;
  }

  .brand {
    margin-bottom: 16px;
  }

  .brand-mark {
    width: 58px;
    height: 58px;
    margin-bottom: 12px;
    border-radius: 16px;
  }

  .app-name {
    font-size: 28px;
  }

  .form-heading {
    margin-bottom: 16px;
  }

  .auth-form {
    gap: 10px;
  }

  .input-shell input,
  .primary-button {
    height: 46px;
  }

  .error-message {
    min-height: 14px;
    margin-top: 4px;
    font-size: 0.76rem;
  }

  .site-footer {
    margin-top: 16px;
  }
}