/* ========================================
   MATERIAL DESIGN 3 - AUTH STYLES
   Abie Messenger
   ======================================== */

/* ========================================
   AUTH SCREEN LAYOUT
   ======================================== */
#authScreen {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--md-sys-color-surface);
  padding: 24px;
  /* iOS PWA: padding для safe area */
  padding-top: max(24px, env(safe-area-inset-top, 24px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
  padding-left: max(24px, env(safe-area-inset-left, 24px));
  padding-right: max(24px, env(safe-area-inset-right, 24px));
}

/* ========================================
   AUTH CARD (Elevated Card Style)
   ======================================== */
.auth-box {
  background: var(--md-sys-color-surface-container-lowest);
  padding: 48px 40px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  box-shadow: var(--md-sys-elevation-level3);
  text-align: center;
  width: 100%;
  max-width: 420px;
  animation: md-scale-in var(--md-sys-motion-duration-medium4) var(--md-sys-motion-easing-emphasized-decelerate);
}

/* ========================================
   BRANDING
   ======================================== */
.auth-box h1 {
  font-family: var(--md-sys-typescale-display-small-font-family);
  font-size: var(--md-sys-typescale-display-small-font-size);
  font-weight: 700;
  line-height: var(--md-sys-typescale-display-small-line-height);
  color: var(--md-sys-color-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.auth-box > p {
  font-family: var(--md-sys-typescale-body-large-font-family);
  font-size: var(--md-sys-typescale-body-large-font-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 32px;
}

/* ========================================
   AUTH TABS (Segmented Button Style)
   ======================================== */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 32px;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 4px;
  position: relative;
}

/* Скользящий индикатор */
.auth-tabs .tab-indicator {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: var(--md-sys-color-secondary-container);
  border-radius: var(--md-sys-shape-corner-full);
  box-shadow: var(--md-sys-elevation-level1);
  transition: transform var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
  z-index: 0;
}

.auth-tabs[data-active="register"] .tab-indicator {
  transform: translateX(100%);
}

.auth-tab {
  flex: 1;
  padding: 12px 24px;
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-label-large-font-family);
  font-size: var(--md-sys-typescale-label-large-font-size);
  font-weight: var(--md-sys-typescale-label-large-font-weight);
  letter-spacing: var(--md-sys-typescale-label-large-letter-spacing);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.auth-tab::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  border-radius: inherit;
}

.auth-tab:hover::before {
  opacity: var(--md-sys-state-hover-opacity);
}

.auth-tab.active {
  color: var(--md-sys-color-on-secondary-container);
}

.auth-tab.active::before {
  opacity: 0;
}

/* ========================================
   AUTH FORMS
   ======================================== */
.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
  animation: md-fade-in var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-standard-decelerate);
}

/* ========================================
   TEXT FIELDS (Outlined Style)
   ======================================== */
.auth-form input,
.auth-form select {
  width: 100%;
  padding: 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-family: var(--md-sys-typescale-body-large-font-family);
  font-size: var(--md-sys-typescale-body-large-font-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  color: var(--md-sys-color-on-surface);
  background: transparent;
  margin-bottom: 16px;
  transition:
    border-color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    border-width var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    box-shadow var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.auth-form input::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

.auth-form input:hover,
.auth-form select:hover {
  border-color: var(--md-sys-color-on-surface);
}

.auth-form input:focus,
.auth-form select:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 15px; /* Compensate for thicker border */
}

/* Input with error state */
.auth-form input.error,
.auth-form input:invalid:not(:placeholder-shown) {
  border-color: var(--md-sys-color-error);
}

.auth-form input.error:focus {
  border-color: var(--md-sys-color-error);
}

/* Select styling */
.auth-form select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%2374777F' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
  cursor: pointer;
}

/* ========================================
   BUTTONS (Filled Style)
   ======================================== */
.auth-form button {
  width: 100%;
  padding: 16px 24px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-label-large-font-family);
  font-size: var(--md-sys-typescale-label-large-font-size);
  font-weight: var(--md-sys-typescale-label-large-font-weight);
  letter-spacing: var(--md-sys-typescale-label-large-letter-spacing);
  cursor: pointer;
  transition:
    box-shadow var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
    transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  position: relative;
  overflow: hidden;
  margin-top: 8px;
}

.auth-form button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.auth-form button:hover {
  box-shadow: var(--md-sys-elevation-level1);
}

.auth-form button:hover::before {
  opacity: var(--md-sys-state-hover-opacity);
}

.auth-form button:active {
  transform: scale(0.98);
}

.auth-form button:active::before {
  opacity: var(--md-sys-state-pressed-opacity);
}

.auth-form button:disabled {
  background: var(--md-sys-color-on-surface);
  color: var(--md-sys-color-surface);
  opacity: 0.12;
  cursor: not-allowed;
  box-shadow: none;
}

.auth-form button:disabled::before {
  display: none;
}

/* ========================================
   ERROR MESSAGE
   ======================================== */
.error-message {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  margin-top: 16px;
  font-family: var(--md-sys-typescale-body-medium-font-family);
  font-size: var(--md-sys-typescale-body-medium-font-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  text-align: left;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: md-shake 0.5s var(--md-sys-motion-easing-standard);
}

.error-message::before {
  content: '';
  width: 24px;
  height: 24px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23410002' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E");
  background-size: contain;
  flex-shrink: 0;
}

/* ========================================
   FORM HINT
   ======================================== */
.form-hint {
  font-family: var(--md-sys-typescale-body-small-font-family);
  font-size: var(--md-sys-typescale-body-small-font-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  color: var(--md-sys-color-on-surface-variant);
  text-align: left;
  margin: -8px 0 16px 0;
  padding-left: 16px;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 480px) {
  #authScreen {
    padding: 16px;
    align-items: flex-start;
    padding-top: 10vh;
  }

  .auth-box {
    padding: 32px 24px;
    border-radius: var(--md-sys-shape-corner-large);
  }

  .auth-box h1 {
    font-size: 32px;
    line-height: 40px;
  }

  .auth-tabs {
    margin-bottom: 24px;
  }

  .auth-tab {
    padding: 10px 16px;
    font-size: 13px;
  }

  .auth-form input,
  .auth-form select {
    padding: 14px;
  }

  .auth-form input:focus,
  .auth-form select:focus {
    padding: 13px;
  }

  .auth-form button {
    padding: 14px 20px;
  }
}

/* ========================================
   LOADING STATE
   ======================================== */
.auth-form button.loading {
  color: transparent;
  pointer-events: none;
}

.auth-form button.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  margin-top: -10px;
  margin-left: -10px;
  border: 2px solid transparent;
  border-top-color: var(--md-sys-color-on-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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