<?php
/**
 * Neighbor Confirmation Page
 * Allows neighbors to confirm boundaries with ID verification
 */

define('APP_RUNNING', true);
require_once 'db_connect.php';

$message = '';
$error = '';
$neighbor = null;
$land = null;

// Get confirmation code from URL or form
$code = isset($_GET['code']) ? trim($_GET['code']) : (isset($_POST['code']) ? trim($_POST['code']) : '');

if(!empty($code)) {
    $code = mysqli_real_escape_string($conn, strtoupper($code));

    // Find the neighbor record
    $result = mysqli_query($conn, "
        SELECT ln.*, l.land_name, l.id as land_id,
               u.full_name as owner_name, u.phone as owner_phone,
               v.name as village_name
        FROM land_neighbors ln
        JOIN lands l ON ln.land_id = l.id
        JOIN users u ON l.user_id = u.id
        LEFT JOIN villages v ON l.village_id = v.id
        WHERE ln.confirmation_code = '$code'
    ");

    if($result && mysqli_num_rows($result) > 0) {
        $neighbor = mysqli_fetch_assoc($result);
        $land = [
            'id' => $neighbor['land_id'],
            'land_name' => $neighbor['land_name'],
            'owner_name' => $neighbor['owner_name'],
            'village_name' => $neighbor['village_name']
        ];
    } else {
        $error = 'Invalid confirmation code. Please check and try again.';
    }
}

// Handle confirmation submission
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action'])) {
    $action = $_POST['action'];
    $neighbor_id = intval($_POST['neighbor_id'] ?? 0);

    if($neighbor_id > 0 && $neighbor) {
        // Verify the neighbor_id matches
        if($neighbor['id'] != $neighbor_id) {
            $error = 'Invalid request.';
        } else {
            $uploadDir = 'uploads/neighbor_docs/';
            if(!is_dir($uploadDir)) {
                mkdir($uploadDir, 0755, true);
            }

            $nationalId = mysqli_real_escape_string($conn, trim($_POST['national_id'] ?? ''));
            $idType = mysqli_real_escape_string($conn, $_POST['id_type'] ?? 'national_id');
            $witnessName = mysqli_real_escape_string($conn, trim($_POST['witness_name'] ?? ''));
            $witnessPhone = mysqli_real_escape_string($conn, trim($_POST['witness_phone'] ?? ''));
            $witnessNationalId = mysqli_real_escape_string($conn, trim($_POST['witness_national_id'] ?? ''));

            // Handle file uploads
            $idDocumentPath = null;
            $confirmationDocPath = null;

            // Upload ID document
            if(isset($_FILES['id_document']) && $_FILES['id_document']['error'] == 0) {
                $allowedTypes = ['image/jpeg', 'image/png', 'image/jpg', 'application/pdf'];
                if(in_array($_FILES['id_document']['type'], $allowedTypes)) {
                    $ext = pathinfo($_FILES['id_document']['name'], PATHINFO_EXTENSION);
                    $filename = 'id_' . $neighbor_id . '_' . time() . '.' . $ext;
                    if(move_uploaded_file($_FILES['id_document']['tmp_name'], $uploadDir . $filename)) {
                        $idDocumentPath = $uploadDir . $filename;
                    }
                }
            }

            // Upload confirmation document/photo
            if(isset($_FILES['confirmation_doc']) && $_FILES['confirmation_doc']['error'] == 0) {
                $allowedTypes = ['image/jpeg', 'image/png', 'image/jpg', 'application/pdf'];
                if(in_array($_FILES['confirmation_doc']['type'], $allowedTypes)) {
                    $ext = pathinfo($_FILES['confirmation_doc']['name'], PATHINFO_EXTENSION);
                    $filename = 'confirm_' . $neighbor_id . '_' . time() . '.' . $ext;
                    if(move_uploaded_file($_FILES['confirmation_doc']['tmp_name'], $uploadDir . $filename)) {
                        $confirmationDocPath = $uploadDir . $filename;
                    }
                }
            }

            if($action == 'confirm') {
                // Confirm the boundary
                $idDocSql = $idDocumentPath ? "'$idDocumentPath'" : "NULL";
                $confirmDocSql = $confirmationDocPath ? "'$confirmationDocPath'" : "NULL";

                $sql = "UPDATE land_neighbors SET
                    confirmation_status = 'confirmed',
                    confirmed_at = NOW(),
                    confirmation_method = 'app',
                    neighbor_national_id = '$nationalId',
                    neighbor_id_type = '$idType',
                    neighbor_id_document = $idDocSql,
                    confirmation_document = $confirmDocSql,
                    witness_name = '$witnessName',
                    witness_phone = '$witnessPhone',
                    witness_national_id = '$witnessNationalId'
                    WHERE id = $neighbor_id";

                if(mysqli_query($conn, $sql)) {
                    // Update land's neighbor verification count
                    $landId = $neighbor['land_id'];
                    mysqli_query($conn, "UPDATE lands SET neighbor_verification_count =
                        (SELECT COUNT(*) FROM land_neighbors WHERE land_id = $landId AND confirmation_status = 'confirmed')
                        WHERE id = $landId");

                    // Create notification for land owner
                    $ownerResult = mysqli_query($conn, "SELECT user_id FROM lands WHERE id = $landId");
                    $ownerId = mysqli_fetch_assoc($ownerResult)['user_id'];
                    $neighborName = $neighbor['neighbor_name'] ?: 'A neighbor';

                    mysqli_query($conn, "INSERT INTO cbc_notifications (user_id, notification_type, title, message, land_id, created_at)
                        VALUES ($ownerId, 'neighbor_confirmed', 'Neighbor Confirmed',
                        '$neighborName has confirmed the boundary for your land.', $landId, NOW())");

                    $message = 'Thank you! Boundary confirmed successfully. / Asante! Mpaka umethibitishwa.';
                    $neighbor['confirmation_status'] = 'confirmed';
                } else {
                    $error = 'Failed to save confirmation. Please try again.';
                }

            } elseif($action == 'dispute') {
                $disputeReason = mysqli_real_escape_string($conn, trim($_POST['dispute_reason'] ?? ''));
                $boundaryDescription = mysqli_real_escape_string($conn, trim($_POST['boundary_description'] ?? ''));

                $idDocSql = $idDocumentPath ? "'$idDocumentPath'" : "NULL";

                $sql = "UPDATE land_neighbors SET
                    confirmation_status = 'disputed',
                    confirmed_at = NOW(),
                    confirmation_method = 'app',
                    neighbor_national_id = '$nationalId',
                    neighbor_id_type = '$idType',
                    neighbor_id_document = $idDocSql,
                    dispute_reason = '$disputeReason',
                    dispute_boundary_description = '$boundaryDescription'
                    WHERE id = $neighbor_id";

                if(mysqli_query($conn, $sql)) {
                    // Create notification for land owner
                    $landId = $neighbor['land_id'];
                    $ownerResult = mysqli_query($conn, "SELECT user_id FROM lands WHERE id = $landId");
                    $ownerId = mysqli_fetch_assoc($ownerResult)['user_id'];
                    $neighborName = $neighbor['neighbor_name'] ?: 'A neighbor';

                    mysqli_query($conn, "INSERT INTO cbc_notifications (user_id, notification_type, title, message, land_id, created_at)
                        VALUES ($ownerId, 'neighbor_disputed', 'Boundary Disputed',
                        '$neighborName has disputed the boundary for your land.', $landId, NOW())");

                    // Also notify village officials
                    $villageId = $neighbor['village_id'] ?? null;
                    if($villageId) {
                        $officials = mysqli_query($conn, "SELECT id FROM users WHERE village_id = $villageId AND role IN ('village_chairman', 'land_officer')");
                        while($official = mysqli_fetch_assoc($officials)) {
                            mysqli_query($conn, "INSERT INTO cbc_notifications (user_id, notification_type, title, message, land_id, created_at)
                                VALUES ({$official['id']}, 'boundary_dispute', 'New Boundary Dispute',
                                'A neighbor has disputed boundary for land in your village.', $landId, NOW())");
                        }
                    }

                    $message = 'Your dispute has been recorded. Village officials will review. / Mgogoro wako umerekodiwa.';
                    $neighbor['confirmation_status'] = 'disputed';
                } else {
                    $error = 'Failed to save dispute. Please try again.';
                }
            }
        }
    }
}

$directionLabels = [
    'north' => 'Kaskazini / North',
    'south' => 'Kusini / South',
    'east' => 'Mashariki / East',
    'west' => 'Magharibi / West',
    'northeast' => 'Kaskazini-Mashariki',
    'northwest' => 'Kaskazini-Magharibi',
    'southeast' => 'Kusini-Mashariki',
    'southwest' => 'Kusini-Magharibi'
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Confirm Boundary / Thibitisha Mpaka - Land Secure</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="assets/font-awesome/css/all.min.css">
    <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="confirm-container">
        <div class="confirm-header">
            <div class="logo">
                <i class="fas fa-map-marked-alt"></i>
                <span>Land Secure CBC</span>
            </div>
            <h1><i class="fas fa-handshake"></i> Boundary Confirmation / Uthibitisho wa Mpaka</h1>
        </div>

        <?php if($message): ?>
        <div class="alert alert-success">
            <i class="fas fa-check-circle"></i> <?php echo $message; ?>
        </div>
        <?php endif; ?>

        <?php if($error): ?>
        <div class="alert alert-danger">
            <i class="fas fa-exclamation-circle"></i> <?php echo $error; ?>
        </div>
        <?php endif; ?>

        <?php if(!$neighbor && empty($error)): ?>
        <!-- Code Entry Form -->
        <div class="confirm-card">
            <div class="card-icon">
                <i class="fas fa-key"></i>
            </div>
            <h2>Enter Confirmation Code / Ingiza Nambari ya Uthibitisho</h2>
            <p>Enter the code you received to confirm your neighbor's land boundary.</p>

            <form method="GET" class="code-form">
                <div class="form-group">
                    <input type="text" name="code" class="form-control code-input"
                           placeholder="e.g., A1B2C3D4" maxlength="8" required
                           style="text-transform: uppercase;">
                </div>
                <button type="submit" class="btn-primary">
                    <i class="fas fa-search"></i> Find / Tafuta
                </button>
            </form>
        </div>

        <?php elseif($neighbor): ?>

        <?php if($neighbor['confirmation_status'] == 'pending'): ?>
        <!-- Confirmation Form -->
        <div class="confirm-card">
            <div class="land-info">
                <h3><i class="fas fa-map-marked-alt"></i> Land Details / Maelezo ya Ardhi</h3>
                <div class="info-grid">
                    <div class="info-item">
                        <label>Land Name / Jina:</label>
                        <span><?php echo htmlspecialchars($land['land_name']); ?></span>
                    </div>
                    <div class="info-item">
                        <label>Owner / Mmiliki:</label>
                        <span><?php echo htmlspecialchars($land['owner_name']); ?></span>
                    </div>
                    <div class="info-item">
                        <label>Village / Kijiji:</label>
                        <span><?php echo htmlspecialchars($land['village_name'] ?: 'Not specified'); ?></span>
                    </div>
                    <div class="info-item">
                        <label>Your Position / Upande Wako:</label>
                        <span class="direction-badge">
                            <?php echo $directionLabels[$neighbor['neighbor_direction']] ?? $neighbor['neighbor_direction']; ?>
                        </span>
                    </div>
                </div>
            </div>

            <!-- Tabs -->
            <div class="confirm-tabs">
                <button class="tab-btn active" onclick="showTab('confirm')">
                    <i class="fas fa-check-circle"></i> Confirm / Thibitisha
                </button>
                <button class="tab-btn" onclick="showTab('dispute')">
                    <i class="fas fa-exclamation-triangle"></i> Dispute / Pinga
                </button>
            </div>

            <!-- Confirm Tab -->
            <div id="confirmTab" class="tab-content active">
                <form method="POST" enctype="multipart/form-data">
                    <input type="hidden" name="action" value="confirm">
                    <input type="hidden" name="neighbor_id" value="<?php echo $neighbor['id']; ?>">
                    <input type="hidden" name="code" value="<?php echo htmlspecialchars($code); ?>">

                    <div class="section-title">
                        <i class="fas fa-id-card"></i> Your Identification / Kitambulisho Chako
                    </div>

                    <div class="form-row">
                        <div class="form-group">
                            <label>ID Type / Aina ya Kitambulisho <span class="required">*</span></label>
                            <select name="id_type" class="form-control" required>
                                <option value="national_id">National ID / NIDA</option>
                                <option value="voter_id">Voter ID / Kadi ya Mpiga Kura</option>
                                <option value="passport">Passport / Pasipoti</option>
                                <option value="driving_license">Driving License / Leseni</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>ID Number / Nambari <span class="required">*</span></label>
                            <input type="text" name="national_id" class="form-control" required
                                   placeholder="e.g., 19850101-12345-00001-23">
                        </div>
                    </div>

                    <div class="form-group">
                        <label>Upload ID Photo / Pakia Picha ya Kitambulisho <span class="required">*</span></label>
                        <div class="file-upload">
                            <input type="file" name="id_document" id="idDocument" accept="image/*,.pdf" required>
                            <label for="idDocument" class="file-label">
                                <i class="fas fa-cloud-upload-alt"></i>
                                <span>Click to upload ID photo</span>
                            </label>
                            <div id="idPreview" class="file-preview"></div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label>Upload Signed Confirmation / Pakia Uthibitisho <span class="text-muted">(Optional)</span></label>
                        <div class="file-upload">
                            <input type="file" name="confirmation_doc" id="confirmDoc" accept="image/*,.pdf">
                            <label for="confirmDoc" class="file-label">
                                <i class="fas fa-file-signature"></i>
                                <span>Upload signed form or photo at boundary</span>
                            </label>
                            <div id="confirmPreview" class="file-preview"></div>
                        </div>
                    </div>

                    <div class="section-title">
                        <i class="fas fa-user-friends"></i> Witness Information / Shahidi <span class="text-muted">(Optional)</span>
                    </div>

                    <div class="form-row">
                        <div class="form-group">
                            <label>Witness Name / Jina la Shahidi</label>
                            <input type="text" name="witness_name" class="form-control"
                                   placeholder="Full name">
                        </div>
                        <div class="form-group">
                            <label>Witness Phone / Simu ya Shahidi</label>
                            <input type="tel" name="witness_phone" class="form-control"
                                   placeholder="0712345678">
                        </div>
                    </div>

                    <div class="form-group">
                        <label>Witness ID Number / Nambari ya Shahidi</label>
                        <input type="text" name="witness_national_id" class="form-control"
                               placeholder="National ID number">
                    </div>

                    <div class="confirm-notice">
                        <i class="fas fa-info-circle"></i>
                        <p>By confirming, you agree that the boundary between your land and this land is correct as marked.</p>
                        <p>Kwa kuthibitisha, unakubali kuwa mpaka kati ya ardhi yako na ardhi hii ni sahihi kama ilivyowekwa.</p>
                    </div>

                    <button type="submit" class="btn-confirm">
                        <i class="fas fa-check"></i> Confirm Boundary / Thibitisha Mpaka
                    </button>
                </form>
            </div>

            <!-- Dispute Tab -->
            <div id="disputeTab" class="tab-content">
                <form method="POST" enctype="multipart/form-data">
                    <input type="hidden" name="action" value="dispute">
                    <input type="hidden" name="neighbor_id" value="<?php echo $neighbor['id']; ?>">
                    <input type="hidden" name="code" value="<?php echo htmlspecialchars($code); ?>">

                    <div class="section-title">
                        <i class="fas fa-id-card"></i> Your Identification / Kitambulisho Chako
                    </div>

                    <div class="form-row">
                        <div class="form-group">
                            <label>ID Type / Aina ya Kitambulisho <span class="required">*</span></label>
                            <select name="id_type" class="form-control" required>
                                <option value="national_id">National ID / NIDA</option>
                                <option value="voter_id">Voter ID / Kadi ya Mpiga Kura</option>
                                <option value="passport">Passport / Pasipoti</option>
                                <option value="driving_license">Driving License / Leseni</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>ID Number / Nambari <span class="required">*</span></label>
                            <input type="text" name="national_id" class="form-control" required
                                   placeholder="e.g., 19850101-12345-00001-23">
                        </div>
                    </div>

                    <div class="form-group">
                        <label>Upload ID Photo / Pakia Picha ya Kitambulisho <span class="required">*</span></label>
                        <div class="file-upload">
                            <input type="file" name="id_document" id="idDocument2" accept="image/*,.pdf" required>
                            <label for="idDocument2" class="file-label">
                                <i class="fas fa-cloud-upload-alt"></i>
                                <span>Click to upload ID photo</span>
                            </label>
                        </div>
                    </div>

                    <div class="section-title">
                        <i class="fas fa-exclamation-triangle"></i> Dispute Details / Maelezo ya Mgogoro
                    </div>

                    <div class="form-group">
                        <label>Reason for Dispute / Sababu ya Mgogoro <span class="required">*</span></label>
                        <select name="dispute_reason" class="form-control" required>
                            <option value="">Select reason...</option>
                            <option value="boundary_wrong">Boundary is wrong / Mpaka si sahihi</option>
                            <option value="land_overlap">Land overlaps my property / Ardhi inaingia kwangu</option>
                            <option value="not_neighbor">I am not a neighbor / Mimi si jirani</option>
                            <option value="ownership_dispute">Ownership dispute / Mgogoro wa umiliki</option>
                            <option value="other">Other / Nyingine</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label>Describe the Issue / Elezea Tatizo <span class="required">*</span></label>
                        <textarea name="boundary_description" class="form-control" rows="4" required
                                  placeholder="Explain the boundary issue in detail..."></textarea>
                    </div>

                    <div class="dispute-notice">
                        <i class="fas fa-gavel"></i>
                        <p>Disputes will be reviewed by village officials and may require a site visit.</p>
                        <p>Migogoro itapitiwa na viongozi wa kijiji na inaweza kuhitaji ziara ya eneo.</p>
                    </div>

                    <button type="submit" class="btn-dispute">
                        <i class="fas fa-exclamation-triangle"></i> Submit Dispute / Wasilisha Mgogoro
                    </button>
                </form>
            </div>
        </div>

        <?php else: ?>
        <!-- Already Processed -->
        <div class="confirm-card result-card">
            <div class="result-icon <?php echo $neighbor['confirmation_status']; ?>">
                <?php if($neighbor['confirmation_status'] == 'confirmed'): ?>
                <i class="fas fa-check-circle"></i>
                <?php elseif($neighbor['confirmation_status'] == 'disputed'): ?>
                <i class="fas fa-exclamation-triangle"></i>
                <?php else: ?>
                <i class="fas fa-clock"></i>
                <?php endif; ?>
            </div>
            <h2>
                <?php
                if($neighbor['confirmation_status'] == 'confirmed') echo 'Boundary Confirmed / Mpaka Umethibitishwa';
                elseif($neighbor['confirmation_status'] == 'disputed') echo 'Dispute Recorded / Mgogoro Umerekodiwa';
                else echo 'Status: ' . ucfirst($neighbor['confirmation_status']);
                ?>
            </h2>
            <p class="result-land">
                Land: <?php echo htmlspecialchars($land['land_name']); ?><br>
                Owner: <?php echo htmlspecialchars($land['owner_name']); ?>
            </p>
            <?php if($neighbor['confirmed_at']): ?>
            <p class="result-date">
                <i class="fas fa-calendar"></i>
                <?php echo date('F j, Y g:i A', strtotime($neighbor['confirmed_at'])); ?>
            </p>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <?php endif; ?>

        <div class="footer-info">
            <p>Need help? Contact village office or call support.</p>
            <p>Unahitaji msaada? Wasiliana na ofisi ya kijiji au piga simu.</p>
        </div>
    </div>

    <style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    body {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
        background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        min-height: 100vh;
        padding: 20px;
    }

    .confirm-container {
        max-width: 700px;
        margin: 0 auto;
    }

    .confirm-header {
        text-align: center;
        margin-bottom: 30px;
    }

    .logo {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin-bottom: 20px;
    }

    .logo i {
        font-size: 32px;
        background: linear-gradient(135deg, #11998e, #38ef7d);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .logo span {
        font-size: 20px;
        font-weight: 700;
        color: #1e293b;
    }

    .confirm-header h1 {
        font-size: 24px;
        color: #1e293b;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
    }

    .confirm-card {
        background: white;
        border-radius: 24px;
        padding: 30px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.1);
        margin-bottom: 24px;
    }

    .card-icon {
        width: 80px;
        height: 80px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 20px;
        font-size: 36px;
        color: white;
    }

    .confirm-card h2 {
        text-align: center;
        color: #1e293b;
        margin-bottom: 10px;
    }

    .confirm-card > p {
        text-align: center;
        color: #64748b;
        margin-bottom: 24px;
    }

    .code-form {
        max-width: 300px;
        margin: 0 auto;
    }

    .code-input {
        text-align: center;
        font-size: 24px;
        font-weight: 700;
        letter-spacing: 4px;
        padding: 16px;
    }

    .land-info {
        background: linear-gradient(135deg, rgba(17, 153, 142, 0.1), rgba(56, 239, 125, 0.1));
        border-radius: 16px;
        padding: 20px;
        margin-bottom: 24px;
    }

    .land-info h3 {
        font-size: 16px;
        color: #11998e;
        margin-bottom: 16px;
    }

    .info-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .info-item {
        display: flex;
        flex-direction: column;
    }

    .info-item label {
        font-size: 12px;
        color: #64748b;
        margin-bottom: 4px;
    }

    .info-item span {
        font-weight: 600;
        color: #1e293b;
    }

    .direction-badge {
        display: inline-block;
        background: linear-gradient(135deg, #3b82f6, #1d4ed8);
        color: white !important;
        padding: 4px 12px;
        border-radius: 20px;
        font-size: 13px;
    }

    .confirm-tabs {
        display: flex;
        gap: 12px;
        margin-bottom: 24px;
    }

    .tab-btn {
        flex: 1;
        padding: 14px;
        border: 2px solid #e2e8f0;
        background: white;
        border-radius: 12px;
        font-weight: 600;
        color: #64748b;
        cursor: pointer;
        transition: all 0.3s;
    }

    .tab-btn.active {
        border-color: #11998e;
        background: linear-gradient(135deg, rgba(17, 153, 142, 0.1), rgba(56, 239, 125, 0.1));
        color: #11998e;
    }

    .tab-btn:hover:not(.active) {
        border-color: #94a3b8;
    }

    .tab-content {
        display: none;
    }

    .tab-content.active {
        display: block;
    }

    .section-title {
        font-size: 14px;
        font-weight: 600;
        color: #1e293b;
        margin: 24px 0 16px;
        padding-bottom: 8px;
        border-bottom: 2px solid #f1f5f9;
    }

    .form-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        display: block;
        font-size: 14px;
        font-weight: 500;
        color: #475569;
        margin-bottom: 8px;
    }

    .required { color: #ef4444; }

    .form-control {
        width: 100%;
        padding: 12px 16px;
        border: 2px solid #e2e8f0;
        border-radius: 10px;
        font-size: 15px;
        transition: all 0.3s;
    }

    .form-control:focus {
        outline: none;
        border-color: #11998e;
        box-shadow: 0 0 0 4px rgba(17, 153, 142, 0.1);
    }

    .file-upload {
        position: relative;
    }

    .file-upload input[type="file"] {
        position: absolute;
        opacity: 0;
        width: 100%;
        height: 100%;
        cursor: pointer;
    }

    .file-label {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        padding: 24px;
        border: 2px dashed #cbd5e1;
        border-radius: 12px;
        cursor: pointer;
        transition: all 0.3s;
    }

    .file-label i {
        font-size: 32px;
        color: #94a3b8;
    }

    .file-label span {
        color: #64748b;
    }

    .file-upload:hover .file-label {
        border-color: #11998e;
        background: rgba(17, 153, 142, 0.05);
    }

    .confirm-notice, .dispute-notice {
        padding: 16px;
        border-radius: 12px;
        margin: 24px 0;
        display: flex;
        gap: 12px;
    }

    .confirm-notice {
        background: #f0fdf4;
        border-left: 4px solid #22c55e;
    }

    .dispute-notice {
        background: #fef3c7;
        border-left: 4px solid #f59e0b;
    }

    .confirm-notice i { color: #22c55e; }
    .dispute-notice i { color: #f59e0b; }

    .confirm-notice p, .dispute-notice p {
        font-size: 13px;
        color: #475569;
        margin: 0 0 4px;
    }

    .btn-primary, .btn-confirm, .btn-dispute {
        width: 100%;
        padding: 16px;
        border: none;
        border-radius: 12px;
        font-weight: 600;
        font-size: 16px;
        cursor: pointer;
        transition: all 0.3s;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
    }

    .btn-primary {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
    }

    .btn-confirm {
        background: linear-gradient(135deg, #22c55e, #16a34a);
        color: white;
    }

    .btn-dispute {
        background: linear-gradient(135deg, #f59e0b, #d97706);
        color: white;
    }

    .btn-primary:hover, .btn-confirm:hover, .btn-dispute:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    }

    .result-card {
        text-align: center;
    }

    .result-icon {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 24px;
        font-size: 48px;
    }

    .result-icon.confirmed {
        background: linear-gradient(135deg, #d1fae5, #a7f3d0);
        color: #059669;
    }

    .result-icon.disputed {
        background: linear-gradient(135deg, #fef3c7, #fde68a);
        color: #d97706;
    }

    .result-land {
        color: #64748b;
        margin-bottom: 16px;
    }

    .result-date {
        color: #94a3b8;
        font-size: 14px;
    }

    .alert {
        border: none;
        border-radius: 14px;
        padding: 16px 20px;
        margin-bottom: 24px;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .alert-success {
        background: #d1fae5;
        color: #166534;
    }

    .alert-danger {
        background: #fee2e2;
        color: #991b1b;
    }

    .footer-info {
        text-align: center;
        color: #94a3b8;
        font-size: 13px;
    }

    @media (max-width: 600px) {
        .form-row, .info-grid {
            grid-template-columns: 1fr;
        }

        .confirm-tabs {
            flex-direction: column;
        }
    }
    </style>

    <script>
    function showTab(tab) {
        document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active'));
        document.querySelectorAll('.tab-btn').forEach(el => el.classList.remove('active'));

        document.getElementById(tab + 'Tab').classList.add('active');
        event.target.classList.add('active');
    }

    // File preview
    document.querySelectorAll('input[type="file"]').forEach(input => {
        input.addEventListener('change', function() {
            const label = this.nextElementSibling;
            if(this.files.length > 0) {
                label.querySelector('span').textContent = this.files[0].name;
                label.style.borderColor = '#22c55e';
                label.style.background = 'rgba(34, 197, 94, 0.1)';
            }
        });
    });
    </script>
</body>
</html>
