/* ============================================================
   Store Mini — Mobile-First Design System
   ✅ Safe-area insets (iPhone notch / Dynamic Island)
   ✅ Dynamic viewport height (dvh) — handles iOS keyboard
   ✅ Touch targets ≥ 44×44 px (Apple HIG)
   ✅ font-size ≥ 16px on inputs — prevents iOS auto-zoom
   ✅ Signature modal as full-screen bottom sheet on mobile
   ✅ Overscroll / rubber-band prevention
   ✅ Hardware-accelerated animations only
   ============================================================ */

/* ========== CSS VARIABLES ========== */
:root {
    --bg-main: #0d1117;
    --bg-secondary: #0f172a;
    --card-bg: #1e293b;
    --card-border: rgba(148, 163, 184, 0.12);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #38bdf8;
    --primary-dark: #0ea5e9;
    --primary-deeper: #0284c7;
    --danger: #f87171;
    --success: #34d399;
    --line: rgba(148, 163, 184, 0.2);
    --glow-primary: rgba(56, 189, 248, 0.25);

    /* Safe-area */
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);

    /* Touch target minimum */
    --touch-min: 48px;
}

/* ========== RESET ========== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    /* Prevent iOS text-size-adjust after orientation change */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: "Sarabun", "Segoe UI", Arial, sans-serif;
    color: var(--text-main);
    /* Prevent overscroll bounce on iOS */
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== AUTH PAGE — FULL-SCREEN LAYOUT ========== */
html:has(.auth-page) {
    width: 100%;
    height: 100%;
}
html:has(.auth-page) body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
}

.auth-page {
    background:
        radial-gradient(ellipse at 20% 20%, rgba(56, 189, 248, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(14, 165, 233, 0.06) 0%, transparent 50%),
        linear-gradient(160deg, #0d1117 0%, #0f172a 50%, #0d1b2a 100%);
    min-height: 100dvh;
    min-height: 100vh; /* fallback */
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding:
        calc(20px + var(--sat))
        calc(16px + var(--sar))
        calc(20px + var(--sab))
        calc(16px + var(--sal));
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
}

.auth-backdrop {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.auth-shell {
    position: relative;
    z-index: 1;
    width: min(100%, 420px);
    margin: auto;
    flex: 0 0 auto;
}

/* On very small screens (e.g. 320px wide), let content scroll from top */
@media (max-height: 600px) {
    .auth-page {
        justify-content: flex-start;
        align-items: center;
        padding-top: calc(16px + var(--sat));
        padding-bottom: calc(16px + var(--sab));
    }
}

/* ========== BACKGROUND ORBS ========== */
.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
    pointer-events: none;
    z-index: 0;
    will-change: transform;
}

.bg-orb-1 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.18) 0%, transparent 70%);
    top: -120px;
    right: -80px;
    animation: orbFloat1 14s ease-in-out infinite;
}

.bg-orb-2 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(14, 165, 233, 0.12) 0%, transparent 70%);
    bottom: -80px;
    left: -60px;
    animation: orbFloat2 16s ease-in-out infinite;
}

.bg-orb-3 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.1) 0%, transparent 70%);
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: orbFloat3 12s ease-in-out infinite;
}

@keyframes orbFloat1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-40px, 50px) scale(1.12); }
}
@keyframes orbFloat2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(50px, -40px) scale(1.1); }
}
@keyframes orbFloat3 {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.3; }
    50% { transform: translate(-50%, -56%) scale(1.18); opacity: 0.5; }
}

/* ========== LOGIN CARD ========== */
.login-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    background: linear-gradient(160deg, rgba(30, 41, 59, 0.96) 0%, rgba(15, 23, 42, 0.99) 100%);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 40px 28px 32px;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.3),
        0 12px 28px rgba(0, 0, 0, 0.4),
        0 32px 64px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    text-align: center;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Glowing top accent */
.login-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.6), transparent);
    border-radius: 50%;
    pointer-events: none;
}

/* ========== CARD ENTER ANIMATION ========== */
.card-enter {
    animation: cardEnter 0.8s cubic-bezier(0.34, 1.3, 0.64, 1) forwards;
    opacity: 0;
    transform: translateY(40px) scale(0.92) perspective(800px) rotateX(5deg);
    will-change: transform, opacity;
}

@keyframes cardEnter {
    to {
        opacity: 1;
        transform: translateY(0) scale(1) perspective(800px) rotateX(0deg);
    }
}

/* ========== APP LOGO ========== */
.app-logo {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 14px;
    animation: float 3.5s ease-in-out infinite;
    will-change: transform;
}

.logo-mark,
.app-brand-icon {
    object-fit: cover;
    display: block;
    flex-shrink: 0;
    background: transparent;
    padding: 0;
    border: none;
}

.logo-mark {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    box-shadow:
        0 8px 24px rgba(56, 189, 248, 0.15),
        0 0 40px rgba(56, 189, 248, 0.08);
    animation: logoGlow 4.5s ease-in-out infinite;
}

.app-brand-icon {
    width: 58px;
    height: 58px;
    border-radius: 14px;
    box-shadow: none;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes logoGlow {
    0%, 100% { box-shadow: 0 8px 24px rgba(56,189,248,.15), 0 0 40px rgba(56,189,248,.08); }
    50% { box-shadow: 0 12px 32px rgba(56,189,248,.3), 0 0 60px rgba(56,189,248,.15); }
}

.app-title {
    margin: 0 0 6px;
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.app-subtitle {
    margin: 0 0 28px;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.55;
}

/* ========== PIN DOTS ========== */
.pin-dots {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 28px;
}

.pin-dot {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(148, 163, 184, 0.3);
    border-radius: 50%;
    background: rgba(148, 163, 184, 0.05);
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    will-change: transform;
}

.pin-dot.active {
    background: linear-gradient(145deg, #67e8f9, #38bdf8, #0ea5e9);
    border-color: #38bdf8;
    box-shadow:
        0 0 18px rgba(56, 189, 248, 0.65),
        0 4px 12px rgba(56, 189, 248, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.3);
    transform: scale(1.25);
}

.pin-dot.pop {
    animation: dotPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dotPop {
    0% { transform: scale(0.7); }
    55% { transform: scale(1.55); }
    100% { transform: scale(1.25); }
}

/* ========== NUMPAD — MOBILE OPTIMIZED ========== */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
}

.num-btn {
    position: relative;
    overflow: hidden;
    background: linear-gradient(160deg, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.95) 100%);
    border: 1px solid rgba(148, 163, 184, 0.15);
    color: var(--text-main);
    border-radius: 16px;
    /* Minimum touch target: 48px */
    height: 72px;
    font-size: 1.6rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation; /* faster touch response, no double-tap zoom */
    -webkit-tap-highlight-color: transparent;
    box-shadow:
        0 4px 0 rgba(0, 0, 0, 0.4),
        0 8px 20px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    transform: translateY(0) scale(1);
    will-change: transform;
    transition:
        transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
        background 0.18s ease,
        border-color 0.18s ease;
    animation: btnFadeIn 0.5s cubic-bezier(0.34, 1.2, 0.64, 1) backwards;
}

@keyframes btnFadeIn {
    from { opacity: 0; transform: translateY(18px) scale(0.85); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.num-btn:hover {
    border-color: rgba(56, 189, 248, 0.3);
    background: linear-gradient(160deg, rgba(56, 189, 248, 0.08) 0%, rgba(14, 165, 233, 0.04) 100%);
    transform: translateY(-3px) scale(1.02);
    box-shadow:
        0 7px 0 rgba(0, 0, 0, 0.35),
        0 14px 30px rgba(56, 189, 248, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.num-btn.pressed,
.num-btn:active {
    transform: translateY(4px) scale(0.96);
    background: linear-gradient(160deg, rgba(56, 189, 248, 0.16) 0%, rgba(14, 165, 233, 0.1) 100%);
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow:
        0 1px 0 rgba(0, 0, 0, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.2),
        0 0 22px rgba(56, 189, 248, 0.22),
        inset 0 2px 6px rgba(0, 0, 0, 0.2);
    transition-duration: 0.08s;
}

.num-btn .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(56, 189, 248, 0.22);
    transform: scale(0);
    animation: rippleExpand 0.55s ease-out forwards;
    pointer-events: none;
    will-change: transform, opacity;
}

@keyframes rippleExpand {
    to { transform: scale(2.8); opacity: 0; }
}

.num-btn.control-btn {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-muted);
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.8) 0%, rgba(8, 15, 30, 0.9) 100%);
    border-color: rgba(148, 163, 184, 0.1);
    box-shadow:
        0 3px 0 rgba(0, 0, 0, 0.5),
        0 6px 14px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.num-btn.control-btn:hover { color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }

.num-btn.control-btn.pressed,
.num-btn.control-btn:active {
    color: var(--danger);
    background: linear-gradient(160deg, rgba(248, 113, 113, 0.12) 0%, rgba(239, 68, 68, 0.08) 100%);
    border-color: rgba(248, 113, 113, 0.4);
    box-shadow: 0 1px 0 rgba(0,0,0,.4), 0 0 16px rgba(248,113,113,.15), inset 0 2px 6px rgba(0,0,0,.25);
}

.num-btn .delete-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

/* ========== ALERTS ========== */
.error-alert {
    font-size: 0.875rem;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    background: rgba(248, 113, 113, 0.08);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--danger);
    animation: shake 0.4s ease-in-out;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
    line-height: 1.45;
}

.success-alert {
    font-size: 0.875rem;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    background: rgba(52, 211, 153, 0.08);
    border: 1px solid rgba(52, 211, 153, 0.3);
    color: var(--success);
    animation: fadeInUp 0.5s cubic-bezier(0.34, 1.2, 0.64, 1);
    display: flex;
    align-items: flex-start;
    gap: 8px;
    text-align: left;
    line-height: 1.45;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ========== LOADING OVERLAY ========== */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid rgba(56, 189, 248, 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    margin-bottom: 14px;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.2);
    will-change: transform;
}

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

.loading-text {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
}

/* ========== PAGE LINK ========== */
.page-link {
    margin-top: 24px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
    /* Ensure enough touch height around link */
    padding: 8px 0;
}

.login-card .page-link a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease, text-shadow 0.2s ease;
    display: inline-block;
    padding: 4px 8px; /* extra tap area */
}

.login-card .page-link a:hover {
    color: #67e8f9;
    text-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
}

/* ========== PWA INSTALL ========== */
.pwa-install {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.pwa-install__btn {
    width: 100%;
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 13px 18px;
    border-radius: 14px;
    border: 1px solid rgba(56, 189, 248, 0.25);
    background: rgba(56, 189, 248, 0.06);
    color: var(--primary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    box-shadow: 0 4px 14px rgba(56, 189, 248, 0.06);
}

.pwa-install__btn:hover { transform: translateY(-2px); border-color: rgba(56,189,248,.5); background: rgba(56,189,248,.1); box-shadow: 0 8px 24px rgba(56,189,248,.15); }
.pwa-install__btn:active { transform: translateY(0); }
.pwa-install__btn i { font-size: 1.2rem; }
.pwa-install__hint { margin: 8px 0 0; font-size: 0.78rem; color: var(--text-muted); }

/* ========== PWA INSTALL MODAL ========== */
.pwa-install-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: max(16px, var(--sat)) 16px max(16px, var(--sab));
}
.pwa-install-modal[hidden] { display: none !important; }

.pwa-install-modal__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.pwa-install-modal__panel {
    position: relative;
    width: min(100%, 380px);
    max-height: calc(100dvh - 32px);
    margin: auto;
    flex-shrink: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: linear-gradient(160deg, rgba(30, 41, 59, 0.99) 0%, rgba(15, 23, 42, 1) 100%);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 20px;
    padding: 28px 24px calc(24px + var(--sab));
    box-shadow: 0 32px 64px rgba(0,0,0,.5), 0 0 0 1px rgba(56,189,248,.1);
    text-align: center;
}

.pwa-install-modal__close {
    position: absolute; top: 14px; right: 14px;
    width: 40px; height: 40px;
    border: 1px solid rgba(148, 163, 184, 0.15); border-radius: 10px;
    background: rgba(148, 163, 184, 0.06); color: var(--text-muted);
    display: grid; place-items: center; cursor: pointer;
    touch-action: manipulation; font-size: 1.15rem;
    transition: background 0.2s, color 0.2s;
}
.pwa-install-modal__close:hover { background: rgba(248,113,113,.1); color: var(--danger); }

.pwa-install-modal__brand .logo-mark { width: 60px; height: 60px; animation: none; }
.pwa-install-modal__title { margin: 14px 0 8px; font-size: 1.25rem; color: var(--text-main); font-weight: 700; }
.pwa-install-modal__lead { margin: 0 0 16px; font-size: 0.9rem; color: var(--text-muted); line-height: 1.55; }
.pwa-install-modal__steps { margin: 0 0 20px; padding-left: 22px; text-align: left; font-size: 0.88rem; color: var(--text-main); line-height: 1.6; }
.pwa-install-modal__steps li + li { margin-top: 10px; }
.pwa-install-modal__steps i { vertical-align: -2px; color: var(--primary); }

.pwa-install-modal__done {
    width: 100%; border: none; border-radius: 12px;
    padding: 14px 18px;
    background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 60%, #0284c7 100%);
    color: #fff; font-family: inherit; font-size: 0.95rem; font-weight: 700;
    cursor: pointer; touch-action: manipulation;
    box-shadow: 0 8px 20px rgba(56,189,248,.25);
    min-height: var(--touch-min);
    transition: filter 0.2s, transform 0.2s;
}
.pwa-install-modal__done:hover { filter: brightness(1.08); transform: translateY(-1px); }

body.pwa-install-modal-open { overflow: hidden; }

/* ========== REGISTER CARD ========== */
.register-card { max-width: 480px; }
.register-card .app-subtitle { margin-bottom: 20px; }

/* ========== REGISTER FORM ========== */
.register-lookup {
    text-align: left;
    margin-bottom: 14px;
}

.register-lookup label {
    display: flex; align-items: center; gap: 7px;
    margin-bottom: 8px; font-size: 0.875rem;
    color: var(--text-muted); font-weight: 600;
}
.register-lookup label i { color: var(--primary); font-size: 1rem; }

.lookup-row { display: flex; gap: 10px; }

/* !! font-size: 16px — prevents iOS auto-zoom when focusing input !! */
.form-input {
    flex: 1; width: 100%;
    padding: 14px 14px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    font-size: 16px; /* MUST be ≥ 16px */
    font-family: inherit;
    color: var(--text-main);
    background: rgba(30, 41, 59, 0.7);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.25s ease, box-shadow 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-height: var(--touch-min);
}
.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14), 0 4px 12px rgba(56, 189, 248, 0.08);
}
.form-input::placeholder { color: rgba(148, 163, 184, 0.45); }

.lookup-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 0 20px;
    border: 1px solid rgba(56, 189, 248, 0.3); border-radius: 12px;
    background: rgba(56, 189, 248, 0.1); color: var(--primary);
    font-family: inherit; font-size: 0.95rem; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    touch-action: manipulation;
    min-height: var(--touch-min);
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.lookup-btn:hover { background: rgba(56,189,248,.18); border-color: rgba(56,189,248,.5); transform: translateY(-1px); }
.lookup-btn:active { transform: translateY(0); }

.lookup-hint {
    margin-top: 8px; font-size: 0.82rem;
    color: var(--text-muted); min-height: 20px; transition: color 0.2s;
}
.lookup-hint.success { color: var(--success); }
.lookup-hint.error { color: var(--danger); }
.lookup-hint.loading { color: var(--primary); }

.employee-preview {
    background: rgba(56, 189, 248, 0.04);
    border: 1px solid rgba(56, 189, 248, 0.12);
    border-radius: 14px; padding: 14px 16px; margin-bottom: 14px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px;
    text-align: left; opacity: 0.5;
    transition: opacity 0.3s, border-color 0.3s;
}
.employee-preview.ready { opacity: 1; border-color: rgba(56,189,248,.25); }
.preview-item span { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 3px; }
.preview-item strong { font-size: 0.9rem; color: var(--text-main); word-break: break-word; }

/* ========== ROLE SELECTOR ========== */
.register-role-section { text-align: left; margin-bottom: 14px; display: none; }
.register-role-section.show { display: block; }

.register-role-label {
    display: flex; align-items: center; gap: 7px;
    font-size: 0.875rem; color: var(--text-muted); font-weight: 600; margin-bottom: 10px;
}
.register-role-label i { color: var(--primary); }

.register-role-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.register-role-option { display: block; cursor: pointer; }
.register-role-option input { position: absolute; opacity: 0; pointer-events: none; }

.register-role-card {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 16px 12px;
    border-radius: 14px; border: 1.5px solid rgba(148, 163, 184, 0.15);
    background: rgba(30, 41, 59, 0.5); color: var(--text-muted);
    font-size: 0.9rem; font-weight: 600; min-height: 80px; justify-content: center;
    transition: all 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
    touch-action: manipulation;
}
.register-role-card i { font-size: 1.5rem; }
.register-role-option input:checked + .register-role-card {
    border-color: var(--primary); background: rgba(56, 189, 248, 0.1); color: var(--primary);
    box-shadow: 0 0 0 1px rgba(56,189,248,.2), 0 4px 16px rgba(56,189,248,.12);
    transform: translateY(-2px);
}
.register-role-card:hover { border-color: rgba(56,189,248,.3); color: var(--text-main); }

/* ========== PIN INFO ========== */
.register-pin-info {
    background: rgba(56, 189, 248, 0.05); border: 1px solid rgba(56, 189, 248, 0.15);
    border-radius: 14px; padding: 14px 16px; margin-bottom: 14px;
    text-align: left; display: none;
}
.register-pin-info.show { display: block; }
.register-pin-info__label {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.8rem; color: var(--text-muted); font-weight: 600; margin-bottom: 6px;
}
.register-pin-info__label i { color: var(--primary); }
.register-pin-info__value {
    font-size: 1.7rem; font-weight: 700; color: var(--primary);
    letter-spacing: 8px; text-shadow: 0 0 20px rgba(56,189,248,.4); margin-bottom: 4px;
}
.register-pin-info__hint { font-size: 0.78rem; color: var(--text-muted); }

/* ========== SIGNATURE SECTION ========== */
.register-signature-section { text-align: left; margin-bottom: 14px; display: none; }
.register-signature-section.show { display: block; }
.register-signature-label {
    display: flex; align-items: center; gap: 7px;
    font-size: 0.875rem; color: var(--text-muted); font-weight: 600; margin-bottom: 8px;
}
.register-signature-label i { color: var(--primary); }

.register-signature-box {
    display: flex; align-items: center; justify-content: center;
    min-height: 110px;
    border: 1.5px dashed rgba(56, 189, 248, 0.25); border-radius: 14px;
    background: rgba(56, 189, 248, 0.03); cursor: pointer; touch-action: manipulation;
    transition: border-color 0.25s, background 0.25s;
}
.register-signature-box:hover { border-color: rgba(56,189,248,.5); background: rgba(56,189,248,.06); }

.sig-placeholder-content {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    color: var(--text-muted); padding: 20px;
}
.sig-placeholder-content svg { width: 40px; height: 40px; opacity: 0.45; }
.sig-placeholder-content span { font-size: 0.9rem; }

.sig-preview-wrapper {
    display: flex; flex-direction: column; align-items: center;
    position: relative; width: 100%; padding: 12px;
}
.sig-preview-img {
    max-height: 80px; max-width: 100%; object-fit: contain;
    filter: invert(1) brightness(0.65) sepia(1) hue-rotate(165deg) saturate(3);
}
.sig-edit-badge {
    display: flex; align-items: center; gap: 5px;
    font-size: 0.78rem; color: var(--primary); margin-top: 6px;
}
.sig-edit-badge svg { width: 14px; height: 14px; stroke: currentColor; fill: none; }

/* ========== SUBMIT BUTTON ========== */
.submit-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    min-height: var(--touch-min);
    padding: 14px 18px;
    border: none; border-radius: 14px;
    background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 60%, #0284c7 100%);
    color: #fff; font-family: inherit; font-size: 1rem; font-weight: 700;
    cursor: pointer; touch-action: manipulation;
    box-shadow: 0 8px 20px rgba(56,189,248,.25), 0 2px 4px rgba(0,0,0,.2);
    transition: filter 0.2s, transform 0.2s, box-shadow 0.2s;
    margin-top: 8px;
}
.submit-btn:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-2px); box-shadow: 0 12px 28px rgba(56,189,248,.35), 0 4px 8px rgba(0,0,0,.2); }
.submit-btn:active:not(:disabled) { transform: translateY(0); filter: brightness(0.95); }
.submit-btn:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

/* ========== SIGNATURE MODAL — BOTTOM SHEET ON MOBILE ========== */
.sig-modal-overlay {
    position: fixed; inset: 0; z-index: 900;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: none; align-items: flex-end; justify-content: center;
    padding: 0;
}
.sig-modal-overlay.show { display: flex; }

.sig-modal-card {
    background: linear-gradient(160deg, rgba(30, 41, 59, 0.99) 0%, rgba(15, 23, 42, 1) 100%);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: 600px;
    overflow: hidden;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
    /* Safe area at bottom */
    padding-bottom: var(--sab);
    animation: slideUp 0.35s cubic-bezier(0.34, 1.2, 0.64, 1) forwards;
    will-change: transform;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0.6; }
    to   { transform: translateY(0); opacity: 1; }
}

/* Bottom sheet drag handle */
.sig-modal-card::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: rgba(148, 163, 184, 0.25);
    border-radius: 2px;
    margin: 12px auto 0;
}

.sig-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}
.sig-modal-header h3 { font-size: 1rem; font-weight: 700; color: var(--text-main); }
.sig-modal-close {
    background: none; border: none; font-size: 1.6rem; line-height: 1;
    cursor: pointer; color: var(--text-muted); padding: 4px; width: auto;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
    touch-action: manipulation; transition: color 0.2s;
}
.sig-modal-close:hover { color: var(--danger); }

.sig-modal-body { padding: 16px 20px; }

.sig-canvas-wrap {
    width: 100%; border-radius: 12px; overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.15);
    background: #f8fafc; touch-action: none;
}

.sig-canvas {
    width: 100%; height: 220px; display: block;
    cursor: crosshair; touch-action: none;
}

.sig-hint { margin: 10px 0 0; font-size: 0.8rem; color: var(--text-muted); text-align: center; }

.sig-modal-footer {
    display: flex; gap: 10px;
    padding: 12px 20px 16px;
}

.sig-btn-clear {
    flex: 1; padding: 13px;
    border-radius: 12px; border: 1px solid rgba(248, 113, 113, 0.3);
    background: rgba(248, 113, 113, 0.08); color: var(--danger);
    font-family: inherit; font-size: 0.95rem; font-weight: 600;
    cursor: pointer; touch-action: manipulation;
    min-height: var(--touch-min);
    transition: background 0.2s, border-color 0.2s;
}
.sig-btn-clear:hover { background: rgba(248,113,113,.14); border-color: rgba(248,113,113,.5); }

.sig-btn-save {
    flex: 2; padding: 13px;
    border-radius: 12px; border: none;
    background: linear-gradient(135deg, #38bdf8, #0ea5e9, #0284c7);
    color: #fff; font-family: inherit; font-size: 0.95rem; font-weight: 700;
    cursor: pointer; touch-action: manipulation;
    min-height: var(--touch-min);
    box-shadow: 0 4px 14px rgba(56,189,248,.2);
    transition: filter 0.2s, transform 0.2s;
}
.sig-btn-save:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ========== DESKTOP OVERRIDE — Centered modal dialog ========== */
@media (min-width: 601px) {
    .sig-modal-overlay {
        align-items: center;
        padding: 20px;
    }
    .sig-modal-card {
        border-radius: 20px;
        max-width: 500px;
        width: 100%;
        animation: fadeScaleIn 0.3s cubic-bezier(0.34, 1.2, 0.64, 1) forwards;
    }
    @keyframes fadeScaleIn {
        from { transform: scale(0.9); opacity: 0; }
        to   { transform: scale(1); opacity: 1; }
    }
    .sig-modal-card::before { display: none; }
    .sig-canvas { height: 240px; }
}

/* ========== MOBILE RESPONSIVE OVERRIDES ========== */
@media (max-width: 480px) {
    .login-card {
        border-radius: 20px;
        padding: 32px 20px 28px;
    }

    .register-card {
        border-radius: 20px;
        padding: 28px 18px 24px;
    }

    .app-title { font-size: 1.5rem; }
    .app-subtitle { font-size: 0.85rem; margin-bottom: 22px; }

    .numpad {
        gap: 10px;
        max-width: 300px;
    }

    .num-btn {
        height: 68px;
        font-size: 1.45rem;
        border-radius: 14px;
    }

    .pin-dot { width: 18px; height: 18px; }
    .pin-dots { gap: 14px; }

    .register-role-selector { gap: 8px; }
    .register-role-card { padding: 14px 10px; min-height: 72px; font-size: 0.85rem; }

    .employee-preview { grid-template-columns: 1fr; gap: 8px; }

    .lookup-btn { padding: 0 14px; font-size: 0.85rem; }
}

/* Extra-small: 320px wide (older iPhones) */
@media (max-width: 360px) {
    .login-card, .register-card { padding: 24px 16px 22px; }
    .numpad { max-width: 280px; gap: 8px; }
    .num-btn { height: 62px; font-size: 1.35rem; border-radius: 12px; }
    .pin-dot { width: 16px; height: 16px; }
    .pin-dots { gap: 12px; }
}

/* Short screens (landscape mode) */
@media (max-height: 500px) {
    .app-logo { margin-bottom: 8px; }
    .logo-mark { width: 52px; height: 52px; }
    .app-title { font-size: 1.3rem; }
    .app-subtitle { display: none; }
    .pin-dots { margin-bottom: 16px; }
    .numpad { gap: 8px; }
    .num-btn { height: 54px; font-size: 1.3rem; }
    .login-card { padding: 20px 20px 16px; }
    .page-link { margin-top: 14px; }
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
    .card-enter, .app-logo, .logo-mark, .bg-orb, .num-btn, .pin-dot.pop, .sig-modal-card {
        animation: none !important;
        transition: none !important;
    }
    .card-enter { opacity: 1; transform: none; }
    .sig-modal-card { transform: none; }
}

/* ========== DEPARTMENT SELECT ========== */
.register-dept-section {
    text-align: left;
    margin-bottom: 14px;
    display: none;
}
.register-dept-section.show { display: block; }

.register-dept-label {
    display: flex; align-items: center; gap: 7px;
    font-size: 0.875rem; color: var(--text-muted); font-weight: 600; margin-bottom: 8px;
}
.register-dept-label i { color: var(--primary); }

.dept-select-wrap {
    position: relative;
}

.dept-select-wrap::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 0; height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-muted);
    pointer-events: none;
    transition: transform 0.2s;
}

.form-select {
    width: 100%;
    padding: 14px 40px 14px 14px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    font-size: 16px; /* ≥16px — prevent iOS zoom */
    font-family: inherit;
    color: var(--text-main);
    background: rgba(30, 41, 59, 0.7);
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    min-height: 48px;
    touch-action: manipulation;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    line-height: 1.4;
}

.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14), 0 4px 12px rgba(56, 189, 248, 0.08);
}

.form-select option {
    background: #1e293b;
    color: var(--text-main);
    padding: 8px;
}

.form-select option:disabled {
    color: var(--text-muted);
}

/* Highlight selected state */
.form-select.has-value {
    border-color: rgba(56, 189, 248, 0.3);
    background: rgba(56, 189, 248, 0.04);
}

/* Department badge shown in preview after selection */
.dept-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 5px 12px;
    border-radius: 20px;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.25);
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 600;
    animation: fadeInUp 0.3s ease;
}
.dept-badge i { font-size: 0.85rem; }

