/* ============================================
   VARIÁVEIS DE TEMA
   ============================================ */
:root {
    --bg-primary: #f2f2f7;
    --bg-card: #ffffff;
    --bg-input: #f2f2f7;
    --bg-input-focus: #ffffff;
    --bg-button: #007aff;
    --bg-button-hover: #0051d5;
    --bg-key: #f2f2f7;
    --bg-key-hover: #e5e5ea;
    --bg-key-active: #d1d1d6;
    
    --text-primary: #000000;
    --text-secondary: #8e8e93;
    --text-white: #ffffff;
    --text-link: #007aff;
    
    --border-input: #d1d1d6;
    --border-input-focus: #007aff;
    
    --error-bg: #ff3b30;
    --error-text: #ffffff;
    --wait-bg: #fff3cd;
    --wait-border: #ffc107;
    --wait-text: #856404;
    
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.08);

    /* Ecrã do PIN (estilo "O Meu Pingo Doce") */
    --pin-screen-bg: #ffffff;
    --pin-blob-accent: #3bbeff;
    --pin-blob-soft: #d6f1ff;
    --pin-text: #161616;
    --pin-text-script: #1a1a1a;
    --pin-dot-border: #c9c9c9;
    --pin-dot-bg: #ffffff;
    --pin-key-text: #000000;
    --pin-footer-text: #444444;
    --pin-home-indicator: #1a1a1a;
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-card: #161b22;
    --bg-input: #21262d;
    --bg-input-focus: #161b22;
    --bg-button: #1f6feb;
    --bg-button-hover: #58a6ff;
    --bg-key: #21262d;
    --bg-key-hover: #2d333b;
    --bg-key-active: #373e47;
    
    --text-primary: #e6edf3;
    --text-secondary: #7d8590;
    --text-white: #e6edf3;
    --text-link: #58a6ff;
    
    --border-input: #30363d;
    --border-input-focus: #58a6ff;
    
    --error-bg: #f85149;
    --error-text: #ffffff;
    --wait-bg: #3d2e00;
    --wait-border: #f0c36d;
    --wait-text: #f0c36d;
    
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.4);

    /* Ecrã do PIN (estilo "O Meu Pingo Doce") */
    --pin-screen-bg: #0E1117;
    --pin-blob-accent: #2C5C8F;
    --pin-blob-soft: #1A1F2B;
    --pin-text: #FFFFFF;
    --pin-text-script: #A9B4C7;
    --pin-dot-border: #383E4D;
    --pin-dot-bg: transparent;
    --pin-key-text: #FFFFFF;
    --pin-footer-text: #A9B4C7;
    --pin-home-indicator: #FFFFFF;
}

/* ============================================
   RESET E CONFIGURAÇÕES GLOBAIS
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: none;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   CONTAINER
   ============================================ */
.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    text-align: center;
    padding: 40px 0 30px;
}

.header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.header p {
    font-size: 15px;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

/* ============================================
   CONTENT
   ============================================ */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-bottom: 20px;
}

/* ============================================
   CARD
   ============================================ */
.card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-card);
    transition: all 0.3s ease;
}

/* ============================================
   USER GREETING
   ============================================ */
.user-greeting {
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 24px;
    transition: color 0.3s ease;
}

.user-greeting strong {
    color: var(--text-primary);
    font-weight: 600;
    transition: color 0.3s ease;
}

/* ============================================
   INPUT GROUP
   ============================================ */
.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.input-group input {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.input-group input:focus {
    outline: none;
    border-color: var(--border-input-focus);
    background: var(--bg-input-focus);
}

.input-group input::placeholder {
    color: var(--text-secondary);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--bg-button);
    color: var(--text-white);
}

.btn-primary:hover {
    background: var(--bg-button-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* ============================================
   ERROR & ALERTS
   ============================================ */
.error-banner {
    background: var(--error-bg);
    color: var(--error-text);
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
    animation: slideIn 0.3s ease;
    transition: all 0.3s ease;
}

.attempts-info {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    margin: 12px 0;
    transition: color 0.3s ease;
}

.wait-timer {
    background: var(--wait-bg);
    border: 1px solid var(--wait-border);
    color: var(--wait-text);
    padding: 12px 16px;
    border-radius: 10px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    transition: all 0.3s ease;
}

.blocked-message {
    background: var(--error-bg);
    color: var(--error-text);
    padding: 16px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.6;
    transition: all 0.3s ease;
}

.blocked-message a {
    color: var(--error-text);
    text-decoration: underline;
    font-weight: 600;
}

/* ============================================
   FOOTER LINKS
   ============================================ */
.footer-links {
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.8;
    transition: color 0.3s ease;
}

.footer-links a {
    color: var(--text-link);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.footer-links a:hover {
    text-decoration: underline;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   RESPONSIVIDADE - MOBILE PEQUENO
   ============================================ */
@media (max-width: 400px) {
    .container {
        padding: 16px;
    }
    
    .header {
        padding: 25px 0 20px;
    }
    
    .header h1 {
        font-size: 24px;
    }
    
    .header p {
        font-size: 14px;
    }
    
    .card {
        padding: 20px;
        border-radius: 14px;
    }
    
    .input-group input {
        padding: 12px 14px;
        font-size: 15px;
    }
    
    .btn {
        padding: 12px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 30px 0 20px;
    }
    
    .header h1 {
        font-size: 26px;
    }
}

@media (max-width: 360px) {
}

/* Modo paisagem mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .header {
        padding: 20px 0 15px;
    }
    
    .header h1 {
        font-size: 22px;
    }
    
    .header p {
        font-size: 13px;
    }
}

/* ============================================
   RESPONSIVIDADE - TABLETS
   ============================================ */
@media (min-width: 768px) {
    .container {
        max-width: 600px;
        padding: 24px 32px;
    }
    
    .header {
        padding: 50px 0 40px;
    }
    
    .header h1 {
        font-size: 32px;
        margin-bottom: 10px;
    }
    
    .header p {
        font-size: 17px;
    }
    
    .card {
        padding: 32px;
        border-radius: 18px;
    }
    
    .user-greeting {
        font-size: 17px;
        margin-bottom: 28px;
    }
    
    .input-group {
        margin-bottom: 18px;
    }
    
    .input-group label {
        font-size: 15px;
        margin-bottom: 10px;
    }
    
    .input-group input {
        padding: 16px 18px;
        font-size: 17px;
        border-radius: 12px;
    }
    
    .btn {
        padding: 16px;
        font-size: 17px;
        border-radius: 12px;
    }
    
    .error-banner,
    .wait-timer,
    .blocked-message {
        padding: 14px 18px;
        font-size: 15px;
        border-radius: 12px;
    }
    
    .attempts-info {
        font-size: 14px;
    }
    
    .footer-links {
        margin-top: 24px;
        font-size: 14px;
    }
}

/* ============================================
   RESPONSIVIDADE - DESKTOPS
   ============================================ */
@media (min-width: 1024px) {
    .container {
        max-width: 700px;
        padding: 32px 48px;
    }
    
    .header {
        padding: 60px 0 50px;
    }
    
    .header h1 {
        font-size: 36px;
        margin-bottom: 12px;
    }
    
    .header p {
        font-size: 18px;
    }
    
    .card {
        padding: 40px;
        border-radius: 20px;
    }
    
    .user-greeting {
        font-size: 18px;
        margin-bottom: 32px;
    }
    
    .input-group {
        margin-bottom: 20px;
    }
    
    .input-group label {
        font-size: 16px;
        margin-bottom: 12px;
    }
    
    .input-group input {
        padding: 18px 20px;
        font-size: 18px;
        border-radius: 14px;
    }
    
    .btn {
        padding: 18px;
        font-size: 18px;
        border-radius: 14px;
    }
    
    .error-banner,
    .wait-timer,
    .blocked-message {
        padding: 16px 20px;
        font-size: 16px;
        border-radius: 14px;
    }
    
    .attempts-info {
        font-size: 15px;
    }
    
    .footer-links {
        margin-top: 28px;
        font-size: 15px;
    }
    
    /* Efeitos hover para desktop */
    .btn-primary:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
    }
    
    .footer-links a:hover {
        color: var(--bg-button-hover);
    }
}

/* ============================================
   RESPONSIVIDADE - TELAS MUITO GRANDES
   ============================================ */
@media (min-width: 1440px) {
    .container {
        max-width: 800px;
    }
    
    .header h1 {
        font-size: 40px;
    }
    
    .header p {
        font-size: 19px;
    }
    
    .card {
        padding: 48px;
    }
}

/* ============================================
   ECRÃ DE PIN (estilo "O Meu Pingo Doce")
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Caveat:wght@600;700&display=swap');

.pin-screen {
    position: fixed;
    inset: 0;
    background: var(--pin-screen-bg);
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    display: flex;
    flex-direction: column;
    font-family: 'Baloo 2', sans-serif;
    transition: background-color 0.3s ease;
    z-index: 500;
}

/* ---------- Decorative blobs ---------- */
.pin-blob {
    position: absolute;
    border-radius: 50%;
    z-index: 0;
    pointer-events: none;
}

.pin-blob-top-right {
    width: 220px;
    height: 220px;
    max-width: 38vw;
    max-height: 30vh;
    background: var(--pin-blob-accent);
    opacity: 0.85;
    top: -6%;
    right: -6%;
}

.pin-blob-mid-left {
    width: 145px;
    height: 145px;
    max-width: 26vw;
    max-height: 20vh;
    background: var(--pin-blob-soft);
    top: 38%;
    left: -7%;
}

.pin-blob-corner {
    display: none;
}

/* ---------- Main content ---------- */
.pin-content {
    position: relative;
    z-index: 1;
    flex: 0 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-top: clamp(20px, 6vh, 60px);
}

.pin-logo-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.pin-welcome {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: clamp(24px, 6vh, 36px);
    line-height: 1;
    letter-spacing: -0.5px;
    color: var(--pin-text);
    text-align: center;
}

.pin-name-script {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(20px, 5vh, 30px);
    color: var(--pin-text-script);
    margin-top: 2px;
    transform: rotate(-2deg);
    text-align: center;
}

.pin-title {
    margin-top: clamp(12px, 3vh, 30px);
    font-size: clamp(16px, 3.6vh, 22px);
    font-weight: 700;
    color: var(--pin-text);
    text-align: center;
    padding: 0 24px;
}

/* ---------- Code dots ---------- */
.pin-dots {
    display: flex;
    gap: clamp(10px, 2.2vh, 16px);
    margin-top: clamp(14px, 3vh, 24px);
}

.pin-dot {
    width: clamp(13px, 2.2vh, 17px);
    height: clamp(13px, 2.2vh, 17px);
    border-radius: 50%;
    border: 1.5px solid var(--pin-dot-border);
    background: var(--pin-dot-bg);
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.pin-dot.filled {
    background: var(--pin-blob-accent);
    border-color: var(--pin-blob-accent);
    transform: scale(1.05);
}

.pin-dot.error {
    border-color: var(--error-bg);
}

@keyframes pin-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(4px); }
}

.pin-dots.shake {
    animation: pin-shake 0.4s ease;
}

/* ---------- Messages above keypad ---------- */
.pin-messages {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    width: 100%;
    max-width: 360px;
    margin: clamp(8px, 1.8vh, 14px) auto 0;
    padding: 0 16px;
}

/* ---------- Keypad area ---------- */
.pin-keypad-area {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.pin-keypad-bg {
    position: absolute;
    bottom: 0;
    left: -10%;
    width: 120%;
    height: 100%;
    background: radial-gradient(ellipse 75% 60% at 50% 100%, var(--pin-blob-soft) 0%, var(--pin-blob-soft) 55%, rgba(0,0,0,0) 100%);
    border-radius: 50% 50% 0 0 / 65% 65% 0 0;
    z-index: 0;
}

.pin-keypad {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    max-width: 360px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
}

.pin-key-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 10px;
    flex: 1 1 auto;
    min-height: 0;
}

.pin-key {
    width: clamp(60px, 22vw, 100px);
    height: 100%;
    max-height: clamp(56px, 11vh, 100px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(28px, 8vh, 52px);
    font-weight: 700;
    font-family: 'Baloo 2', sans-serif;
    color: var(--pin-key-text);
    background: none;
    border: none;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: opacity 0.1s ease, transform 0.08s ease;
}

.pin-key:active {
    opacity: 0.55;
    transform: scale(0.94);
}

.pin-key.pin-icon-key {
    color: var(--pin-key-text);
}

.pin-key.pin-icon-key svg {
    width: clamp(22px, 6vh, 36px);
    height: clamp(22px, 6vh, 36px);
}

.pin-key.pin-icon-key:disabled {
    opacity: 0;
    cursor: default;
    pointer-events: none;
}

/* ---------- Footer links ---------- */
.pin-footer-links {
    flex: 0 0 auto;
    margin-top: clamp(2px, 0.8vh, 4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(2px, 0.8vh, 6px);
}

.pin-footer-link {
    font-size: clamp(11px, 2.6vh, 14px);
    font-weight: 600;
    color: var(--pin-footer-text);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    text-decoration: none;
    font-family: 'Baloo 2', sans-serif;
}

.pin-footer-link .pin-action {
    color: var(--pin-blob-accent);
    font-weight: 700;
}

/* ---------- Responsividade ---------- */
@media (max-width: 360px) {
    .pin-key { width: clamp(54px, 20vw, 90px); }
}

@media (min-width: 480px) {
    .pin-keypad,
    .pin-messages {
        max-width: 400px;
    }
}

/* Ecrãs muito baixos (browser com barra de endereço, landscape, etc.) */
@media (max-height: 650px) {
    .pin-content {
        padding-top: clamp(10px, 3vh, 30px);
    }
    .pin-welcome { font-size: clamp(20px, 5vh, 30px); }
    .pin-name-script { font-size: clamp(16px, 4vh, 24px); }
    .pin-title { font-size: clamp(14px, 3vh, 18px); margin-top: clamp(8px, 2vh, 16px); }
    .pin-dots { margin-top: clamp(8px, 2vh, 14px); }
}