<?php
    /*-------------------------
    Autor: Autor Dev
    Web: www.google.com
    E-Mail: waptoing7@gmail.com
    ---------------------------*/
    // session_start();
    include "admin/config/config.php";
    if (isset($_SESSION['user_id']) AND $_SESSION['user_id'] != 0) {
        header("location: ?view=tickets");
        // header("location: tickets.php");
        exit;
    }else if(isset($_SESSION['admin_id']) AND $_SESSION['admin_id'] != 0){
        // header("location: admin/dashboard.php");
        header("location: admin/?view=dashboard");
    }
    $config = mysqli_query($con, "select * from configuration where name='website' ");
    $row01=mysqli_fetch_array($config);
    $website=$row01['val'];

    $fav = mysqli_query($con, "select * from configuration where name='favicon' ");
    $row02=mysqli_fetch_array($fav);
    $favicon=$row02['val'];

?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo $website ?> | Iniciar Sesión</title>
    <!-- favicon -->
    <link rel="shortcut icon" href="admin/images/<?php echo $favicon ?>" />
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="admin/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="admin/bootstrap/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="admin/dist/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="admin/plugins/iCheck/square/blue.css">

    <style>
        @import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

        body.login-page {
            font-family: 'Outfit', sans-serif !important;
            background-color: #0b1329 !important;
            display: flex !important;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
            padding: 0;
            position: relative;
        }
        
        /* Backdrop overlay for readability */
        body.login-page::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(15, 23, 42, 0.6) !important; /* Translucent elegant overlay */
            backdrop-filter: blur(8px) !important; /* Soft blur to clear visual noise */
            -webkit-backdrop-filter: blur(8px) !important;
            z-index: 0;
        }

        .login-box {
            width: 100%;
            max-width: 440px;
            margin: 0 !important;
            padding: 20px;
            position: relative;
            z-index: 10;
        }

        .login-box-body {
            background: rgba(255, 255, 255, 0.96) !important;
            border-radius: 20px !important;
            border: 1px solid rgba(255, 255, 255, 0.8) !important;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35) !important;
            padding: 40px 35px 35px 35px !important;
            color: #334155 !important;
            transition: all 0.3s ease;
        }

        .login-logo-container {
            text-align: center;
            margin-bottom: 25px;
            margin-top: -20px;
        }

        .login-logo-container img {
            max-height: 110px;
            width: auto;
            object-fit: contain;
            filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.03));
            transition: transform 0.3s ease;
        }

        .login-logo-container img:hover {
            transform: scale(1.02);
        }

        .login-header {
            text-align: center;
            margin-bottom: 25px;
        }

        .login-header-icon {
            width: 48px;
            height: 48px;
            background: rgba(2, 82, 197, 0.1);
            color: #0252c5;
            border-radius: 12px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            margin-bottom: 12px;
        }

        .login-header h2 {
            font-family: 'Outfit', sans-serif !important;
            font-size: 22px;
            font-weight: 700;
            color: #0f172a;
            margin: 0 0 6px 0;
            letter-spacing: -0.5px;
        }

        .login-header p {
            font-family: 'Outfit', sans-serif !important;
            font-size: 14px;
            color: #64748b;
            margin: 0;
        }

        .form-group {
            margin-bottom: 20px !important;
        }

        .form-control {
            font-family: 'Outfit', sans-serif !important;
            height: 48px !important;
            border-radius: 10px !important;
            border: 1.5px solid #cbd5e1 !important;
            background-color: #f8fafc !important;
            box-shadow: none !important;
            padding-left: 16px !important;
            padding-right: 40px !important;
            font-size: 15px !important;
            color: #1e293b !important;
            transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
        }

        .form-control:focus {
            border-color: #0252c5 !important;
            background-color: #ffffff !important;
            box-shadow: 0 0 0 4px rgba(2, 82, 197, 0.15) !important;
            outline: none !important;
        }

        .form-control::placeholder {
            color: #94a3b8 !important;
            opacity: 1 !important;
        }

        .has-feedback .form-control-feedback {
            line-height: 48px !important;
            height: 48px !important;
            color: #94a3b8 !important;
            right: 12px !important;
            font-size: 16px !important;
            transition: color 0.25s ease !important;
            pointer-events: none;
        }

        .form-control:focus ~ .form-control-feedback {
            color: #0252c5 !important;
        }

        /* Dropdown Styling */
        select.form-control {
            appearance: none !important;
            -webkit-appearance: none !important;
            -moz-appearance: none !important;
            background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E") !important;
            background-repeat: no-repeat !important;
            background-position: right 14px center !important;
            background-size: 18px !important;
            padding-right: 40px !important;
            cursor: pointer;
        }

        select.form-control:focus {
            background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%230252c5' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E") !important;
        }

        /* Checkbox customization */
        .checkbox.icheck {
            margin-top: 5px !important;
            margin-bottom: 20px !important;
            padding-left: 0 !important;
        }

        .checkbox.icheck label {
            font-family: 'Outfit', sans-serif !important;
            font-size: 14px !important;
            color: #475569 !important;
            font-weight: 500 !important;
            display: inline-flex !important;
            align-items: center !important;
            gap: 8px !important;
            cursor: pointer !important;
            padding-left: 0 !important;
            user-select: none;
        }

        .checkbox.icheck label div.icheckbox_square-blue {
            margin: 0 !important;
            float: none !important;
        }

        /* Links styling */
        .login-links-container {
            display: flex !important;
            justify-content: space-between !important;
            align-items: center !important;
            margin-top: 5px !important;
            margin-bottom: 25px !important;
            font-size: 14px !important;
        }

        .login-links-container a {
            font-family: 'Outfit', sans-serif !important;
            color: #64748b !important;
            font-weight: 500 !important;
            text-decoration: none !important;
            transition: all 0.2s ease !important;
            position: relative !important;
            padding: 2px 0 !important;
        }

        .login-links-container a::after {
            content: '' !important;
            position: absolute !important;
            width: 100% !important;
            transform: scaleX(0) !important;
            height: 1.5px !important;
            bottom: 0 !important;
            left: 0 !important;
            background-color: #0252c5 !important;
            transform-origin: bottom right !important;
            transition: transform 0.25s ease-out !important;
        }

        .login-links-container a:hover {
            color: #0252c5 !important;
        }

        .login-links-container a:hover::after {
            transform: scaleX(1) !important;
            transform-origin: bottom left !important;
        }

        /* Button Styling */
        .btn-login {
            font-family: 'Outfit', sans-serif !important;
            width: 100% !important;
            height: 48px !important;
            background: linear-gradient(135deg, #0252c5 0%, #013580 100%) !important;
            color: #ffffff !important;
            border: none !important;
            border-radius: 10px !important;
            font-size: 16px !important;
            font-weight: 600 !important;
            letter-spacing: 0.5px !important;
            cursor: pointer !important;
            box-shadow: 0 4px 12px rgba(2, 82, 197, 0.3) !important;
            transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
            gap: 8px !important;
        }

        .btn-login:hover {
            background: linear-gradient(135deg, #0261e8 0%, #0247ad 100%) !important;
            box-shadow: 0 6px 20px rgba(2, 82, 197, 0.45) !important;
            transform: translateY(-1px) !important;
        }

        .btn-login:active {
            transform: translateY(1px) scale(0.98) !important;
            box-shadow: 0 2px 8px rgba(2, 82, 197, 0.2) !important;
        }

        .btn-login:focus {
            outline: none !important;
            box-shadow: 0 0 0 4px rgba(2, 82, 197, 0.35) !important;
        }

        /* Alert Styling */
        .alert {
            border-radius: 10px !important;
            border: none !important;
            padding: 15px 20px !important;
            font-size: 14px !important;
            margin-bottom: 20px !important;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
        }

        .alert-danger {
            background-color: #fef2f2 !important;
            color: #991b1b !important;
            border-left: 4px solid #ef4444 !important;
        }

        .alert-danger .close {
            color: #991b1b !important;
            opacity: 0.5 !important;
        }

        .alert-danger .close:hover {
            opacity: 1 !important;
        }
    </style>
</head>
<body style="background: url('images/fondoserin.jpeg');
    background-position: center center;
    background-size: cover;" class="hold-transition login-page">
<div class="login-box">
    <div class="login-box-body">
        <div class="login-logo-container">
            <img src="assets/img/serintsa.png" alt="Logo">
            <b style="display: none;"><?php echo $website ?></b>
        </div>
        <?php if(isset($_SESSION['data'])){ ?>
            <div class="alert alert-<?php echo $_SESSION['data']['alert']; ?> fade in">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong><?php echo $_SESSION['data']['notice']; ?></strong> 
                <br><?php echo $_SESSION['data']['msg']; ?>
            </div>
        <?php 
                unset($_SESSION['data']);//elimino la variable de sesion
            } 
        ?>            
        <div class="login-header">
            <div class="login-header-icon">
                <i class="fa fa-laptop"></i>
            </div>
            <h2>Sistema de Tickets</h2>
            <p>Ingresa tus datos para iniciar sesión</p>
        </div>
        <form action="action/login.php" method="post">
            <div class="form-group has-feedback">
                <select class="form-control" autofocus name="type_session" id="type_session" required>
                    <option value="1">Empleado</option>
                    <option value="2">Administrador/Agente</option>
                </select>
            </div>

            <div id="otro">
                <div class="form-group has-feedback">
                    <input type="text" class="form-control" autofocus name="email" id="email" placeholder="Correo Electrónico" />
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" name="password" id="password" placeholder="Contraseña" />
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
            </div>
            
            <div id="cliente">
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" name="rfc" id="rfc" placeholder="CODIGO_EMPLEADO" />
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
            </div>

            <div class="checkbox icheck">
                <label>
                    <input name="session" type="checkbox"> Mantener sesión
                </label>
            </div>

            <div class="login-links-container">
                <a href="./?view=register" class="login-link-register">Registrarte</a>
                <a href="?view=reset_password" class="login-link-forgot">¿Olvidaste tu contraseña?</a>
            </div>

            <button type="submit" name="token" value="Iniciar Sesión" class="btn-login">
                Iniciar Sesión <i class="fa fa-sign-in"></i>
            </button>
        </form>
        
    </div><!-- /.login-box-body -->
</div><!-- /.login-box -->

<!-- jQuery 2.2.3 -->
<script src="admin/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="admin/bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="admin/plugins/iCheck/icheck.min.js"></script>
<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });


        $("#cliente").show();
        $("#otro").hide();

        $("#type_session").change(function(){
            // alert($(this).val())
            if($(this).val()==1){
                $("#cliente").show();
                $("#otro").hide();
            }else{
                $("#cliente").hide();
                $("#otro").show();
            }
        })
    });
</script>
</body>
</html>
