<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<style>
.detail-grid { display:grid; grid-template-columns:1fr 1fr; gap:0; }
.detail-item { padding:10px 16px; border-bottom:1px solid #f0f2f5; }
.detail-item.full { grid-column:1/-1; }
.detail-item .dl { font-size:10px; font-weight:700; color:#aaa; text-transform:uppercase; letter-spacing:.5px; display:block; margin-bottom:3px; }
.detail-item .dv { font-size:13px; color:#222; }
.contact-avatar-lg {
    width:72px; height:72px; border-radius:50%;
    background:linear-gradient(135deg,#4a9fd4,#1e3a5f);
    display:flex; align-items:center; justify-content:center;
    font-size:26px; font-weight:700; color:#fff; margin:0 auto 12px;
}
@media(max-width:767px){ .detail-grid{grid-template-columns:1fr} .detail-item.full{grid-column:1} .col-md-8,.col-md-4{width:100%!important;float:none!important} }
</style>

<section class="content-header">
    <h1><i class="fa fa-address-book-o"></i> <?php echo lang('contact') ?> <small><?php echo lang('view') ?></small></h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo site_url('admin') ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li><a href="<?php echo site_url('admin/contacts') ?>"><?php echo lang('contacts') ?></a></li>
        <li class="active"><?php echo lang('view') ?></li>
    </ol>
</section>

<section class="content">
<div class="row">

<div class="col-md-8">
    <div class="box box-primary">
        <div class="box-header with-border" style="background:linear-gradient(135deg,#1e3a5f,#2e75b6);border-radius:10px 10px 0 0">
            <h3 class="box-title" style="color:#fff"><i class="fa fa-user"></i> <?php echo htmlspecialchars($contact->name ?? '') ?></h3>
            <div class="box-tools pull-right">
                <?php if(check_user_role(23)==1): ?>
                <a href="<?php echo site_url('admin/contacts/edit/'.$contact->id) ?>" class="btn btn-xs" style="background:rgba(255,255,255,.2);color:#fff">
                    <i class="fa fa-pencil"></i> Editar
                </a>
                <?php endif; ?>
            </div>
        </div>
        <div class="box-body no-padding">
            <div class="detail-grid">
                <div class="detail-item">
                    <span class="dl">Nome</span>
                    <span class="dv"><strong><?php echo htmlspecialchars($contact->name ?? '—') ?></strong></span>
                </div>
                <div class="detail-item">
                    <span class="dl">Telefone</span>
                    <span class="dv">
                        <?php if(!empty($contact->contact)): ?>
                        <a href="tel:<?php echo $contact->contact ?>"><i class="fa fa-phone text-muted" style="margin-right:5px"></i><?php echo htmlspecialchars($contact->contact) ?></a>
                        <?php else: ?>—<?php endif; ?>
                    </span>
                </div>
                <div class="detail-item">
                    <span class="dl">E-mail</span>
                    <span class="dv">
                        <?php if(!empty($contact->email)): ?>
                        <a href="mailto:<?php echo $contact->email ?>"><i class="fa fa-envelope-o text-muted" style="margin-right:5px"></i><?php echo htmlspecialchars($contact->email) ?></a>
                        <?php else: ?>—<?php endif; ?>
                    </span>
                </div>
                <div class="detail-item">
                    <span class="dl">Empresa / Organização</span>
                    <span class="dv"><?php echo htmlspecialchars($contact->company ?? '—') ?></span>
                </div>
                <div class="detail-item full">
                    <span class="dl">Endereço</span>
                    <span class="dv"><?php echo htmlspecialchars($contact->address ?? '—') ?></span>
                </div>
                <?php if(!empty($contact->description)): ?>
                <div class="detail-item full">
                    <span class="dl">Observações</span>
                    <span class="dv" style="white-space:pre-wrap"><?php echo htmlspecialchars($contact->description) ?></span>
                </div>
                <?php endif; ?>
            </div>
        </div>
        <div class="box-footer">
            <a href="<?php echo site_url('admin/contacts') ?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> Voltar</a>
            <?php if(check_user_role(23)==1): ?>
            <a href="<?php echo site_url('admin/contacts/edit/'.$contact->id) ?>" class="btn btn-warning btn-sm"><i class="fa fa-pencil"></i> Editar</a>
            <?php endif; ?>
        </div>
    </div>
</div>

<div class="col-md-4">
    <div class="box" style="border-top:3px solid #1e3a5f">
        <div class="box-body" style="text-align:center;padding:20px">
            <?php
            $parts = explode(' ', trim($contact->name ?? ''));
            $ini = strtoupper(substr($parts[0],0,1).(isset($parts[1])?substr($parts[1],0,1):''));
            ?>
            <div class="contact-avatar-lg"><?php echo $ini ?></div>
            <h4 style="margin:0 0 4px;font-weight:700"><?php echo htmlspecialchars($contact->name ?? '') ?></h4>
            <?php if(!empty($contact->company)): ?>
            <small class="text-muted"><?php echo htmlspecialchars($contact->company) ?></small>
            <?php endif; ?>
        </div>
    </div>
    <div class="box" style="border-top:3px solid #2e7d32">
        <div class="box-header with-border"><h3 class="box-title"><i class="fa fa-bolt"></i> Ações Rápidas</h3></div>
        <div class="box-body" style="padding:10px">
            <?php if(!empty($contact->email)): ?>
            <a href="mailto:<?php echo $contact->email ?>" class="btn btn-info btn-block btn-sm" style="margin-bottom:6px">
                <i class="fa fa-envelope"></i> Enviar E-mail
            </a>
            <?php endif; ?>
            <?php if(!empty($contact->contact)): ?>
            <a href="tel:<?php echo $contact->contact ?>" class="btn btn-success btn-block btn-sm" style="margin-bottom:6px">
                <i class="fa fa-phone"></i> Ligar
            </a>
            <?php endif; ?>
            <?php if(check_user_role(23)==1): ?>
            <a href="<?php echo site_url('admin/contacts/edit/'.$contact->id) ?>" class="btn btn-warning btn-block btn-sm">
                <i class="fa fa-pencil"></i> Editar Contato
            </a>
            <?php endif; ?>
        </div>
    </div>
</div>

</div>
</section>
