<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Breno Paiva Advocacia — Login</title>
    <link rel="stylesheet" href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css')?>">
    <link rel="stylesheet" href="<?php echo base_url('assets/css/font-awesome.min.css')?>">
    <?php if(!empty($turnstile_key)): ?>
    <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
    <?php endif; ?>
    <style>
        *{box-sizing:border-box;}
        body{
            background:linear-gradient(135deg,#1a1a2e 0%,#16213e 50%,#0f3460 100%);
            min-height:100vh;
            display:flex;
            align-items:center;
            justify-content:center;
            font-family:'Segoe UI',Arial,sans-serif;
            margin:0;
            padding:20px;
        }
        .login-wrapper{width:100%;max-width:400px;}
        .login-card{background:#fff;border-radius:16px;box-shadow:0 25px 60px rgba(0,0,0,.5);overflow:hidden;}
        .login-header{
            background:linear-gradient(135deg,#1a1a2e,#0f3460);
            padding:40px 30px 30px;
            text-align:center;
        }
        .login-header img{max-height:80px;max-width:260px;object-fit:contain;}
        .login-header .system-name{
            color:rgba(255,255,255,.7);
            font-size:12px;
            letter-spacing:2px;
            text-transform:uppercase;
            margin-top:12px;
            display:block;
        }
        .login-body{padding:35px 35px 25px;}
        .form-group{margin-bottom:20px;}
        .form-group label{
            display:block;
            font-weight:600;
            color:#444;
            font-size:13px;
            margin-bottom:7px;
            letter-spacing:.3px;
        }
        .input-group{display:flex;border-radius:8px;overflow:hidden;border:1.5px solid #dee2e6;transition:border-color .2s;}
        .input-group:focus-within{border-color:#0f3460;box-shadow:0 0 0 3px rgba(15,52,96,.12);}
        .input-group-addon{
            background:#f8f9fa;
            border:none;
            padding:0 14px;
            display:flex;
            align-items:center;
            color:#6c757d;
            font-size:15px;
            border-right:1.5px solid #dee2e6;
            min-width:44px;
            justify-content:center;
        }
        .form-control{
            border:none;
            height:46px;
            font-size:14px;
            padding:0 14px;
            flex:1;
            outline:none;
            background:#fff;
            color:#333;
        }
        .form-control::placeholder{color:#bbb;}
        .pass-wrapper{position:relative;display:flex;border-radius:8px;overflow:hidden;border:1.5px solid #dee2e6;transition:border-color .2s;}
        .pass-wrapper:focus-within{border-color:#0f3460;box-shadow:0 0 0 3px rgba(15,52,96,.12);}
        .pass-wrapper .form-control{border:none;background:#fff;}
        .toggle-pass{
            background:#f8f9fa;
            border:none;
            border-left:1.5px solid #dee2e6;
            padding:0 14px;
            cursor:pointer;
            color:#999;
            display:flex;
            align-items:center;
            transition:color .2s;
        }
        .toggle-pass:hover{color:#0f3460;}
        .btn-login{
            width:100%;
            height:48px;
            background:linear-gradient(135deg,#1a1a2e,#0f3460);
            border:none;
            color:#fff;
            font-size:15px;
            font-weight:600;
            border-radius:8px;
            letter-spacing:.5px;
            cursor:pointer;
            transition:all .3s;
            margin-top:8px;
        }
        .btn-login:hover{
            background:linear-gradient(135deg,#0f3460,#e94560);
            transform:translateY(-1px);
            box-shadow:0 6px 20px rgba(0,0,0,.3);
        }
        .btn-login:active{transform:translateY(0);}
        .alert{border-radius:8px;font-size:13px;padding:12px 15px;margin-bottom:16px;border:none;}
        .alert-danger{background:#fff0f0;color:#c00;border-left:4px solid #c00;}
        .alert-success{background:#f0fff4;color:#1D6B3B;border-left:4px solid #1D6B3B;}
        .forgot-link{text-align:center;margin-top:18px;}
        .forgot-link a{color:#0f3460;font-size:13px;text-decoration:none;opacity:.8;}
        .forgot-link a:hover{opacity:1;text-decoration:underline;}
        .security-badge{
            display:flex;
            align-items:center;
            justify-content:center;
            gap:6px;
            font-size:11px;
            color:#aaa;
            margin-top:14px;
        }
        .cf-turnstile{display:flex;justify-content:center;margin:16px 0 8px;}
        .login-footer{
            background:#f8f9fa;
            padding:14px;
            text-align:center;
            font-size:11px;
            color:#bbb;
            border-top:1px solid #f0f0f0;
        }
    </style>
</head>
<body>
<div class="login-wrapper">
    <div class="login-card">
        <div class="login-header">
            <?php
            $this->load->model('setting_model');
            $s = $this->setting_model->get_setting();
            if(!empty($s->image)):
            ?>
            <img src="<?php echo base_url('assets/uploads/images/Nova logo Breno Paiva Adv site.jpg')?>"
     alt="<?php echo htmlspecialchars($s->name??'Breno Paiva Advocacia')?>"
     style="max-width: 180px; height: auto; display: block; margin: 0 auto 10px auto;"
     onerror="this.style.display='none';document.getElementById('firm-name').style.display='block'">
            <?php else: ?>
            <span style="color:#fff;font-size:22px;font-weight:700"><?php echo htmlspecialchars($s->name??'Breno Paiva Advocacia')?></span>
            <?php endif; ?>
            <span id="firm-name" style="display:none;color:#fff;font-size:20px;font-weight:700"><?php echo htmlspecialchars($s->name??'Breno Paiva Advocacia')?></span>
            <span style="color: #FFFFFF; font-weight: bold;"><i class="fa fa-gavel"></i> Sistema de Gestão Jurídica </span> <br></br>
            <span style="color: #FFFFFF;"><class="fa fa-gavel"> Painel Administrativo </span>
        </div>

        <div class="login-body">
            <?php if(!empty($error)): ?>
            <div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> <?php echo $error?></div>
            <?php endif; ?>
            <?php if($this->session->flashdata('message')): ?>
            <div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $this->session->flashdata('message')?></div>
            <?php endif; ?>

            <form method="post" action="<?php echo site_url('admin/login')?>">
                <div class="form-group">
                    <label><i class="fa fa-user" style="color:#0f3460;margin-right:5px"></i> Usuário</label>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-user"></i></span>
                        <input type="text" name="username" class="form-control"
                               placeholder="Digite seu usuário"
                               value="<?php echo set_value('username')?>"
                               autocomplete="username" required>
                    </div>
                </div>

                <div class="form-group">
                    <label><i class="fa fa-lock" style="color:#0f3460;margin-right:5px"></i> Senha</label>
                    <div class="pass-wrapper">
                        <input type="password" name="password" id="inp-pass" class="form-control"
                               placeholder="Digite sua senha"
                               autocomplete="current-password" required>
                        <button type="button" class="toggle-pass" onclick="togglePass()" title="Mostrar/ocultar senha">
                            <i class="fa fa-eye" id="eye-icon"></i>
                        </button>
                    </div>
                </div>

                <?php if(!empty($turnstile_key)): ?>
                <div class="cf-turnstile" data-sitekey="<?php echo htmlspecialchars($turnstile_key)?>"></div>
                <?php endif; ?>

                <input type="hidden" name="submitted" value="1">
                <button type="submit" class="btn-login">
                    <i class="fa fa-sign-in"></i>&nbsp; Entrar no Sistema
                </button>
            </form>

            <div class="forgot-link">
                <a href="<?php echo site_url('forgot/forgot_password')?>">
                    <i class="fa fa-key"></i> Esqueci minha senha
                </a>
            </div>

            <div class="security-badge">
                <i class="fa fa-shield" style="color:#28a745"></i>
                <span>Conexão segura &middot; Bloqueio após <?php echo $max_attempts??5?> tentativas</span>
            </div>
        </div>

        <div class="login-footer">
            Breno Paiva Advocacia - Gerência de Tecnologia da Informação
        </div>
    </div>
</div>

<script>
function togglePass() {
    var inp = document.getElementById('inp-pass');
    var ico = document.getElementById('eye-icon');
    if(inp.type==='password'){
        inp.type='text';
        ico.className='fa fa-eye-slash';
    } else {
        inp.type='password';
        ico.className='fa fa-eye';
    }
}
</script>
</body>
</html>
