/* ============================================
   Agent AI CzasNaWnetrze - Chat Widget Styles
   Dark theme matching brand design
   ============================================ */

:root {
    --cnw-primary: #1a1a1a;
    --cnw-primary-hover: #333333;
    --cnw-accent: #8B1A1A;
    --cnw-accent-hover: #a52222;
    --cnw-bg-window: #f5f5f5;
    --cnw-bg-msg-agent: #ffffff;
    --cnw-bg-msg-user: #1a1a1a;
    --cnw-text-main: #1a1a1a;
    --cnw-text-agent: #1a1a1a;
    --cnw-text-user: #ffffff;
    --cnw-text-muted: #888888;
    --cnw-border: #e0e0e0;
    --cnw-input-bg: #ffffff;
    --cnw-shadow: 0 5px 25px rgba(0,0,0,0.2);
    --cnw-radius: 16px;
    --cnw-promo-bg: #f9f5f0;
    --cnw-promo-border: #e0d5c8;
    --cnw-promo-label: #8B6914;
    --cnw-font: 'Roboto', Arial, sans-serif;
}

/* Lock body scroll when chat is open on mobile */
html.cnw-chat-open,
html.cnw-chat-open body {
    overflow: hidden !important;
    height: 100%;
}

/* Container */
#cnw-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: var(--cnw-font);
}

/* Launcher button */
#cnw-launcher {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--cnw-primary);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 28px;
    line-height: 1;
}

#cnw-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#cnw-launcher svg {
    width: 28px;
    height: 28px;
    fill: white;
}

/* Chat window */
#cnw-chat-window {
    display: none;
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 460px;
    max-width: calc(100vw - 24px);
    height: 720px;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
    background: var(--cnw-bg-window);
    border-radius: var(--cnw-radius);
    box-shadow: var(--cnw-shadow);
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease, height 0.3s ease, bottom 0.3s ease, right 0.3s ease;
}

#cnw-chat-window.open {
    display: flex;
}

/* Header - dark/black */
#cnw-header {
    background: var(--cnw-primary);
    color: white;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#cnw-header-title {
    font-size: 15px;
    font-weight: 600;
}

#cnw-header-subtitle {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 2px;
}

#cnw-header-actions {
    display: flex;
    gap: 8px;
}

#cnw-header-actions button {
    background: #3a3a3a;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: opacity 0.15s, background 0.15s;
    line-height: 1;
}

#cnw-header-actions button:hover {
    opacity: 1;
    background: #555;
}

/* Messages area */
#cnw-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--cnw-bg-window);
}

#cnw-messages::-webkit-scrollbar {
    width: 6px;
}

#cnw-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Message bubbles */
.cnw-msg {
    max-width: 90%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
}

.cnw-msg.agent {
    align-self: flex-start;
    background: var(--cnw-bg-msg-agent);
    color: var(--cnw-text-agent);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.cnw-msg.user {
    align-self: flex-end;
    background: var(--cnw-bg-msg-user);
    color: var(--cnw-text-user);
    border-bottom-right-radius: 4px;
}

/* Status / typing indicator */
.cnw-msg.status {
    align-self: flex-start;
    background: var(--cnw-bg-msg-agent);
    color: var(--cnw-text-muted);
    font-style: italic;
    font-size: 13px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.cnw-typing-dots span {
    animation: cnwBlink 1.4s infinite both;
    font-size: 16px;
}
.cnw-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.cnw-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cnwBlink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* ==========================================
   Promo section (sponsored articles)
   ========================================== */
.cnw-promo-section {
    background: var(--cnw-promo-bg);
    border: 1px solid var(--cnw-promo-border);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.cnw-promo-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--cnw-promo-label);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ==========================================
   Article cards
   ========================================== */
.cnw-article-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 0;
}

.cnw-article-card {
    display: flex;
    gap: 10px;
    background: white;
    border: 1px solid var(--cnw-border);
    border-radius: 10px;
    padding: 10px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s, border-color 0.15s;
    cursor: pointer;
}

.cnw-article-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-color: var(--cnw-primary);
}

.cnw-promo-section .cnw-article-card {
    background: #fdfaf5;
}

.cnw-card-img {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #eee;
}

.cnw-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.cnw-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--cnw-text-main);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cnw-card-intro {
    font-size: 12px;
    color: var(--cnw-text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cnw-card-meta {
    font-size: 11px;
    color: #aaa;
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: auto;
}

.cnw-card-meta span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================
   Page block
   ========================================== */
.cnw-page-block {
    margin-top: 10px;
    padding-top: 8px;
}

.cnw-page-block + .cnw-page-block {
    border-top: 1px solid var(--cnw-border);
}

.cnw-no-more {
    text-align: center;
    font-size: 12px;
    color: var(--cnw-text-muted);
    padding: 10px 0 2px;
}

/* ==========================================
   Show more button
   ========================================== */
.cnw-show-more {
    display: block;
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    background: #f0f0f0;
    color: var(--cnw-primary);
    border: 1px solid var(--cnw-primary);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s;
}

.cnw-show-more:hover {
    background: #e0e0e0;
}

/* ==========================================
   Suggestion chips
   ========================================== */
.cnw-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.cnw-suggestion-chip {
    padding: 6px 12px;
    background: white;
    border: 1px solid var(--cnw-primary);
    border-radius: 16px;
    font-size: 12px;
    color: var(--cnw-primary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: normal;
    word-break: break-word;
}

.cnw-suggestion-chip:hover {
    background: var(--cnw-primary);
    color: white;
}

/* ==========================================
   Category browser (welcome screen)
   ========================================== */
.cnw-msg:has(.cnw-category-browser) {
    width: 95%;
    max-width: 95%;
}

.cnw-category-browser {
    margin-top: 12px;
    display: flex;
    gap: 0;
    border: 1px solid var(--cnw-border);
    border-radius: 10px;
    overflow: hidden;
    background: white;
}

.cnw-category-tabs {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--cnw-border);
    background: #fafafa;
}

.cnw-category-tab {
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--cnw-text-muted);
    cursor: pointer;
    border: none;
    background: none;
    white-space: nowrap;
    text-align: left;
    transition: color 0.15s, background 0.15s;
    font-family: var(--cnw-font);
    position: relative;
}

.cnw-category-tab:hover {
    color: var(--cnw-primary);
    background: #f0f0f0;
}

.cnw-category-tab.active {
    color: var(--cnw-primary);
    background: #eaeaea;
}

.cnw-category-tab.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--cnw-primary);
}

.cnw-category-list {
    flex: 1;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    max-height: 310px;
}

.cnw-category-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--cnw-primary);
    cursor: pointer;
    border: none;
    background: none;
    font-family: var(--cnw-font);
    transition: background 0.15s;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cnw-category-item:hover {
    background: #eaeaea;
}

/* ==========================================
   Input area
   ========================================== */
#cnw-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--cnw-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--cnw-bg-window);
}

#cnw-input {
    flex: 1;
    border: 1px solid var(--cnw-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 16px;
    font-family: var(--cnw-font);
    resize: none;
    max-height: 80px;
    line-height: 1.4;
    outline: none;
    background: var(--cnw-input-bg);
    transition: border-color 0.15s;
}

#cnw-input:focus {
    border-color: var(--cnw-primary);
}

#cnw-input::placeholder {
    color: #bbb;
}

#cnw-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--cnw-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

#cnw-send-btn:hover {
    background: var(--cnw-primary-hover);
}

#cnw-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#cnw-send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* ==========================================
   Expanded mode (~3/4 of viewport)
   ========================================== */
#cnw-chat-window.expanded {
    width: 75vw;
    height: 80vh;
    max-height: 80vh;
    bottom: 10vh;
    right: 12.5vw;
    border-radius: var(--cnw-radius);
    transition: width 0.3s ease, height 0.3s ease, bottom 0.3s ease, right 0.3s ease;
}

#cnw-chat-window.expanded .cnw-article-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

#cnw-chat-window.expanded .cnw-article-card {
    flex-direction: column;
}

#cnw-chat-window.expanded .cnw-card-img {
    width: 100%;
    height: 140px;
    border-radius: 8px 8px 0 0;
}

#cnw-chat-window.expanded .cnw-msg {
    max-width: 80%;
}

#cnw-chat-window.expanded .cnw-promo-section .cnw-article-cards {
    display: flex;
    flex-direction: column;
}

#cnw-chat-window.expanded .cnw-promo-section .cnw-article-card {
    flex-direction: row;
    max-width: 480px;
}

#cnw-chat-window.expanded .cnw-promo-section .cnw-card-img {
    width: 100px;
    height: 100px;
    border-radius: 8px;
}


/* ==========================================
   Fullscreen mode (standalone page)
   ========================================== */
#cnw-chat-window.fullscreen {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
}

#cnw-chat-window.fullscreen .cnw-article-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

#cnw-chat-window.fullscreen .cnw-article-card {
    flex-direction: column;
}

#cnw-chat-window.fullscreen .cnw-card-img {
    width: 100%;
    height: 140px;
    border-radius: 8px 8px 0 0;
}

#cnw-chat-window.fullscreen .cnw-msg {
    max-width: 70%;
}

#cnw-chat-window.fullscreen .cnw-promo-section .cnw-article-cards {
    display: flex;
    flex-direction: column;
}

#cnw-chat-window.fullscreen .cnw-promo-section .cnw-article-card {
    flex-direction: row;
    max-width: 480px;
}

#cnw-chat-window.fullscreen .cnw-promo-section .cnw-card-img {
    width: 100px;
    height: 100px;
    border-radius: 8px;
}

/* ==========================================
   Mobile responsive
   ========================================== */
@media (max-width: 640px) {
    #cnw-widget-container {
        bottom: 0;
        right: 0;
    }

    #cnw-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    #cnw-chat-window.expanded {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
    }

    #cnw-header {
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
        padding-left: calc(16px + env(safe-area-inset-left, 0px));
        padding-right: calc(16px + env(safe-area-inset-right, 0px));
    }

    #cnw-messages {
        padding: 12px;
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
    }

    #cnw-input-area {
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
    }

    #cnw-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    #cnw-launcher {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: calc(16px + env(safe-area-inset-right, 0px));
    }

    .cnw-msg {
        max-width: 95%;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .cnw-article-card {
        min-width: 0;
        max-width: 100%;
    }

    .cnw-card-body,
    .cnw-card-title,
    .cnw-card-intro,
    .cnw-text {
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .cnw-card-meta {
        flex-wrap: wrap;
    }

    .cnw-article-cards,
    .cnw-promo-section {
        max-width: 100%;
    }
}
@media(max-width: 575px) {
    .cnw-agent {
        margin: 0 -15px;
    }
}