/* SafeHomePro ACE widget — calm, modern, homeowner-first.
   Specificity kept low (:where) so Astra/theme can extend without !important. */

:where(.shpace) {
    --shpace-primary: #3B82F6;
    --shpace-primary-hover: #2563EB;
    --shpace-surface: #FFFFFF;
    --shpace-surface-alt: #F8FAFC;
    --shpace-text: #0F172A;
    --shpace-text-muted: #64748B;
    --shpace-border: #E2E8F0;
    --shpace-radius: 14px;
    --shpace-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
    --shpace-bubble-user: #DBEAFE;
    --shpace-bubble-bot: #F1F5F9;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--shpace-text);
    line-height: 1.5;
    box-sizing: border-box;
}

:where(.shpace) *,
:where(.shpace) *::before,
:where(.shpace) *::after {
    box-sizing: border-box;
}

/* --- Launcher --- */
:where(.shpace--launcher) {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

.shpace__launcher {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    background: var(--shpace-primary);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shpace-shadow);
    transition: background-color .15s ease, transform .15s ease;
}
.shpace__launcher:hover { background: var(--shpace-primary-hover); }
.shpace__launcher:active { transform: translateY(1px); }
.shpace__launcher-icon { font-size: 18px; }

/* --- Panel --- */
.shpace__panel {
    background: var(--shpace-surface);
    border: 1px solid var(--shpace-border);
    border-radius: var(--shpace-radius);
    box-shadow: var(--shpace-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.shpace--launcher .shpace__panel {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: min(380px, calc(100vw - 40px));
    height: min(560px, calc(100vh - 120px));
    z-index: 9999;
}

.shpace--inline .shpace__panel {
    width: 100%;
    max-width: 720px;
    height: 520px;
    margin: 0 auto;
}

/* --- Header --- */
.shpace__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--shpace-surface-alt);
    border-bottom: 1px solid var(--shpace-border);
}
.shpace__title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.shpace__title strong {
    font-size: 16px;
    color: var(--shpace-text);
    letter-spacing: -0.01em;
}
.shpace__subtitle {
    font-size: 12px;
    color: var(--shpace-text-muted);
}
.shpace__close {
    background: transparent;
    border: 0;
    font-size: 22px;
    line-height: 1;
    color: var(--shpace-text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
}
.shpace__close:hover { background: rgba(15, 23, 42, 0.06); color: var(--shpace-text); }

/* --- Messages --- */
.shpace__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--shpace-surface);
}

.shpace__msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14.5px;
    word-wrap: break-word;
}

.shpace__msg p { margin: 0 0 8px; }
.shpace__msg p:last-child { margin-bottom: 0; }
.shpace__msg h4 {
    margin: 4px 0 6px;
    font-size: 14px;
    font-weight: 700;
    color: var(--shpace-text);
}
.shpace__msg ul {
    margin: 4px 0 8px;
    padding-left: 18px;
}
.shpace__msg li { margin: 2px 0; }
.shpace__msg strong { font-weight: 600; }

.shpace__msg--user {
    align-self: flex-end;
    background: var(--shpace-bubble-user);
    color: var(--shpace-text);
    border-bottom-right-radius: 4px;
}
.shpace__msg--assistant {
    align-self: flex-start;
    background: var(--shpace-bubble-bot);
    color: var(--shpace-text);
    border-bottom-left-radius: 4px;
}

.shpace__msg--typing {
    color: var(--shpace-text-muted);
    font-style: italic;
}

/* --- Disclaimer --- */
.shpace__disclaimer {
    margin: 0;
    padding: 8px 16px;
    font-size: 11.5px;
    color: var(--shpace-text-muted);
    background: var(--shpace-surface-alt);
    border-top: 1px solid var(--shpace-border);
    line-height: 1.4;
}

/* --- Form --- */
.shpace__form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--shpace-border);
    background: var(--shpace-surface);
}
.shpace__input {
    flex: 1 1 auto;
    resize: none;
    padding: 10px 12px;
    border: 1px solid var(--shpace-border);
    border-radius: 10px;
    font: inherit;
    color: var(--shpace-text);
    background: var(--shpace-surface);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.shpace__input:focus {
    border-color: var(--shpace-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.shpace__send {
    padding: 0 16px;
    background: var(--shpace-primary);
    color: #fff;
    border: 0;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease;
}
.shpace__send:hover:not(:disabled) { background: var(--shpace-primary-hover); }
.shpace__send:disabled { opacity: .55; cursor: not-allowed; }

/* Screen-reader-only utility */
.shpace .screen-reader-text {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}

/* Mobile tweaks */
@media (max-width: 480px) {
    .shpace--launcher .shpace__panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        border-radius: 0;
    }
    .shpace__launcher-label { display: none; }
}
