/* login.css */

/* ========== Base ========== */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
}

:root{
  --surface:#ffffff;
  --border:#e5e7eb;
  --muted:#6b7280;
  --text:#111827;
  --primary:#0d6efd;            /* bootstrap-ish primary */
  --primary-hover:#0b5ed7;
  --ring: rgba(13,110,253,.35);
  --shadow: 0 10px 30px rgba(0,0,0,.06);
  --radius: 10px;
}

img { max-width: 100%; height: auto; }
.text-content { font-size: calc(16px + 0.5vw); text-align: center; }

.container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%; height: 100%; box-sizing: border-box; padding: 10px;
}

/* ========== Form controls ========== */
.form-login { width: 100%; max-width: 350px; padding: 20px; margin: auto; }
.form-group { width: 100%; max-width: 350px; margin: 0 auto 15px; }
.input-group { display: flex; align-items: center; }
.input-group-append { margin-left: -1px; }

.form-control {
  flex: 1; padding: 10px; font-size: 16px;
  border: 1px solid #ced4da; border-radius: .25rem;
}

/* ========== Buttons (accessibility & consistency) ========== */
.btn-primary {
  background-color: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  padding: 10px 8px;
  font-size: 16px;
  line-height: 1.0;
  border-radius: .5rem;
  cursor: pointer;
  width: auto;
  white-space: normal;          /* allow wrapping for localized text */
  min-width: 150px;
  min-height: 30px;             /* ~44px tap target */
  font-weight: 600;
  box-shadow: 0 1px 1px rgba(0,0,0,.02);
  transition: background-color .15s ease, box-shadow .15s ease, transform .02s ease;
}
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-primary:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}
.btn-primary:disabled,
.btn-primary[disabled]{
  opacity:.65; cursor:not-allowed; box-shadow:none;
}

/* ========== App store links ========== */
.app-links { display: flex; justify-content: center; gap: 12px; margin-top: 10px; }
.app-link { display: inline-block; }
.app-link img { width: 110px; height: auto; transition: transform .2s ease; }
.app-link:hover img { transform: scale(1.06); }

/* ========== Top-right language dropdown ========== */
.langdrop{
  position: fixed;
  z-index: 3000; /* bumped for mobile reliability */
  top: max(12px, calc(env(safe-area-inset-top, 0px) + 12px));
  right: max(12px, calc(env(safe-area-inset-right, 0px) + 12px));
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}
.langdrop__btn{
  display: flex; align-items: center; gap: .5rem;
  background: #ffffff; color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow);
  padding: .55rem .75rem; min-height: 20px; cursor: pointer;
  touch-action: manipulation; /* better tap behavior on mobile */
}
.langdrop__btn:focus-visible{ outline: 3px solid var(--ring); outline-offset: 2px; }
.langdrop__icon{ width: 18px; height: 18px; color: #6b7280; }
.langdrop__caret{ color: #6b7280; }

.langdrop__panel{
  position: fixed;
  z-index: 3001; /* above button */
  top: calc(max(12px, env(safe-area-inset-top, 0px)) + 56px);
  right: max(12px, calc(env(safe-area-inset-right, 0px) + 12px));
  width: min(200px, 92vw);
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow);
  transform-origin: top right;
  transform: translateY(-6px) scale(.98);
  opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease; overflow: hidden;
}
.langdrop__panel.open{ opacity:1; pointer-events:auto; transform: translateY(0) scale(1); }
.langdrop__search{ padding: .55rem .65rem; border-bottom: 1px solid var(--border); }
.langdrop__search input{
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: .55rem .65rem; font-size: 16px; background:#fff; color: var(--text);
}
.langdrop__list{ list-style:none; margin:0; padding:.35rem; max-height:min(45vh, 420px); overflow:auto; -webkit-overflow-scrolling:touch; }
.langdrop__opt{
  display:flex; align-items:center; justify-content:space-between;
  padding:.55rem .6rem; border-radius:10px; cursor:pointer;
}
.langdrop__opt:hover, .langdrop__opt[aria-selected="true"]{ background:#f3f4f6; }

/* ========== Layout: LINKS | FORM | BUTTONS (grid areas) ========== */
.login-layout{
  display: grid;
  grid-template-columns: 1fr minmax(320px, 350px) 1fr;  /* left rail | centered form | right rail */
  grid-template-areas:
    ". app ."
    "links form buttons";
  gap: 16px 24px;
  align-items: start;
  width: 100%;
  max-width: 1200px;
  margin: 20px auto 0;
  padding: 0 16px;
}

/* Area assignments (desktop/tablet) */
.login-layout .app-links{ grid-area: app; justify-self: center; margin-bottom: 4px; }
.form-login{ grid-area: form; justify-self: center; align-self: start; }

/* Right rail: vertical action buttons */
.btn-rail{
  grid-area: buttons;
  justify-self: start;            /* hug the form side */
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-left: 20px;
  border-left: 1px solid var(--border);
}
.btn-rail .btn{
  min-width: 200px;
  width: max-content;             /* grow with localized text */
  text-align: left;
}

/* Left rail: vertical links like the right rail */
.login-layout .links-container{
  grid-area: links;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: start;
  justify-self: end;              /* hug the form side */
  padding-right: 20px;
  border-right: 1px solid var(--border);
  background: transparent;
  border: 0;
  box-shadow: none;
  max-width: 260px;               /* adjust if needed */
}
.login-layout .links-container a{
  display: block;
  min-width: 200px;               /* mirrors .btn-rail .btn */
  width: max-content;
  text-align: left;
  padding: 10px 8px;
  color: var(--primary);
  text-decoration: none;
  border-radius: .5rem;
  border: 1px solid transparent;
}
.login-layout .links-container a:hover{
  background: #f3f6ff;
  text-decoration: underline;
}
.login-layout .links-container a:focus-visible{
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

/* ========== Phone portrait: one-column order ========== */
@media (max-width: 768px) and (orientation: portrait){
  .login-layout{
    grid-template-columns: 1fr;
    grid-template-areas:
      "app"
      "form"
      "buttons"
      "links";
    gap: 12px;
  }

  .btn-rail{
    border-left: none;
    padding-left: 0;
    width: 100%;
    max-width: 360px;
    justify-self: center;
  }
  .btn-rail .btn{
    width: 100%;
    text-align: center;
  }

  .login-layout .links-container{
    padding-right: 0;
    border-right: none;
    width: 100%;
    max-width: min(92vw, 520px);
    justify-self: center;
  }
  .login-layout .links-container a{
    min-width: 0;
    width: 100%;
    text-align: center;
  }
}

/* Also handle small landscape / narrow devices */
@media (max-width: 600px){
  .btn-rail{ gap: 10px; }
  .form-login{ max-width: 360px; }
}

/* Global direction awareness */
html[dir="rtl"] body { direction: rtl; }
html[dir="ltr"] body { direction: ltr; }

/* Inputs & textareas follow page direction and align accordingly */
.rtl-aware { direction: inherit; text-align: start; }
.rtl-aware::placeholder { text-align: inherit; }

/* Input groups: keep the eye button on the visual end */
html[dir="rtl"] .input-group { flex-direction: row-reverse; }
html[dir="rtl"] .input-group-append { margin-left: 0; margin-right: -1px; }

/* RTL mirroring for rails */
html[dir="rtl"] .btn-rail .btn { text-align: right; }
html[dir="rtl"] .links-container { padding-right: 0; padding-left: 20px; border-right: none; border-left: 1px solid var(--border); }
html[dir="rtl"] .links-container a{ text-align: right; }

/* Language dropdown search follows page direction */
html[dir="rtl"] .langdrop__search input { direction: inherit; text-align: start; }

/* ===== Loading overlay ===== */
#loading{
  display: none;                 /* jQuery fadeIn/fadeOut toggles this */
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.75);
  backdrop-filter: blur(2px);
  z-index: 2000;                 /* above .langdrop */
}

#loading .loading-content{
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  text-align: center;
  min-width: 180px;
}

#loading .spinner-border{
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: 12px;
}

#loading .loading-text{
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ===== Reduce motion: keep backdrop static, spinner still spins ===== */
@media (prefers-reduced-motion: reduce){
  #loading{ backdrop-filter: none; }
  #loading .spinner-border{
    animation: spinner-border .75s linear infinite !important;
  }
}
