:root {
    --bg-main:        #0a1628;
    --bg-card:        #0f2040;
    --bg-input:       #ffffff;
    --accent:         #1a5c2a;
    --accent-hover:   #22732f;
    --accent-glow:    rgba(26, 92, 42, 0.35);
    --text-primary:   #f0f4f8;
    --text-secondary: #8eafd4;
    --border:         rgba(255, 255, 255, 0.08);
    --error-color:    #f43f5e;
    --success-color:  #10b981;
    --transition:     all 0.3s ease;
}

* {
    margin:     0;
    padding:    0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
}

body {
    background-color: var(--bg-main);
    color:            var(--text-primary);
    display:          flex;
    justify-content:  center;
    align-items:      center;
    min-height:       100vh;
    min-height:       -webkit-fill-available;
    padding:          20px;
    position:         relative;
    overflow-x:       hidden;
}

body::before,
body::after {
    content:       '';
    position:      fixed;
    width:         500px;
    height:        500px;
    border-radius: 50%;
    filter:        blur(120px);
    z-index:       -1;
    opacity:       0.12;
    pointer-events: none;
}

body::before {
    background: #1a5c2a;
    top:        -150px;
    left:       -150px;
}

body::after {
    background: #2d8a42;
    bottom:     -150px;
    right:      -150px;
}

/* ── Container ── */
.auth-container {
    width:           100%;
    max-width:       460px;
    background:      var(--bg-card);
    padding:         48px 40px;
    border-radius:   24px;
    border:          1px solid var(--border);
    backdrop-filter: blur(10px);
    box-shadow:      0 24px 48px rgba(0, 0, 0, 0.4);
    animation:       modalIn 0.4s ease-out;
}

@keyframes modalIn {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

/* ── Logo ── */
.logo-wrapper {
    text-align:    center;
    margin-bottom: 32px;
}

.logo-wrapper img {
    max-width: 200px;
    height:    auto;
}

/* ── Headings ── */
h2 {
    font-size:     22px;
    font-weight:   700;
    text-align:    center;
    margin-bottom: 8px;
    color:         var(--text-primary);
}

p.subtitle {
    text-align:    center;
    font-size:     14px;
    color:         var(--text-secondary);
    margin-bottom: 28px;
    line-height:   1.5;
}

/* ── Forms ── */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display:        block;
    font-size:      0.82rem;
    font-weight:    500;
    color:          var(--text-secondary);
    margin-bottom:  8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-wrapper input {
    width:         100%;
    padding:       14px 16px;
    background:    var(--bg-input);
    border:        1px solid #d1dae8;
    border-radius: 12px;
    font-size:     16px;
    color:         #0d1b2e;
    transition:    var(--transition);
    outline:       none;
    -webkit-appearance: none;
    appearance:    none;
}

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

.input-wrapper input:focus {
    border-color: #1a5c2a;
    box-shadow:   0 0 0 3px rgba(26, 92, 42, 0.15);
}

/* ── Buttons ── */
.btn {
    width:           100%;
    padding:         14px;
    border:          none;
    border-radius:   12px;
    font-size:       1rem;
    font-weight:     600;
    cursor:          pointer;
    transition:      var(--transition);
    display:         flex;
    justify-content: center;
    align-items:     center;
    gap:             10px;
    -webkit-appearance: none;
    touch-action:    manipulation;
}

.btn-primary {
    background:  linear-gradient(135deg, #1a5c2a 0%, #2d8a42 100%);
    color:       white;
    box-shadow:  0 4px 15px rgba(26, 92, 42, 0.35);
    margin-top:  8px;
}

.btn-primary:hover {
    transform:  translateY(-2px);
    box-shadow: 0 6px 20px rgba(26, 92, 42, 0.45);
}

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

.btn-primary:disabled {
    opacity:   0.7;
    cursor:    not-allowed;
    transform: none;
}

.btn-link {
    background:  none;
    color:       #4d9fff;
    font-size:   0.88rem;
    margin-top:  12px;
    padding:     8px;
    font-weight: 400;
}

.btn-link:hover { color: #66aaff; }

/* ── Views ── */
.auth-view        { display: none; }
.auth-view.active { display: block; }

/* ── Messages ── */
.message {
    padding:       12px 16px;
    border-radius: 12px;
    font-size:     14px;
    margin-bottom: 20px;
    display:       none;
    text-align:    center;
    line-height:   1.4;
}

.message.error {
    display:    block;
    background: rgba(244, 63, 94, 0.1);
    color:      var(--error-color);
    border:     1px solid rgba(244, 63, 94, 0.2);
}

.message.success {
    display:    block;
    background: rgba(16, 185, 129, 0.1);
    color:      var(--success-color);
    border:     1px solid rgba(16, 185, 129, 0.2);
}

/* ── Loader ── */
.loader {
    width:            20px;
    height:           20px;
    border:           3px solid rgba(255, 255, 255, 0.3);
    border-radius:    50%;
    border-top-color: white;
    animation:        spin 1s linear infinite;
    display:          none;
}

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

.loading .loader   { display: block; }
.loading .btn-text { display: none;  }

/* ── QR Container ── */
.qr-container {
    display:         flex;
    justify-content: center;
    align-items:     center;
    margin:          24px auto 16px;
    padding:         16px;
    background:      #ffffff;
    border-radius:   16px;
    box-shadow:      0 4px 12px rgba(0,0,0,0.2);
    width:           fit-content;
    min-width:       252px;
    min-height:      252px;
}

#qr-canvas {
    display:         flex;
    align-items:     center;
    justify-content: center;
    line-height:     0;
}

#qr-canvas > div        { line-height: 0; display: block; }
#qr-canvas img,
#qr-canvas > div > img  {
    display:       block !important;
    width:         220px !important;
    height:        220px !important;
    border-radius: 4px;
}

/* ── Manual MFA code ── */
.secret-code-wrapper {
    text-align:    center;
    margin-bottom: 8px;
}

.secret-label {
    font-size:     12px;
    color:         var(--text-secondary);
    margin-bottom: 8px;
}

.secret-code {
    display:        inline-block;
    background:     rgba(255,255,255,0.05);
    border:         1px solid var(--border);
    border-radius:  8px;
    padding:        8px 16px;
    font-family:    monospace;
    font-size:      12px;
    letter-spacing: 2px;
    color:          var(--text-primary);
    word-break:     break-all;
    max-width:      100%;
    line-height:    1.6;
}

/* ── TOTP icon ── */
.totp-icon {
    text-align:    center;
    font-size:     52px;
    margin-bottom: 20px;
}

/* ── Back to login ── */
.back-to-login {
    display:         flex;
    align-items:     center;
    justify-content: center;
    margin-top:      20px;
    color:           var(--text-secondary);
    font-size:       0.88rem;
    cursor:          pointer;
    transition:      var(--transition);
}

.back-to-login:hover { color: var(--accent-hover); }

/* ── Footer ── */
.footer-text {
    text-align:  center;
    font-size:   11px;
    color:       var(--text-secondary);
    margin-top:  36px;
    opacity:     0.7;
}

/* ══════════════════════════════════════════
   MOBILE — iPhone / iPad
══════════════════════════════════════════ */
@media (max-width: 480px) {
    body {
        padding:    12px;
        align-items: flex-start;
        padding-top: 24px;
    }

    .auth-container {
        padding:       32px 24px;
        border-radius: 20px;
        max-width:     100%;
    }

    .logo-wrapper img {
        max-width: 160px;
    }

    h2 { font-size: 20px; }

    .input-wrapper input {
        font-size: 16px;
        padding:   14px 14px;
    }

    .btn {
        padding:   15px;
        font-size: 16px;
    }

    #qr-canvas img,
    #qr-canvas > div > img {
        width:  180px !important;
        height: 180px !important;
    }

    .qr-container {
        min-width:  212px;
        min-height: 212px;
    }
}

@media (max-width: 375px) {
    .auth-container {
        padding: 28px 20px;
    }
}

/* ── Safe area for iPhone notch ── */
@supports (padding: max(0px)) {
    body {
        padding-left:   max(12px, env(safe-area-inset-left));
        padding-right:  max(12px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}