<?php
if (!function_exists('h')) { function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } }

if (!isset($conn) || !($conn instanceof mysqli)) { @include_once __DIR__ . '/../config.php'; }
@mysqli_set_charset($conn, 'utf8mb4');
@mysqli_query($conn, "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci'");
@mysqli_query($conn, "SET collation_connection='utf8mb4_general_ci'");

if (!isset($fetch1) || !is_array($fetch1) || empty($fetch1)) {
    @session_start();
    $uid = $_SESSION['user_id1'] ?? null;
    if ($uid) {
        $sqlBal = "SELECT * FROM hr_dump WHERE empid='".mysqli_real_escape_string($conn,(string)$uid)."' LIMIT 1";
        if ($rBal = mysqli_query($conn, $sqlBal)) { $fetch1 = mysqli_fetch_array($rBal, MYSQLI_ASSOC); }
    }
}

$emp_name  = $fetch1['Employee_Full_Name'] ?? 'User';
$team_name = $fetch1['Team_Name'] ?? '';
$empid     = $fetch1['empid'] ?? ($fetch1['Employee_Number'] ?? '');
$today     = date("Y-m-d", time());

$weekoff_text = 'NA';
$__db = (isset($connwo) && $connwo instanceof mysqli) ? $connwo : $conn;
if ($__db instanceof mysqli && $empid !== '') {
    $sqlWO = "SELECT WeekOff FROM emp_weekoff WHERE empid='".mysqli_real_escape_string($__db,(string)$empid)."' LIMIT 1";
    if ($rWO = mysqli_query($__db, $sqlWO)) {
        if ($rowWO = mysqli_fetch_assoc($rWO)) {
            if (!empty($rowWO['WeekOff'])) $weekoff_text = $rowWO['WeekOff'];
        }
    }
}

$logo_src = '../assets/img/logo.png';
?>
<style>
/* ===== Profile Header (full width & padded) ===== */
.balance{ margin:0 0 14px; }
.profile-header{
    display:flex; align-items:center; justify-content:space-between;
    gap:14px; flex-wrap:nowrap;
    background:#fff;
    border:1px solid #eef2ff;
    border-radius:16px;
    padding:16px 14px;          /* more top padding */
    box-shadow: 0 8px 20px rgba(2,6,23,.06);
    width:100%;                 /* stretch full width */
}
.profile-info{ flex:1 1 auto; min-width:0; }
.profile-info .title{
    display:block; margin:0 0 4px;
    font-size:15px; font-weight:800; color:#0f172a;
    line-height:1.35; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.profile-info .meta{
    margin:0; font-size:13px; color:#475569; line-height:1.4;
}
.profile-logo{
    flex:0 0 auto; max-width:80px; height:auto; border-radius:10px; display:block;
}
@media (max-width: 420px){
    .profile-logo{ max-width:62px; }
    .profile-info .title{ font-size:14px; }
    .profile-info .meta{ font-size:12px; }
}
</style>

<div class="balance">
    <div class="profile-header">
        <div class="profile-info">
            <span class="title" title="<?php echo h($emp_name); ?>"><?php echo h($emp_name); ?></span>
            <p class="meta">
                <?php if($team_name!==''){ echo h($team_name).' '; } ?>(<?php echo h($empid); ?>)<br>
                <?php echo h($today); ?><br>
                Weekoff - <?php echo h($weekoff_text); ?>
            </p>
        </div>
        <a href="#"><img src="<?php echo h($logo_src); ?>" alt="logo" class="profile-logo"></a>
    </div>
</div>
