/* First-aid trigger + full-screen impulse guard chat */
.impulse-aid {
    position: fixed;
    right: 16px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    pointer-events: none;
}

.impulse-aid-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-3);
    background: color-mix(in srgb, var(--bg-0) 92%, transparent);
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 999px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    animation: impulseAidLabelIn 0.5s 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes impulseAidLabelIn {
    to { opacity: 1; transform: none; }
}

.impulse-aid-stack {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
}

.impulse-aid-btn-wrap {
    position: relative;
    pointer-events: none;
}

.impulse-aid-dismiss-panel {
    pointer-events: auto;
    min-width: min(280px, calc(100vw - 32px));
    padding: 12px;
    border-radius: 16px;
    background: rgba(12, 12, 14, 0.96);
    border: 1px solid var(--border);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    animation: impulseAidLabelIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.impulse-aid-dismiss-kicker {
    margin: 0 0 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
}

.impulse-aid-dismiss-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0 0 6px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-3);
    color: var(--text-1);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.impulse-aid-dismiss-opt:last-child {
    margin-bottom: 0;
}

.impulse-aid-dismiss-opt:hover {
    border-color: rgba(255, 77, 94, 0.4);
    background: rgba(255, 77, 94, 0.08);
}

.impulse-aid-dismiss-opt--muted {
    font-weight: 500;
    color: var(--text-3);
    background: transparent;
}

.impulse-aid-dismiss-opt-icon {
    font-size: 16px;
    line-height: 1;
}

.impulse-aid-x {
    position: absolute;
    top: -6px;
    left: -6px;
    z-index: 3;
    pointer-events: auto;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    font-weight: 600;
    color: var(--text-2);
    background: var(--bg-2);
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.impulse-aid-x:hover,
.impulse-aid-x[aria-expanded="true"] {
    color: var(--text-1);
    background: var(--bg-3);
    border-color: rgba(255, 77, 94, 0.45);
}

.impulse-aid-info {
    position: absolute;
    right: -4px;
    bottom: -4px;
    z-index: 3;
    pointer-events: auto;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
    font-style: italic;
    font-family: Georgia, "Times New Roman", serif;
    color: #0a0a0b;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35), 0 0 0 2px rgba(255, 77, 94, 0.85);
}

.impulse-aid-info:hover {
    transform: scale(1.08);
    filter: brightness(1.05);
}

.impulse-aid-btn {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px 12px 14px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(255, 120, 140, 0.95), rgba(255, 77, 94, 0.9));
    color: #0a0a0b;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.02em;
    box-shadow: 0 8px 32px rgba(255, 77, 94, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
    animation: impulseAidPulse 2.8s ease-in-out infinite;
}

.impulse-aid-btn:hover {
    transform: scale(1.03);
    filter: brightness(1.05);
}

.impulse-aid-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

@keyframes impulseAidPulse {
    0%, 100% { box-shadow: 0 8px 32px rgba(255, 77, 94, 0.3), 0 0 0 0 rgba(255, 77, 94, 0.2); }
    50% { box-shadow: 0 12px 40px rgba(255, 77, 94, 0.45), 0 0 0 8px rgba(255, 77, 94, 0); }
}

.impulse-guard {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    background: #050506;
    color: var(--text-1);
}

.impulse-guard-sidebar {
    width: min(280px, 85vw);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: rgba(12, 12, 14, 0.98);
}

.impulse-guard-sidebar-head {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.impulse-guard-new {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px dashed rgba(255, 120, 140, 0.4);
    background: rgba(255, 77, 94, 0.08);
    color: #ff8a9a;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.impulse-guard-threads {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.impulse-guard-thread-row {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 4px;
}

.impulse-guard-thread-row .impulse-guard-thread {
    margin-bottom: 0;
}

.impulse-guard-thread-del {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--red);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
}

.impulse-guard-thread-del:hover {
    background: var(--red-dim);
}

.impulse-guard-thread-row .impulse-guard-thread {
    flex: 1;
    min-width: 0;
}

.impulse-guard-thread {
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.impulse-guard-thread:hover {
    background: var(--bg-3);
}

.impulse-guard-thread.active {
    background: rgba(255, 77, 94, 0.12);
    color: var(--text-0);
}

.impulse-guard-thread-title {
    display: block;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.impulse-guard-thread-date {
    font-size: 11px;
    color: var(--text-4);
}

.impulse-guard-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.impulse-guard-main::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 480px;
    height: 240px;
    background: radial-gradient(ellipse, rgba(255, 77, 94, 0.1) 0%, transparent 70%);
    pointer-events: none;
}

.impulse-guard-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.impulse-guard-top h1 {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.03em;
}

.impulse-guard-top p {
    font-size: 12px;
    color: var(--text-3);
    margin: 2px 0 0;
}

.impulse-guard-close {
    border: none;
    background: var(--bg-3);
    color: var(--text-2);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.impulse-guard-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.impulse-guard-start-btn {
    margin-top: 16px;
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #0a0a0b;
    background: linear-gradient(135deg, rgba(255, 120, 140, 0.95), rgba(255, 77, 94, 0.9));
    box-shadow: 0 8px 24px rgba(255, 77, 94, 0.25);
}

.impulse-guard-start-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.impulse-guard-msg {
    max-width: min(520px, 92%);
    padding: 14px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.impulse-guard-msg--user {
    align-self: flex-end;
    background: rgba(62, 255, 160, 0.12);
    border: 1px solid rgba(62, 255, 160, 0.2);
    border-bottom-right-radius: 4px;
}

.impulse-guard-msg--assistant {
    align-self: flex-start;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.impulse-guard-starter {
    max-width: 420px;
    margin: auto;
    text-align: center;
    padding: 24px;
}

.impulse-guard-starter h2 {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 8px;
    letter-spacing: -0.04em;
}

.impulse-guard-starter p {
    font-size: 14px;
    color: var(--text-3);
    margin: 0 0 20px;
    line-height: 1.5;
}

.impulse-guard-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
    margin-bottom: 12px;
}

.impulse-guard-compose {
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: rgba(8, 8, 10, 0.95);
}

.impulse-guard-compose-inner {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.impulse-guard-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.impulse-guard-input-row textarea {
    flex: 1;
    min-height: 48px;
    max-height: 120px;
    resize: none;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text-1);
    font-size: 14px;
    font-family: inherit;
}

.impulse-guard-send {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 14px;
    background: var(--accent);
    color: #050506;
    font-weight: 700;
    cursor: pointer;
}

.impulse-guard-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.impulse-guard-sidebar-toggle {
    display: none;
    border: none;
    background: var(--bg-3);
    color: var(--text-2);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
}

@media (max-width: 768px) {
    .impulse-guard-sidebar {
        position: absolute;
        inset: 0 auto 0 0;
        z-index: 2;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .impulse-guard-sidebar.open {
        transform: translateX(0);
    }

    .impulse-guard-sidebar-toggle {
        display: inline-block;
    }

    .impulse-aid-label {
        display: none;
    }

    /* FAB + bottom nav: scroll alanında içerik kesilmesin */
    .impulse-aid {
        bottom: calc(78px + env(safe-area-inset-bottom, 0px));
        right: 12px;
        max-width: calc(100vw - 24px);
    }

    .impulse-aid-btn {
        max-width: 100%;
        padding: 10px 14px 10px 12px;
        font-size: 12px;
    }

    .impulse-aid-btn span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@media (max-width: 767px) {
    .app-content {
        padding-bottom: calc(128px + env(safe-area-inset-bottom, 0px));
    }
}

.app-root.impulse-guard-open {
    overflow: hidden;
}

.debt-guard-cta {
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface-1));
}

.debt-guard-cta-btn {
    width: 100%;
    margin-top: 8px;
}

.debt-guard-verdict--lend {
    border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.debt-guard-verdict--decline {
    border-color: color-mix(in srgb, var(--red, #ef4444) 45%, transparent);
}

.debt-guard-verdict--conditional {
    border-color: color-mix(in srgb, #eab308 50%, transparent);
}

.dynamic-ai-form-field + .dynamic-ai-form-field {
    margin-top: 14px;
}

.dynamic-ai-form-req {
    color: var(--red, #ef4444);
}

.dynamic-ai-form-multi {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

[data-theme="light"] .impulse-guard {
    background: var(--bg-0);
}

[data-theme="light"] .impulse-guard-sidebar {
    background: var(--surface-sidebar, var(--bg-1));
}

[data-theme="light"] .impulse-aid-label {
    background: var(--glass);
    color: var(--text-2);
}

[data-theme="light"] .impulse-guard-thread:hover,
[data-theme="light"] .impulse-guard-thread.active {
    background: var(--accent-dim);
    border-color: var(--accent-border);
}
