:root {
    --cc-primary: #1d4ed8;
    --cc-primary-dark: #1e3a8a;
    --cc-primary-soft: rgba(29, 78, 216, 0.12);
    --cc-bg: #ffffff;
    --cc-bg-soft: #f8fafc;
    --cc-surface: rgba(255, 255, 255, 0.94);
    --cc-surface-strong: rgba(255, 255, 255, 0.98);
    --cc-text: #0f172a;
    --cc-text-soft: #475569;
    --cc-border: #dbe4f0;
    --cc-border-strong: rgba(148, 163, 184, 0.34);
    --cc-shadow: 0 28px 60px rgba(15, 23, 42, 0.18);
    --cc-shadow-soft: 0 12px 30px rgba(15, 23, 42, 0.12);
    --cc-radius-lg: 28px;
    --cc-radius-md: 18px;
    --cc-radius-sm: 14px;
    --cc-z: 999999;
    --cc-win-w: min(420px, calc(100vw - 84px));
    --cc-win-h: min(680px, calc(100vh - 80px));
    --cc-notch-w: 68px;
    --cc-notch-h: 172px;
    --cc-font: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
    --cc-header-bg: linear-gradient(160deg, var(--cc-primary-dark), var(--cc-primary));
}

#civic-chatbot-root {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    z-index: var(--cc-z);
    font-family: var(--cc-font);
    font-size: 15px;
    line-height: 1.55;
    box-sizing: border-box;
}

#civic-chatbot-root *,
#civic-chatbot-root *::before,
#civic-chatbot-root *::after {
    box-sizing: inherit;
}

.cc-widget--right-center {
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

.cc-notch-toggle {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: var(--cc-notch-w);
    min-height: var(--cc-notch-h);
    margin-right: 0;
    padding: 18px 12px 18px 10px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-right: none;
    border-radius: 26px 0 0 26px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.94), rgba(30, 58, 138, 0.98));
    color: #ffffff;
    box-shadow: var(--cc-shadow-soft);
    cursor: pointer;
    overflow: hidden;
    transition: width 0.24s ease, transform 0.24s ease, box-shadow 0.24s ease;
}

.cc-notch-toggle:hover,
.cc-notch-toggle:focus-visible,
.cc-notch-toggle--open {
    width: 78px;
    box-shadow: var(--cc-shadow);
}

.cc-notch-toggle:focus-visible {
    outline: 3px solid rgba(191, 219, 254, 0.86);
    outline-offset: 3px;
}

.cc-notch-toggle__edge {
    position: absolute;
    top: 18px;
    left: 0;
    width: 4px;
    height: calc(100% - 36px);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(191, 219, 254, 0.65));
}

.cc-notch-toggle__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.12);
    flex-shrink: 0;
}

.cc-notch-toggle__label {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
}

.cc-chat-window {
    position: absolute;
    top: 50%;
    right: calc(100% + 16px);
    width: var(--cc-win-w);
    height: var(--cc-win-h);
    display: flex;
    flex-direction: column;
    border-radius: var(--cc-radius-lg);
    border: 1px solid var(--cc-border-strong);
    background: var(--cc-surface);
    backdrop-filter: blur(18px);
    box-shadow: var(--cc-shadow);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) translateX(22px) scale(0.97);
    transform-origin: center right;
    transition: opacity 0.24s ease, transform 0.28s ease;
}

.cc-chat-window--open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(-50%) translateX(0) scale(1);
}

.cc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    color: #ffffff;
    background: var(--cc-header-bg);
}

.cc-header__lead {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.cc-header__titles {
    min-width: 0;
}

.cc-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.cc-header-title {
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.cc-header-subtitle {
    margin-top: 2px;
    font-size: 0.79rem;
    opacity: 0.86;
}

.cc-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cc-close-btn,
.cc-clear-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.cc-close-btn:hover,
.cc-clear-btn:hover,
.cc-close-btn:focus-visible,
.cc-clear-btn:focus-visible {
    background: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.cc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background:
        radial-gradient(circle at top right, rgba(29, 78, 216, 0.08), transparent 28%),
        linear-gradient(180deg, rgba(248, 250, 252, 0.96), rgba(255, 255, 255, 0.96));
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.54) transparent;
}

.cc-messages::-webkit-scrollbar {
    width: 6px;
}

.cc-messages::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.46);
}

.cc-msg {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 90%;
}

.cc-msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.cc-msg--bot {
    align-self: flex-start;
}

.cc-msg-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: var(--cc-header-bg);
    color: #ffffff;
    flex-shrink: 0;
}

.cc-msg-content-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cc-msg-bubble {
    padding: 14px 16px;
    border-radius: var(--cc-radius-md);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
    word-break: break-word;
}

.cc-msg--bot .cc-msg-bubble {
    background: var(--cc-surface-strong);
    color: var(--cc-text);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-bottom-left-radius: 8px;
}

.cc-msg--user .cc-msg-bubble {
    background: linear-gradient(180deg, var(--cc-primary), #2563eb);
    color: #ffffff;
    border-bottom-right-radius: 8px;
}

.cc-msg-text {
    color: inherit;
}

.cc-msg-text p {
    margin: 0 0 10px;
}

.cc-msg-text p:last-child {
    margin-bottom: 0;
}

.cc-msg-text ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

.cc-msg-text li {
    margin-bottom: 4px;
}

.cc-msg-text a {
    color: var(--cc-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cc-msg--user .cc-msg-text a {
    color: #ffffff;
}

.cc-msg-badge {
    display: inline-flex;
    align-items: center;
    margin-bottom: 8px;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.16);
    color: #b45309;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cc-sources {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(226, 232, 240, 0.95);
}

.cc-sources-title {
    margin: 0 0 6px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cc-text-soft);
}

.cc-sources-list {
    margin: 0;
    padding-left: 18px;
}

.cc-sources-list li {
    margin-bottom: 4px;
    font-size: 0.82rem;
    color: var(--cc-text-soft);
}

.cc-msg-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 2px;
}

.cc-msg--user .cc-msg-footer {
    justify-content: flex-end;
}

.cc-msg-time {
    font-size: 0.68rem;
    color: #64748b;
}

.cc-msg-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.cc-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
    padding: 0 7px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.cc-action-btn:hover,
.cc-action-btn:focus-visible {
    background: rgba(148, 163, 184, 0.12);
    color: var(--cc-primary);
}

.cc-action-btn:disabled {
    cursor: default;
    opacity: 0.85;
}

.cc-thumb-active {
    background: rgba(22, 163, 74, 0.14);
    color: #15803d;
}

.cc-thumb-down-active {
    background: rgba(220, 38, 38, 0.12);
    color: #b91c1c;
}

.cc-typing {
    display: flex;
    gap: 6px;
    align-items: center;
    min-height: 50px;
}

.cc-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cc-primary);
    opacity: 0.35;
    animation: cc-dot-bounce 1s ease-in-out infinite;
}

.cc-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.cc-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes cc-dot-bounce {
    0%,
    100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    50% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

.cc-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 176px;
    padding: 12px 16px;
    background: rgba(248, 250, 252, 0.96);
    border-top: 1px solid rgba(226, 232, 240, 0.96);
    overflow-y: auto;
}

.cc-suggestion-item {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: #ffffff;
    color: var(--cc-text);
    text-align: left;
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.cc-suggestion-item:hover,
.cc-suggestion-item:focus-visible {
    transform: translateX(2px);
    border-color: rgba(59, 130, 246, 0.32);
    background: #eff6ff;
}

.cc-form {
    padding: 14px 16px 16px;
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid rgba(226, 232, 240, 0.96);
}

.cc-input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.cc-input {
    flex: 1;
    min-height: 50px;
    max-height: 132px;
    padding: 13px 16px;
    border: 1px solid var(--cc-border);
    border-radius: 18px;
    background: var(--cc-bg-soft);
    color: var(--cc-text);
    resize: none;
    font: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.cc-input:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 4px rgba(191, 219, 254, 0.55);
    background: #ffffff;
}

.cc-input::placeholder {
    color: #94a3b8;
}

.cc-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 16px;
    background: var(--cc-header-bg);
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.25);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cc-send-btn:hover:not(:disabled),
.cc-send-btn:focus-visible:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px rgba(37, 99, 235, 0.28);
}

.cc-send-btn:disabled {
    background: #cbd5e1;
    color: #64748b;
    cursor: not-allowed;
    box-shadow: none;
}

.cc-char-counter {
    margin-top: 6px;
    padding-right: 62px;
    font-size: 0.72rem;
    color: #64748b;
    text-align: right;
}

.cc-modal {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.cc-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.28);
    backdrop-filter: blur(2px);
}

.cc-modal-content {
    position: relative;
    width: min(320px, calc(100% - 32px));
    padding: 24px;
    border-radius: 24px;
    background: #ffffff;
    box-shadow: var(--cc-shadow);
}

.cc-modal-text {
    margin: 0 0 18px;
    color: var(--cc-text);
    font-weight: 600;
}

.cc-modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.cc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: none;
    border-radius: 14px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.cc-btn--secondary {
    background: #e2e8f0;
    color: var(--cc-text);
}

.cc-btn--danger {
    background: #dc2626;
    color: #ffffff;
}

@media (max-width: 900px) {
    :root {
        --cc-win-w: min(390px, calc(100vw - 72px));
        --cc-win-h: min(620px, calc(100vh - 60px));
    }
}

@media (max-width: 640px) {
    #civic-chatbot-root {
        top: auto;
        right: 14px;
        bottom: 14px;
        transform: none;
    }

    .cc-notch-toggle {
        width: 62px;
        min-height: 62px;
        padding: 0;
        border-right: 1px solid rgba(255, 255, 255, 0.24);
        border-radius: 20px;
        justify-content: center;
    }

    .cc-notch-toggle__edge,
    .cc-notch-toggle__label {
        display: none;
    }

    .cc-chat-window {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        right: 0;
        top: 0;
        transform: translateY(100%);
    }

    .cc-chat-window--open {
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cc-notch-toggle,
    .cc-chat-window,
    .cc-send-btn,
    .cc-suggestion-item,
    .cc-action-btn,
    .cc-typing span {
        transition: none !important;
        animation: none !important;
    }
}
