<?php 
// Güvenlik Kontrolü: Eğer index.php üzerinden gelinmemişse erişimi engelle
if (!defined('PDO::ATTR_ERRMODE')) { 
    echo "Direct access denied."; 
    exit; 
} 
?>

<style>
    /* Tasarımın sayfa içinde kaymaması için konteynır */
    .form-wrapper { max-width: 900px; margin: 0 auto; padding-bottom: 40px; }
    
    /* Kart Yapısı */
    .patient-card { background: #fff; border-radius: 24px; box-shadow: 0 10px 40px rgba(0,0,0,0.04); padding: 40px; border: 1px solid #f1f5f9; }
    
    /* Başlık Stilleri */
    .section-title { font-size: 0.7rem; font-weight: 800; color: #2563eb; text-transform: uppercase; letter-spacing: 1.5px; margin: 30px 0 15px 0; display: block; border-bottom: 2px solid #f8fafc; padding-bottom: 8px; }
    .section-title:first-child { margin-top: 0; }

    /* Form Elemanları */
    .f-group { margin-bottom: 20px; }
    .f-group label { display: block; font-size: 0.85rem; font-weight: 600; color: #475569; margin-bottom: 8px; }
    
    .input-aura {
        width: 100%; padding: 14px 18px; border: 2px solid #f1f5f9; border-radius: 14px;
        font-size: 0.95rem; color: #1e293b; transition: 0.3s; outline: none; box-sizing: border-box;
        background: #fdfdfe;
    }
    .input-aura:focus { border-color: #3b82f6; background: #fff; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.08); }

    /* Grid Sistemi */
    .grid-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
    .grid-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
    
    @media (max-width: 768px) { .grid-row, .grid-row-3 { grid-template-columns: 1fr; } }

    /* Buton */
    .btn-submit {
        width: 100%; padding: 18px; background: #2563eb; color: #fff; border: none;
        border-radius: 14px; font-size: 1rem; font-weight: 700; cursor: pointer;
        transition: 0.3s; margin-top: 20px; box-shadow: 0 4px 15px rgba(37, 99, 235, 0.2);
        display: flex; align-items: center; justify-content: center; gap: 10px;
    }
    .btn-submit:hover { background: #1d4ed8; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(37, 99, 235, 0.3); }
</style>

<div class="form-wrapper">
    <div class="patient-card">
        <div style="text-align: center; margin-bottom: 40px;">
            <h2 style="margin: 0; color: #0f172a; font-weight: 800; font-size: 1.8rem;">Yeni Hasta Tanımla</h2>
            <p style="color: #94a3b8; font-size: 1rem; margin-top: 5px;">Klinik ve demografik verileri sisteme işleyin.</p>
        </div>

        <form action="islem.php" method="POST">
            
            <span class="section-title">Kimlik Bilgileri</span>
            <div class="grid-row">
                <div class="f-group">
                    <label>T.C. Kimlik Numarası</label>
                    <input type="number" name="tc_no" class="input-aura" id="tcField" placeholder="11 Hane" required>
                </div>
                <div class="f-group">
                    <label>Kan Grubu</label>
                    <select name="kan_grubu" class="input-aura">
                        <option value="">Seçiniz...</option>
                        <option>A Rh(+)</option><option>A Rh(-)</option>
                        <option>B Rh(+)</option><option>B Rh(-)</option>
                        <option>AB Rh(+)</option><option>AB Rh(-)</option>
                        <option>0 Rh(+)</option><option>0 Rh(-)</option>
                    </select>
                </div>
            </div>

            <div class="grid-row">
                <div class="f-group"><label>Adı</label><input type="text" name="ad" class="input-aura" placeholder="Ad" required></div>
                <div class="f-group"><label>Soyadı</label><input type="text" name="soyad" class="input-aura" placeholder="Soyad" required></div>
            </div>

            <div class="grid-row">
                <div class="f-group">
                    <label>Cinsiyet</label>
                    <select name="cinsiyet" class="input-aura" required>
                        <option value="">Seçiniz...</option>
                        <option value="Erkek">Erkek</option>
                        <option value="Kadın">Kadın</option>
                    </select>
                </div>
                <div class="f-group"><label>Doğum Tarihi</label><input type="date" name="dogum_tarihi" class="input-aura" required></div>
            </div>

            <span class="section-title">Klinik Veriler</span>
            <div class="grid-row-3">
                <div class="f-group">
                    <label>Hepatit</label>
                    <select name="hepatit_durumu" class="input-aura">
                        <option>Negatif</option><option>HbsAg+</option><option>Anti-HCV+</option><option>HIV+</option>
                    </select>
                </div>
                <div class="f-group">
                    <label>Damar Yolu</label>
                    <select name="damar_yolu" class="input-aura">
                        <option>AVF</option><option>AVG</option><option>Kateter</option>
                    </select>
                </div>
                <div class="f-group">
                    <label>Diyabet</label>
                    <select name="diyabet_durumu" class="input-aura">
                        <option value="0">Hayır</option><option value="1">Evet</option>
                    </select>
                </div>
            </div>

            <span class="section-title">İletişim & Yakınlar</span>
            <div class="f-group"><label>Hasta Telefon</label><input type="tel" name="telefon" class="input-aura" placeholder="05xx xxx xx xx"></div>
            <div class="f-group"><label>İkamet Adresi</label><textarea name="adres" class="input-aura" style="min-height: 80px;"></textarea></div>

            <div style="background: #f8fafc; padding: 25px; border-radius: 20px; border: 1px solid #f1f5f9;">
                <p style="margin: 0 0 15px 0; font-size: 0.75rem; font-weight: 800; color: #2563eb;">ACİL DURUM YAKINI</p>
                <div class="grid-row">
                    <div class="f-group"><label>Ad Soyad</label><input type="text" name="yakin_ad_soyad" class="input-aura"></div>
                    <div class="f-group"><label>Yakınlık Derecesi</label><input type="text" name="yakin_yakinlik_derecesi" class="input-aura" placeholder="Örn: Eşi"></div>
                </div>
                <div class="f-group" style="margin-bottom: 0;"><label>Yakın Telefon</label><input type="tel" name="yakin_telefon" class="input-aura"></div>
            </div>

            <button type="submit" name="hasta_kaydet" class="btn-submit">
                <i class="fas fa-save"></i> HASTA KAYDINI TAMAMLA
            </button>
        </form>
    </div>
</div>

<script>
    // TC No Kısıtlama
    const tc = document.getElementById('tcField');
    tc.addEventListener('input', function() {
        if (this.value.length > 11) this.value = this.value.slice(0, 11);
    });
</script>