/* 19 Days to Impact — docked live chat widget.
   Scoped under .dti-chat; reuses the site's CSS custom properties (with
   fallbacks) so it adapts to light/dark via :root[data-theme]. */

.dti-chat {
    --dc-paper: var(--paper, #fff);
    --dc-ink: var(--ink, #111);
    --dc-accent: var(--accent, #F2D34E);
    --dc-accent-ink: var(--accent-ink, #161512);
    --dc-teal: var(--teal, #2A8D8A);
    --dc-line: var(--line, rgba(17, 17, 17, .12));
    --dc-soft: var(--bg-soft, #f0ecec);
    --dc-shadow: var(--shadow, 0 8px 28px -12px rgba(0, 0, 0, .35));
    --dc-radius: 16px;

    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2147482000;
    font-family: var(--font-body, system-ui, sans-serif);
    color: var(--dc-ink);
}

.dti-chat *,
.dti-chat *::before,
.dti-chat *::after { box-sizing: border-box; }

/* The widget toggles visibility via the [hidden] attribute. Our display rules
   below (flex/inline-flex) would otherwise override the UA [hidden] rule, so
   make hidden always win. */
.dti-chat [hidden] { display: none !important; }

.dti-chat .visually-hidden {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- Avatar cluster ---- */
.dti-chat__avatars { display: inline-flex; flex: 0 0 auto; }
.dti-chat__avatar,
.dti-chat__avatars picture {
    width: 30px; height: 30px; border-radius: 50%;
    display: block; object-fit: cover;
    border: 2px solid var(--dc-paper);
    margin-left: -10px; background: var(--dc-soft);
}
.dti-chat__avatars picture:first-child,
.dti-chat__avatars picture:first-child .dti-chat__avatar { margin-left: 0; }
.dti-chat__avatar { border: none; margin: 0; }

/* ---- Launcher (collapsed) — accent-tinted, irregular attention pulse ---- */
.dti-chat__launcher {
    position: relative;
    display: inline-flex; align-items: center; gap: 10px;
    padding: 8px 16px 8px 10px;
    background: var(--dc-paper);
    background: linear-gradient(135deg, var(--dc-paper), color-mix(in srgb, var(--dc-accent) 26%, var(--dc-paper)));
    color: var(--dc-ink);
    border: 1px solid var(--dc-line);
    border: 1px solid color-mix(in srgb, var(--dc-accent) 55%, var(--dc-line));
    border-radius: 999px;
    box-shadow: var(--dc-shadow);
    cursor: pointer;
    font: 600 14px/1 var(--font-body, system-ui, sans-serif);
    transition: transform .15s ease, box-shadow .15s ease;
    animation: dtiLauncherGlow 6.5s ease-in-out infinite;
}
.dti-chat__launcher:hover { transform: translateY(-2px); }
/* Expanding accent ring: two quick ripples, then a long rest (deliberately irregular). */
.dti-chat__launcher::after {
    content: ""; position: absolute; inset: -1px; border-radius: inherit;
    border: 2px solid var(--dc-accent);
    opacity: 0; pointer-events: none;
    animation: dtiLauncherRing 6.5s ease-out infinite;
}
@keyframes dtiLauncherRing {
    0%   { transform: scale(1);    opacity: .6; }
    9%   { transform: scale(1.3);  opacity: 0; }
    14%  { transform: scale(1);    opacity: .5; }
    23%  { transform: scale(1.26); opacity: 0; }
    100% { transform: scale(1);    opacity: 0; }
}
@keyframes dtiLauncherGlow {
    0%, 100% { box-shadow: var(--dc-shadow), 0 0 14px -6px rgba(242, 211, 78, .4); }
    9%       { box-shadow: var(--dc-shadow), 0 0 28px -2px rgba(242, 211, 78, .9); }
    23%      { box-shadow: var(--dc-shadow), 0 0 22px -3px rgba(242, 211, 78, .7); }
    42%      { box-shadow: var(--dc-shadow), 0 0 14px -6px rgba(242, 211, 78, .4); }
}
.dti-chat__launcher-label { white-space: nowrap; }
.dti-chat__badge {
    min-width: 18px; height: 18px; padding: 0 5px;
    background: #E11D48; color: #fff;
    border-radius: 999px; font-size: 11px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
}

/* ---- Panel (expanded) ---- */
.dti-chat__panel {
    display: flex; flex-direction: column;
    width: min(380px, calc(100vw - 40px));
    height: min(580px, calc(100vh - 110px));
    background: var(--dc-paper);
    border: 1px solid var(--dc-line);
    border-radius: var(--dc-radius);
    box-shadow: var(--dc-shadow);
    overflow: hidden;
}

.dti-chat__header {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 12px 12px 16px;
    border-bottom: 1px solid var(--dc-line);
    background: var(--dc-paper);
}
.dti-chat__heading { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.dti-chat__title {
    font-weight: 700; font-size: 14px; letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dti-chat__presence { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; opacity: .7; }
.dti-chat__dot { width: 8px; height: 8px; border-radius: 50%; background: #9b9b9b; flex: 0 0 auto; }
.dti-chat[data-presence="online"] .dti-chat__dot { background: #16A34A; }
.dti-chat__icon {
    flex: 0 0 auto; width: 30px; height: 30px; padding: 0;
    display: grid; place-items: center;
    border: none; background: transparent; color: inherit;
    border-radius: 8px; cursor: pointer; opacity: .65;
    transition: background .15s, opacity .15s;
}
.dti-chat__icon:hover { opacity: 1; background: var(--dc-soft); }

/* ---- Body / messages ---- */
.dti-chat__body { flex: 1 1 auto; overflow-y: auto; padding: 14px; }
.dti-chat__messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.dti-chat__msg { display: flex; flex-direction: column; max-width: 84%; }
.dti-chat__msg--visitor { align-self: flex-end; align-items: flex-end; }
.dti-chat__msg--owner { align-self: flex-start; align-items: flex-start; }
.dti-chat__msg-row { display: flex; align-items: flex-end; gap: 8px; }
.dti-chat__msg-ava { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; background: var(--dc-teal); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.dti-chat__bubble {
    padding: 8px 12px; border-radius: 16px;
    font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.dti-chat__msg--visitor .dti-chat__bubble { background: var(--dc-accent); color: var(--dc-accent-ink); border-bottom-right-radius: 5px; }
.dti-chat__msg--owner .dti-chat__bubble { background: var(--dc-soft); color: var(--dc-ink); border: 1px solid var(--dc-line); border-bottom-left-radius: 5px; }
.dti-chat__sender { font-size: 11px; font-weight: 600; opacity: .6; margin: 0 0 3px 34px; }
.dti-chat__meta { font-size: 10.5px; opacity: .5; margin-top: 3px; }

.dti-chat__bubble img { max-width: 220px; max-height: 220px; border-radius: 10px; display: block; }
.dti-chat__file { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: inherit; font-weight: 600; }
.dti-chat__file::before { content: "📄"; }

/* reactions */
.dti-chat__reactions { display: flex; gap: 4px; margin-top: 4px; }
.dti-chat__reaction {
    font-size: 13px; line-height: 1; padding: 3px 7px;
    background: var(--dc-paper); border: 1px solid var(--dc-line);
    border-radius: 999px;
}
.dti-chat__react-btn {
    align-self: center; border: none; background: transparent; cursor: pointer;
    opacity: 0; font-size: 14px; padding: 2px 4px; transition: opacity .12s;
}
.dti-chat__msg:hover .dti-chat__react-btn { opacity: .5; }
.dti-chat__react-btn:hover { opacity: 1; }
.dti-chat__react-menu {
    display: inline-flex; gap: 2px; padding: 4px;
    background: var(--dc-paper); border: 1px solid var(--dc-line);
    border-radius: 999px; box-shadow: var(--dc-shadow);
}
.dti-chat__react-menu button { border: none; background: transparent; cursor: pointer; font-size: 18px; line-height: 1; padding: 3px; border-radius: 50%; }
.dti-chat__react-menu button:hover { background: var(--dc-soft); transform: scale(1.15); }

/* ---- Name gate ---- */
.dti-chat__gate { display: flex; flex-direction: column; gap: 10px; padding: 6px 2px 2px; }
.dti-chat__gate-intro { margin: 0 0 4px; font-size: 14px; line-height: 1.45; }
.dti-chat__gate input,
.dti-chat__composer textarea {
    width: 100%; padding: 10px 12px; font: inherit; font-size: 14px;
    color: var(--dc-ink); background: var(--dc-paper);
    border: 1px solid var(--dc-line); border-radius: 10px;
}
.dti-chat__gate input:focus,
.dti-chat__composer textarea:focus { outline: 2px solid var(--dc-ink); outline-offset: 1px; }
.dti-chat__gate-actions { display: flex; gap: 8px; }
.dti-chat__btn { padding: 9px 16px; border-radius: 999px; border: 1px solid var(--dc-line); background: var(--dc-paper); color: var(--dc-ink); font: 600 14px var(--font-body, system-ui, sans-serif); cursor: pointer; }
.dti-chat__btn--primary { background: var(--dc-ink); color: var(--dc-paper); border-color: var(--dc-ink); }
.dti-chat__btn:hover { transform: translateY(-1px); }

/* ---- Composer ---- */
.dti-chat__composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--dc-line); }
.dti-chat__hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.dti-chat__attach { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; cursor: pointer; color: inherit; opacity: .65; }
.dti-chat__attach:hover { opacity: 1; background: var(--dc-soft); }
.dti-chat__composer textarea { resize: none; max-height: 110px; line-height: 1.4; border-radius: 18px; }
.dti-chat__send {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
    border: none; cursor: pointer; display: grid; place-items: center;
    background: var(--dc-accent); color: var(--dc-accent-ink);
    transition: transform .12s;
}
.dti-chat__send:hover { transform: scale(1.06); }
.dti-chat__send:disabled { opacity: .4; cursor: default; transform: none; }

.dti-chat__attach-preview { padding: 0 14px 10px; font-size: 12px; opacity: .8; display: flex; align-items: center; gap: 8px; }
.dti-chat__attach-preview button { border: none; background: transparent; cursor: pointer; color: inherit; font-size: 15px; }
.dti-chat__notice { margin: 0; padding: 0 14px 12px; font-size: 12px; opacity: .7; }
.dti-chat__notice--error { color: #B91C1C; opacity: 1; }

/* ---- Mobile: full-screen sheet ---- */
@media (max-width: 600px) {
    .dti-chat { right: 12px; bottom: 12px; }
    .dti-chat__panel {
        position: fixed; inset: 0; width: 100vw; height: 100dvh;
        border-radius: 0; border: none;
    }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    .dti-chat__launcher, .dti-chat__send, .dti-chat__btn, .dti-chat__react-menu button { transition: none; }
    .dti-chat__launcher:hover, .dti-chat__send:hover, .dti-chat__btn:hover { transform: none; }
    .dti-chat__launcher { animation: none; }
    .dti-chat__launcher::after { animation: none; opacity: 0; }
}

/* ---- Print ---- */
@media print { .dti-chat { display: none !important; } }
