/* ==========================================================================
   Form kontrolleri — tek tasarım dili (Bootstrap mantığı)
   --------------------------------------------------------------------------
   Tüm araçlardaki input, select ve textarea alanlarını aynı görünüme getirir.
   Sayfalardaki Tailwind yardımcı sınıfları (bg-black/40, border-white/10 ...)
   ile çakışmaması için temel özellikler !important ile sabitlenir.

   Kapsam dışı tutulanlar:
   - Üst menü/başlık içindeki alanlar (header)
   - Dijital saat ve odak paneli (kendi bileşen tasarımları var)
   - data-no-ahd özniteliği taşıyan her eleman (bilinçli istisna için)

   Bootstrap'teki sınıf adlarına paralel yardımcılar da tanımlanır:
   .form-control, .form-select, .form-label, .form-text, .form-check
   ========================================================================== */

/* --- 1. Tasarım tokenları ------------------------------------------------- */
:root {
    --ahd-form-bg: rgba(0, 0, 0, 0.4);
    --ahd-form-bg-focus: rgba(0, 0, 0, 0.55);
    --ahd-form-border: rgba(255, 255, 255, 0.1);
    --ahd-form-border-hover: rgba(255, 255, 255, 0.2);
    --ahd-form-text: #f8fafc;
    --ahd-form-placeholder: #6b7280;
    --ahd-form-accent: #10b981;
    --ahd-form-accent-soft: rgba(16, 185, 129, 0.25);
    --ahd-form-radius: 0.75rem;
    --ahd-form-height: 3rem;
    --ahd-form-font: inherit;
}

/* --- 2. Metin alanları, select ve textarea ------------------------------- */
body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]), select, textarea):not(header *):not([data-no-ahd]):not(.clock-wrapper *):not(.focus-panel *) {
    appearance: none !important;
    -webkit-appearance: none !important;
    display: block;
    width: 100%;
    min-height: var(--ahd-form-height);
    font-family: var(--ahd-form-font) !important;
    font-size: 1rem !important;
    line-height: 1.5 !important;
    color: var(--ahd-form-text) !important;
    background-color: var(--ahd-form-bg) !important;
    border: 1px solid var(--ahd-form-border) !important;
    border-radius: var(--ahd-form-radius) !important;
    box-shadow: none !important;
    outline: none !important;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease !important;
}

/* Varsayılan iç boşluk: :where() özgüllüğü sıfır tutar; sayfadaki pl-10, px-4 gibi
   Tailwind sınıfları bunu ezebilir. İkon için sol boşluk böylece korunur. */
body :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]), select, textarea):not(header *):not([data-no-ahd]):not(.clock-wrapper *):not(.focus-panel *) {
    padding: 0.75rem 1rem;
}

body :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not(header *):not([data-no-ahd]):not(.clock-wrapper *):not(.focus-panel *)::placeholder {
    color: var(--ahd-form-placeholder) !important;
    opacity: 1;
}

body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea):not(header *):not([data-no-ahd]):not(.clock-wrapper *):not(.focus-panel *):hover {
    border-color: var(--ahd-form-border-hover) !important;
}

body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea):not(header *):not([data-no-ahd]):not(.clock-wrapper *):not(.focus-panel *):focus {
    background-color: var(--ahd-form-bg-focus) !important;
    border-color: var(--ahd-form-accent) !important;
    box-shadow: 0 0 0 3px var(--ahd-form-accent-soft) !important;
}

body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea):not(header *):not([data-no-ahd]):disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Sayısal alanlarda ok tuşlarını gizle (tüm tarayıcılar) */
body input[type="number"]:not([data-no-ahd]):not(header *) {
    -moz-appearance: textfield;
}
body input[type="number"]::-webkit-outer-spin-button,
body input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Select: tek tip ok ikonu */
body select:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *) {
    padding-right: 2.75rem !important;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 1rem center !important;
    background-size: 16px !important;
}

body select option {
    background: #0f172a;
    color: #f8fafc;
}

/* Textarea */
body textarea:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *) {
    min-height: 8rem;
    resize: vertical;
}

/* --- 3. Onay kutusu ve radyo ------------------------------------------- */
body :is(input[type="checkbox"], input[type="radio"]):not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *) {
    appearance: none !important;
    -webkit-appearance: none !important;
    width: 1.125rem !important;
    height: 1.125rem !important;
    margin: 0 !important;
    flex-shrink: 0;
    background-color: var(--ahd-form-bg) !important;
    border: 1px solid var(--ahd-form-border-hover) !important;
    border-radius: 0.375rem !important;
    cursor: pointer;
    display: inline-grid;
    place-content: center;
    transition: background-color .15s ease, border-color .15s ease;
}

body input[type="radio"]:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *) {
    border-radius: 999px !important;
}

body :is(input[type="checkbox"], input[type="radio"]):not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *)::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    transform: scale(0);
    transition: transform .12s ease;
    background: #fff;
}

body input[type="checkbox"]:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *)::before {
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
    width: 0.625rem;
    height: 0.625rem;
}

body input[type="radio"]:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *)::before {
    border-radius: 999px;
}

body :is(input[type="checkbox"], input[type="radio"]):not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *):checked {
    background-color: var(--ahd-form-accent) !important;
    border-color: var(--ahd-form-accent) !important;
}

body :is(input[type="checkbox"], input[type="radio"]):not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *):checked::before {
    transform: scale(1);
}

body :is(input[type="checkbox"], input[type="radio"]):not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *):focus-visible {
    outline: none !important;
    box-shadow: 0 0 0 3px var(--ahd-form-accent-soft) !important;
}

/* --- 4. Aralık (range) kaydırıcısı -------------------------------------- */
body input[type="range"]:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *) {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--ahd-form-border);
    border-radius: 999px;
    outline: none;
    cursor: pointer;
}

body input[type="range"]:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *)::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ahd-form-accent);
    border: 2px solid #0b0f19;
    box-shadow: 0 0 0 1px var(--ahd-form-accent-soft);
}

body input[type="range"]:not([data-no-ahd]):not(header *):not(.clock-wrapper *):not(.focus-panel *)::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ahd-form-accent);
    border: 2px solid #0b0f19;
}

/* --- 5. Bootstrap benzeri yardımcı sınıflar ----------------------------- */
.form-control,
.form-select {
    display: block;
    width: 100%;
    min-height: var(--ahd-form-height);
    padding: 0.75rem 1rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--ahd-form-text);
    background-color: var(--ahd-form-bg);
    border: 1px solid var(--ahd-form-border);
    border-radius: var(--ahd-form-radius);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.form-control:focus,
.form-select:focus {
    outline: none;
    border-color: var(--ahd-form-accent);
    box-shadow: 0 0 0 3px var(--ahd-form-accent-soft);
}

.form-select {
    appearance: none;
    padding-right: 2.75rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #e2e8f0;
}

.form-text {
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: #9ca3af;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    cursor: pointer;
}

/* --- 6. Mobil: dokunmatik hedef boyutu (en az 44px) --------------------- */
@media (max-width: 767px) {
    body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea):not(header *):not([data-no-ahd]):not(.clock-wrapper *):not(.focus-panel *) {
        min-height: 2.75rem !important;
        font-size: 16px !important; /* iOS'ta odaklanınca yakınlaşmayı önler */
    }
}

@media (prefers-reduced-motion: reduce) {
    body :is(input, select, textarea) {
        transition: none !important;
    }
}

/* ==========================================================================
   7. Bileşen: Alan (field) ve birleşik kontrol (input group)
   --------------------------------------------------------------------------
   .ahd-field      : etiket + kontrol + yardımcı metin + hata satırı
   .ahd-group      : değer alanı + ek (affix) + seçici tek çerçevede
   İçindeki elemanlar data-no-ahd taşır; bu bileşen kendi stilini yönetir.
   ========================================================================== */

.ahd-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ahd-field__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.ahd-field__label {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #e2e8f0;
}

.ahd-field__hint {
    font-size: 0.8125rem;
    color: #94a3b8;
    text-align: right;
}

.ahd-field__help {
    font-size: 0.8125rem;
    color: #94a3b8;
}

.ahd-field__error {
    font-size: 0.8125rem;
    color: #f87171;
}

.ahd-field__error[hidden] {
    display: none;
}

.ahd-group {
    position: relative;
    display: flex;
    align-items: stretch;
    width: 100%;
    min-height: 3.25rem;
    background: var(--ahd-form-bg);
    border: 1px solid var(--ahd-form-border);
    border-radius: var(--ahd-form-radius);
    overflow: hidden;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.ahd-group:hover {
    border-color: var(--ahd-form-border-hover);
}

.ahd-group:focus-within {
    background: var(--ahd-form-bg-focus);
    border-color: var(--ahd-form-accent);
    box-shadow: 0 0 0 3px var(--ahd-form-accent-soft);
}

.ahd-group[data-invalid="true"] {
    border-color: #f87171;
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.2);
}

.ahd-group[data-readonly="true"] {
    background: rgba(0, 0, 0, 0.25);
}

/* Değer alanı: çerçevesiz, tüm genişliği kaplar */
.ahd-group__input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 1.125rem; /* iOS yakınlaşmasını önleyecek kadar büyük */
    font-variant-numeric: tabular-nums;
    color: var(--ahd-form-text);
    background: transparent;
    border: 0;
    outline: none;
    box-shadow: none;
    appearance: none;
    -moz-appearance: textfield;
}

.ahd-group__input::placeholder {
    color: var(--ahd-form-placeholder);
    opacity: 1;
}

.ahd-group__input::-webkit-outer-spin-button,
.ahd-group__input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.ahd-group__input:read-only {
    cursor: default;
    color: #e2e8f0;
}

/* Birim/ek bilgi: ayırıcı çizgi ile */
.ahd-group__affix {
    display: inline-flex;
    align-items: center;
    padding: 0 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #94a3b8;
    border-left: 1px solid var(--ahd-form-border);
    white-space: nowrap;
    user-select: none;
}

/* Seçici: aynı yükseklik, ayırıcı çizgi ile */
.ahd-group__select {
    flex: 0 0 auto;
    width: auto;
    min-width: 9.5rem;
    max-width: 14rem;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--ahd-form-text);
    background-color: rgba(15, 23, 42, 0.6);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    background-size: 16px;
    border: 0;
    border-left: 1px solid var(--ahd-form-border);
    border-radius: 0;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.ahd-group__select:focus-visible {
    background-color: rgba(15, 23, 42, 0.85);
}

.ahd-group__select option {
    background: #0f172a;
    color: #f8fafc;
}

@media (max-width: 639px) {
    .ahd-group__select {
        min-width: 7.5rem;
        max-width: 10rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ahd-group { transition: none; }
}

/* Birimleri değiştir düğmesi */
.ahd-swap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 999px;
    color: #22d3ee;
    background: rgba(34, 211, 238, 0.08);
    border: 1px solid rgba(34, 211, 238, 0.25);
    cursor: pointer;
    transition: background-color .15s ease, transform .15s ease, border-color .15s ease;
}

.ahd-swap:hover {
    background: rgba(34, 211, 238, 0.16);
    border-color: rgba(34, 211, 238, 0.45);
}

.ahd-swap:active {
    transform: scale(0.95);
}

.ahd-swap:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ahd-form-accent-soft);
}

.ahd-swap i {
    font-size: 1rem;
}
