/* Canlı destek widget'ı (MODÜL B) — sağ-alt köşe panel, tek seferde TEK ekran.
   Renkler landing token'larına bağlı; token yoksa fallback değerler devreye girer. */

.nm-chat {
    --nmc-accent: var(--landing-accent, #25a66a);
    --nmc-accent-dark: var(--landing-accent-dark, #137a4d);
    --nmc-accent-soft: var(--landing-accent-soft, rgba(37, 166, 106, 0.12));
    --nmc-ink: var(--landing-ink, #173126);
    --nmc-muted: var(--landing-muted, #66796e);
    --nmc-line: var(--landing-line, rgba(37, 88, 59, 0.12));
    --nmc-soft: #f7fbf6;
    position: fixed;
    right: 1.1rem;
    bottom: 1.1rem;
    z-index: 90;
    font-family: var(--landing-font, "Poppins", "Segoe UI", system-ui, sans-serif);
}

/* ---------- Launcher ---------- */
/* Okunmamış yanıt rozeti (launcher butonu üstünde). */
.nm-chat__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    z-index: 2;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 2px #fff;
    pointer-events: none;
}

.nm-chat__badge[hidden] {
    display: none;
}

.nm-chat__launcher {
    position: relative;
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    padding: 0;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--nmc-accent) 0%, var(--nmc-accent-dark) 100%);
    color: #fff;
    box-shadow: 0 16px 34px rgba(19, 122, 77, 0.36);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.nm-chat__launcher:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 22px 42px rgba(19, 122, 77, 0.42);
}

.nm-chat__launcher:focus-visible {
    outline: 3px solid rgba(37, 166, 106, 0.45);
    outline-offset: 3px;
}

.nm-chat__launcher-ic {
    display: grid;
    place-items: center;
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.nm-chat__launcher-ic svg {
    width: 34px;
    height: 34px;
    display: block;
}

.nm-chat__launcher-ic--close {
    position: absolute;
    inset: 0;
    margin: auto;
    opacity: 0;
    transform: rotate(-45deg) scale(0.6);
}

.nm-chat__launcher-ic--close svg {
    width: 24px;
    height: 24px;
}

.nm-chat[data-state="open"] .nm-chat__launcher-ic--mascot {
    opacity: 0;
    transform: rotate(45deg) scale(0.6);
}

.nm-chat[data-state="open"] .nm-chat__launcher-ic--close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

.nm-chat__hint {
    position: absolute;
    right: 72px;
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    white-space: nowrap;
    background: #fff;
    color: var(--nmc-ink);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.42rem 0.7rem;
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(27, 78, 52, 0.16);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.nm-chat__launcher:hover .nm-chat__hint {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.nm-chat[data-state="open"] .nm-chat__hint {
    display: none;
}

/* ---------- Köşe panel + aç/kapa animasyonu ---------- */
.nm-chat__panel {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: min(384px, calc(100vw - 2rem));
    height: min(600px, calc(100vh - 7rem));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--nmc-line);
    border-radius: 22px;
    box-shadow: 0 30px 80px rgba(20, 60, 40, 0.28);
    transform-origin: bottom right;
    opacity: 0;
    visibility: hidden;
    transform: translateY(18px) scale(0.9);
    transition: opacity 0.2s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.3s;
}

.nm-chat[data-state="open"] .nm-chat__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transition: opacity 0.22s ease, transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s;
}

/* ---------- Topbar ---------- */
.nm-chat__head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.85rem 0.95rem;
    background: linear-gradient(135deg, var(--nmc-accent) 0%, var(--nmc-accent-dark) 100%);
    color: #fff;
}

.nm-chat__avatar {
    flex: none;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
}

.nm-chat__avatar svg {
    width: 32px;
    height: 32px;
}

.nm-chat__head-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.nm-chat__head-text strong {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nm-chat__presence {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.76rem;
    line-height: 1;
    opacity: 0.95;
    white-space: nowrap;
}

.nm-chat__presence-text::before {
    content: "Çevrimiçi · ";
}

.nm-chat.is-offline .nm-chat__presence-text::before {
    content: "Çevrimdışı · ";
}

.nm-chat__dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #8ef0b4;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.22);
}

.nm-chat.is-offline .nm-chat__dot {
    background: #ffd27a;
}

.nm-chat__head-actions {
    flex: none;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.nm-chat__menu,
.nm-chat__close {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    cursor: pointer;
    transition: background 0.16s ease;
}

.nm-chat__menu:hover,
.nm-chat__close:hover {
    background: rgba(255, 255, 255, 0.34);
}

.nm-chat__menu svg,
.nm-chat__close svg {
    width: 19px;
    height: 19px;
}

.nm-chat__menu-pop {
    position: absolute;
    top: 40px;
    right: 0;
    min-width: 188px;
    padding: 0.35rem;
    background: #fff;
    border: 1px solid var(--nmc-line);
    border-radius: 14px;
    box-shadow: 0 18px 44px rgba(20, 60, 40, 0.22);
    z-index: 5;
}

.nm-chat__menu-history,
.nm-chat__menu-close {
    width: 100%;
    padding: 0.6rem 0.7rem;
    text-align: left;
    font-size: 0.88rem;
    font-family: inherit;
    background: none;
    border: none;
    border-radius: 10px;
    cursor: pointer;
}

.nm-chat__menu-history {
    color: var(--nmc-ink);
}

.nm-chat__menu-history:hover {
    background: var(--nmc-accent-soft);
}

.nm-chat__menu-close {
    color: #c0392b;
}

.nm-chat__menu-close:hover {
    background: rgba(192, 57, 43, 0.08);
}

/* ---------- Gövde + ekranlar (tek seferde tek ekran) ---------- */
.nm-chat__body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.nm-chat__view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* KRİTİK: hidden ekranlar gizlensin (class display:flex'i ezmesin). */
.nm-chat__view[hidden] {
    display: none;
}

.nm-chat__view:not([hidden]) {
    animation: nmViewIn 0.22s ease;
}

@keyframes nmViewIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ---------- 1) Form ---------- */
.nm-chat__form {
    gap: 0.7rem;
    padding: 1.2rem 1.1rem;
    overflow-y: auto;
    background: var(--nmc-soft);
}

.nm-chat__field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--nmc-muted);
}

.nm-chat__req {
    color: #ef4444;
    font-style: normal;
    font-weight: 700;
}

/* Oturum açmış kullanıcıya selamlama (ad/e-posta formu yerine). */
.nm-chat__greeting {
    margin: 0 0 0.2rem;
    padding: 0.7rem 0.85rem;
    background: var(--nmc-accent-soft, #eafaf2);
    border-radius: 12px;
    font-size: 0.92rem;
    line-height: 1.45;
    color: var(--nmc-ink, #1f2937);
}

.nm-chat__field input,
.nm-chat__field textarea {
    width: 100%;
    padding: 0.72rem 0.8rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--nmc-ink);
    background: #fff;
    border: 1px solid var(--nmc-line);
    border-radius: 14px;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.nm-chat__field textarea {
    resize: none;
    line-height: 1.45;
    min-height: 96px;
}

.nm-chat__field input::placeholder,
.nm-chat__field textarea::placeholder {
    color: #9bb0a4;
}

.nm-chat__field input:focus,
.nm-chat__field textarea:focus {
    outline: none;
    border-color: var(--nmc-accent);
    box-shadow: 0 0 0 3px rgba(37, 166, 106, 0.16);
}

.nm-chat__hp {
    position: absolute !important;
    left: -9999px !important;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.nm-chat__btn {
    margin-top: auto;
    padding: 0.85rem 1rem;
    font-size: 0.98rem;
    font-weight: 700;
    font-family: inherit;
    color: #062315;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--nmc-accent) 0%, #7bd87e 100%);
    box-shadow: 0 14px 28px rgba(37, 166, 106, 0.24);
    transition: transform 0.16s ease, opacity 0.16s ease;
}

.nm-chat__btn:hover {
    transform: translateY(-1px);
}

.nm-chat__btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ---------- 2) Gönderildi ---------- */
.nm-chat__sent {
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    padding: 1.6rem;
    text-align: center;
    background: var(--nmc-soft);
}

.nm-chat__sent-ic {
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--nmc-accent) 0%, var(--nmc-accent-dark) 100%);
    box-shadow: 0 18px 36px rgba(19, 122, 77, 0.3);
}

.nm-chat__sent-ic svg {
    width: 38px;
    height: 38px;
}

.nm-chat__sent h2 {
    margin: 0.3rem 0 0;
    font-size: 1.15rem;
    color: var(--nmc-ink);
}

.nm-chat__sent p {
    margin: 0;
    max-width: 280px;
    font-size: 0.9rem;
    color: var(--nmc-muted);
    line-height: 1.55;
}

/* ---------- 3) Sohbet ---------- */
/* KRİTİK: countdown yalnız geri sayım başlayınca görünür (display:flex hidden'ı ezmesin). */
.nm-chat__countdown[hidden] {
    display: none;
}

.nm-chat__countdown {
    flex: none;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.65rem 1rem;
    background: #fff7e6;
    border-bottom: 1px solid #ffe1a6;
    color: #8a5a00;
    font-size: 0.84rem;
    line-height: 1.4;
}

.nm-chat__countdown-ic {
    flex: none;
    width: 18px;
    height: 18px;
}

.nm-chat__countdown-text {
    flex: 1;
    min-width: 0;
}

.nm-chat__countdown-time {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.nm-chat__messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--nmc-soft);
}

.nm-chat__date {
    align-self: center;
    margin: 0.1rem auto 0.5rem;
    padding: 0.24rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--nmc-muted);
    background: #fff;
    border: 1px solid var(--nmc-line);
    border-radius: 999px;
}

.nm-msg-wrap {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.nm-msg-wrap--me {
    align-self: flex-end;
    align-items: flex-end;
}

.nm-msg-wrap--admin {
    align-self: flex-start;
    align-items: flex-start;
}

.nm-msg {
    max-width: 100%;
    padding: 0.58rem 0.8rem;
    font-size: 0.92rem;
    line-height: 1.45;
    border-radius: 16px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.nm-msg--me {
    background: linear-gradient(135deg, var(--nmc-accent) 0%, var(--nmc-accent-dark) 100%);
    color: #fff;
    border-bottom-right-radius: 5px;
}

.nm-msg--admin {
    background: #fff;
    color: var(--nmc-ink);
    border: 1px solid var(--nmc-line);
    border-bottom-left-radius: 5px;
}

.nm-msg-time {
    margin-top: 3px;
    padding: 0 4px;
    font-size: 0.66rem;
    color: var(--nmc-muted);
}

.nm-chat__status {
    flex: none;
    margin: 0;
    padding: 0.5rem 1rem 0;
    font-size: 0.8rem;
    color: var(--nmc-muted);
    text-align: center;
}

.nm-chat__status:empty {
    display: none;
}

.nm-chat__new {
    flex: none;
    margin: 0.7rem 1rem;
    padding: 0.72rem 1rem;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: inherit;
    color: var(--nmc-accent-dark);
    background: #fff;
    border: 1px solid var(--nmc-accent);
    border-radius: 14px;
    cursor: pointer;
}

.nm-chat__send {
    flex: none;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.8rem 0.9rem;
    border-top: 1px solid var(--nmc-line);
    background: #fff;
}

.nm-chat__send textarea {
    flex: 1;
    resize: none;
    max-height: 120px;
    padding: 0.68rem 0.8rem;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.45;
    color: var(--nmc-ink);
    background: var(--nmc-soft);
    border: 1px solid var(--nmc-line);
    border-radius: 16px;
}

.nm-chat__send textarea:focus {
    outline: none;
    border-color: var(--nmc-accent);
    box-shadow: 0 0 0 3px rgba(37, 166, 106, 0.16);
    background: #fff;
}

.nm-chat__send-btn {
    flex: none;
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--nmc-accent) 0%, var(--nmc-accent-dark) 100%);
    transition: transform 0.16s ease, opacity 0.16s ease;
}

.nm-chat__send-btn:hover {
    transform: scale(1.05);
}

.nm-chat__send-btn svg {
    width: 21px;
    height: 21px;
}

.nm-chat.is-closed .nm-chat__send textarea,
.nm-chat.is-closed .nm-chat__send-btn {
    opacity: 0.5;
    pointer-events: none;
}

/* ---------- 4) Geçmiş görüşmeler ---------- */
.nm-chat__history {
    background: var(--nmc-soft);
}

.nm-chat__history-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 0.9rem;
    background: #fff;
    border-bottom: 1px solid var(--nmc-line);
    color: var(--nmc-ink);
    font-size: 0.95rem;
}

.nm-chat__back {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 999px;
    background: var(--nmc-accent-soft);
    color: var(--nmc-accent-dark);
    cursor: pointer;
}

.nm-chat__back svg {
    width: 18px;
    height: 18px;
}

.nm-chat__history-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nm-chat__hist-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    width: 100%;
    padding: 0.75rem 0.85rem;
    text-align: left;
    font-family: inherit;
    background: #fff;
    border: 1px solid var(--nmc-line);
    border-radius: 14px;
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.nm-chat__hist-item:hover {
    border-color: var(--nmc-accent);
    box-shadow: 0 8px 20px rgba(27, 78, 52, 0.08);
}

.nm-chat__hist-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.nm-chat__hist-badge {
    flex: none;
    font-size: 0.66rem;
    font-weight: 700;
    padding: 0.14rem 0.55rem;
    border-radius: 999px;
}

.nm-chat__hist-badge--open {
    background: var(--nmc-accent-soft);
    color: var(--nmc-accent-dark);
}

.nm-chat__hist-badge--closed {
    background: #eef2f7;
    color: #64748b;
}

.nm-chat__hist-date {
    font-size: 0.72rem;
    color: var(--nmc-muted);
}

.nm-chat__hist-msg {
    font-size: 0.88rem;
    color: var(--nmc-ink);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.nm-chat__hist-empty,
.nm-chat__hist-loading {
    margin: auto;
    padding: 1.5rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--nmc-muted);
}

/* ---------- CAPTCHA + toast ---------- */
.nm-chat__captcha {
    margin: 0.1rem 0;
    min-height: 0;
}

.nm-chat__toast {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 20;
    padding: 0.7rem 0.9rem;
    font-size: 0.84rem;
    line-height: 1.4;
    color: #fff;
    background: #173126;
    border-radius: 12px;
    box-shadow: 0 14px 32px rgba(20, 60, 40, 0.34);
}

.nm-chat__toast--error {
    background: #b3261e;
}

@media (max-width: 480px) {
    .nm-chat {
        right: 0.85rem;
        bottom: 0.85rem;
    }

    .nm-chat__panel {
        width: calc(100vw - 1.7rem);
        height: min(600px, calc(100vh - 6rem));
    }
}

@media (prefers-reduced-motion: reduce) {
    .nm-chat__launcher,
    .nm-chat__panel,
    .nm-chat__hint,
    .nm-chat__launcher-ic,
    .nm-chat__view:not([hidden]) {
        transition: none;
        animation: none;
    }
}
