/* ============================================
   IC&SR Chat - Full Page Embedded Style
   For iframe embedding on icandsr.iitm.ac.in
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Formal Institutional Light Theme Palette */
    --icsr-primary: #003366;
    /* Deep Institutional Navy */
    --icsr-primary-dark: #001F3F;
    /* Very Dark Navy */
    --icsr-primary-light: #00509E;
    /* Accessible Blue */

    --icsr-accent: #C5A059;
    /* Academic Gold */
    --icsr-accent-glow: rgba(197, 160, 89, 0.25);

    --icsr-bg-dark: #F3F4F6;
    /* Very Soft Gray for Container Base */
    --icsr-bg-card: #FFFFFF;
    /* Crisp White for Cards/Bubbles */
    --icsr-bg-input: #FFFFFF;
    /* Crisp White Input */

    --icsr-text-primary: #111827;
    /* High-Contrast Dark */
    --icsr-text-secondary: #374151;
    /* Solid Gray */
    --icsr-text-muted: #6B7280;
    /* Subdued Gray */

    --icsr-border: #D1D5DB;
    /* Clean Structured Border */
    --icsr-radius-sm: 6px;
    /* Sharper, formal corners */
    --icsr-radius-msg: 12px;
    /* Moderately rounded for chat, not overly bubbled */
    --icsr-transition: all 0.25s ease-in-out;
    --icsr-font-scale: 1;
}

/* ---------- Reset & Full Page ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background: var(--icsr-bg-dark);
}

/* ---------- Chat Container (fills entire page) ---------- */
#icsr-chat-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--icsr-bg-dark);
}

/* ---------- Header ---------- */
.icsr-chat-header {
    background: linear-gradient(135deg, var(--icsr-primary), var(--icsr-primary-dark));
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.icsr-chat-header::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, rgba(232, 168, 23, 0.15) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.icsr-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--icsr-accent), #D4940A);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--icsr-primary-dark);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(232, 168, 23, 0.3);
}

.icsr-header-info {
    flex: 1;
    min-width: 0;
}

.icsr-header-title {
    font-family: 'Inter', sans-serif;
    font-size: calc(15px * var(--icsr-font-scale));
    font-weight: 600;
    color: #fff;
    margin: 0;
    line-height: 1.3;
    transition: var(--icsr-transition);
}

.icsr-header-subtitle {
    font-family: 'Inter', sans-serif;
    font-size: calc(11.5px * var(--icsr-font-scale));
    color: rgba(255, 255, 255, 0.7);
    margin: 2px 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--icsr-transition);
}

/* ---------- Font Controls ---------- */
.icsr-font-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    z-index: 10;
}

.icsr-font-controls button {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.75);
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 14px;
    cursor: pointer;
    transition: var(--icsr-transition);
}

.icsr-font-controls button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

.icsr-font-controls button.active {
    color: var(--icsr-primary-dark);
    background: var(--icsr-accent);
    box-shadow: 0 2px 6px rgba(232, 168, 23, 0.3);
}

.icsr-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #48BB78;
    display: inline-block;
    animation: icsr-blink 2s infinite;
}

@keyframes icsr-blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ---------- Messages Area ---------- */
.icsr-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    background: var(--icsr-bg-dark);
}

.icsr-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.icsr-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.icsr-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

/* ---------- Message Bubbles ---------- */
.icsr-message {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 85%;
    min-width: 0;
    animation: icsr-fadeIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.icsr-message.bot {
    align-self: flex-start;
}

.icsr-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.icsr-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    margin-top: 2px;
}

.icsr-message.bot .icsr-msg-avatar {
    background: linear-gradient(135deg, var(--icsr-accent), #D4940A);
    color: var(--icsr-primary-dark);
}

.icsr-message.user .icsr-msg-avatar {
    background: linear-gradient(135deg, #667EEA, #764BA2);
    color: white;
}

.icsr-msg-bubble {
    padding: 12px 16px;
    font-family: 'Inter', sans-serif;
    font-size: calc(13.5px * var(--icsr-font-scale));
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 0;
    position: relative;
    transition: font-size 0.2s ease, padding 0.2s ease;
}

.icsr-message.bot .icsr-msg-bubble {
    background: var(--icsr-bg-card);
    color: var(--icsr-text-primary);
    border-radius: 4px var(--icsr-radius-msg) var(--icsr-radius-msg) var(--icsr-radius-msg);
    border: 1px solid var(--icsr-border);
}

.icsr-message.user .icsr-msg-bubble {
    background: linear-gradient(135deg, var(--icsr-primary), var(--icsr-primary-light));
    color: #fff;
    border-radius: var(--icsr-radius-msg) 4px var(--icsr-radius-msg) var(--icsr-radius-msg);
}

.icsr-msg-bubble a {
    color: var(--icsr-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
}

.icsr-msg-bubble a:hover {
    color: #F0C040;
}

.icsr-msg-bubble ul,
.icsr-msg-bubble ol {
    margin: 6px 0;
    padding-left: 18px;
}

.icsr-msg-bubble li {
    margin: 1px 0;
}

.icsr-msg-bubble strong,
.icsr-msg-bubble b {
    color: var(--icsr-primary);
    font-weight: 600;
}

.icsr-msg-bubble p {
    margin-bottom: 12px;
}

.icsr-msg-bubble p:last-child {
    margin-bottom: 0;
}

.icsr-msg-bubble br {
    display: block;
    margin-bottom: 8px;
    content: "";
    /* Some browsers need content to render block br */
}

@keyframes icsr-fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---------- Edit Button (ChatGPT Style) ---------- */
.icsr-message-actions {
    display: flex;
    flex-shrink: 0;
    gap: 4px;
    margin-left: 8px;
    margin-top: 0px;
    opacity: 0.55;
    transition: var(--icsr-transition);
}

.icsr-message.user:hover .icsr-message-actions,
.icsr-message.user:focus-within .icsr-message-actions {
    opacity: 1;
}

.icsr-edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    color: var(--icsr-text-muted);
    transition: var(--icsr-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.icsr-edit-btn::before {
    content: '';
    width: 14px;
    height: 14px;
    display: block;
    background-color: currentColor;
    -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>');
    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>');
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

.icsr-edit-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.icsr-edit-btn:active {
    transform: scale(0.95);
}

/* ---------- Typing Indicator ---------- */
.icsr-typing {
    display: flex;
    align-self: flex-start;
    max-width: 85%;
    animation: icsr-fadeIn 0.3s ease;
}

.icsr-typing .icsr-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--icsr-accent), #D4940A);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--icsr-primary-dark);
    flex-shrink: 0;
}

.icsr-typing-dots {
    padding: 14px 18px;
    background: var(--icsr-bg-card);
    border-radius: 4px var(--icsr-radius-msg) var(--icsr-radius-msg) var(--icsr-radius-msg);
    border: 1px solid var(--icsr-border);
    display: flex;
    gap: 5px;
    align-items: center;
}

.icsr-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--icsr-text-muted);
    animation: icsr-bounce 1.4s infinite ease-in-out both;
}

.icsr-typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.icsr-typing-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.icsr-typing-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes icsr-bounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ---------- Quick Replies ---------- */
.icsr-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
    animation: icsr-fadeIn 0.5s ease;
    flex-shrink: 0;
}

.icsr-quick-btn {
    padding: 8px 14px;
    font-family: 'Inter', sans-serif;
    font-size: calc(12px * var(--icsr-font-scale));
    font-weight: 500;
    color: var(--icsr-primary);
    background: rgba(139, 26, 26, 0.05);
    border: 1px solid rgba(139, 26, 26, 0.2);
    border-radius: 20px;
    cursor: pointer;
    transition: var(--icsr-transition);
    white-space: nowrap;
}

.icsr-quick-btn:hover {
    background: rgba(139, 26, 26, 0.1);
    border-color: var(--icsr-primary);
    transform: translateY(-1px);
}

/* ---------- Input Area ---------- */
.icsr-chat-input-area {
    padding: 14px 16px;
    background: var(--icsr-bg-dark);
    border-top: 1px solid var(--icsr-border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.icsr-input-wrapper {
    flex: 1;
    position: relative;
}

#icsr-chat-input {
    width: 100%;
    padding: 12px 16px;
    font-family: 'Inter', sans-serif;
    font-size: calc(13.5px * var(--icsr-font-scale));
    color: var(--icsr-text-primary);
    background: var(--icsr-bg-input);
    border: 1px solid var(--icsr-border);
    border-radius: var(--icsr-radius-sm);
    outline: none;
    resize: none;
    max-height: 48px;
    /* line-height: 1.5; */
    transition: var(--icsr-transition);
    box-sizing: border-box;
}

#icsr-chat-input::placeholder {
    color: var(--icsr-text-muted);
}

#icsr-chat-input:focus {
    border-color: var(--icsr-accent);
    box-shadow: 0 0 0 3px var(--icsr-accent-glow);
}

#icsr-send-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--icsr-radius-sm);
    background: linear-gradient(135deg, var(--icsr-primary), var(--icsr-primary-light));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--icsr-transition);
    flex-shrink: 0;
}

#icsr-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(139, 26, 26, 0.4);
}

#icsr-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#icsr-send-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* ---------- Powered By Footer ---------- */
.icsr-powered-by {
    text-align: center;
    padding: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 10px;
    color: var(--icsr-text-muted);
    background: var(--icsr-bg-dark);
    border-top: 1px solid var(--icsr-border);
    flex-shrink: 0;
}

.icsr-powered-by a {
    color: var(--icsr-primary);
    text-decoration: none;
    font-weight: 500;
}
/* ============================================
   Context dropdown (moved here from main.html so every embed gets it)
   ============================================ */
#icsr-context-select {
    padding: 0 40px 0 16px;
    border-radius: var(--icsr-radius-sm);
    border: 2px solid var(--icsr-primary-light);
    background-color: var(--icsr-bg-card);
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: calc(14px * var(--icsr-font-scale, 1));
    color: var(--icsr-primary-dark);
    outline: none;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 51, 102, 0.1);
    transition: var(--icsr-transition);
    margin-right: 4px;
    height: 46px;
    min-width: 170px;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg width="12" height="8" viewBox="0 0 12 8" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1.5L6 6.5L11 1.5" stroke="%2300509E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>');
    background-repeat: no-repeat;
    background-position: right 16px center;
}

#icsr-context-select:focus {
    border-color: var(--icsr-primary-light);
    box-shadow: 0 0 0 3px rgba(0, 80, 158, 0.15);
    background-color: #FFFFFF;
}

#icsr-context-select:hover {
    border-color: #9CA3AF;
}

#icsr-context-select option {
    background-color: #FFFFFF;
    color: #111827;
}

/* Input box: always at least as tall as the send button, grows up to 3 lines */
#icsr-chat-input {
    height: 46px;
    min-height: 46px;
    max-height: 96px;
    display: block;
}

.icsr-input-wrapper {
    min-width: 0;
}

/* ============================================
   RESPONSIVE — one layout that stays neat from a small popup widget
   up to a full browser page (subdomain). Works inside an iframe because
   media queries see the iframe's own width/height.
   ============================================ */

/* Never let anything force a sideways scrollbar */
#icsr-chat-container,
.icsr-chat-messages {
    overflow-x: hidden;
}

.icsr-msg-bubble img,
.icsr-msg-bubble table {
    max-width: 100%;
}

/* ---- Large / full page (>= 900px): keep lines readable ---- */
@media (min-width: 900px) {
    .icsr-chat-header {
        padding: 16px 32px;
    }

    .icsr-chat-messages {
        padding: 24px max(32px, calc((100% - 1100px) / 2));
    }

    .icsr-message,
    .icsr-typing {
        max-width: 70%;
    }

    .icsr-quick-replies {
        justify-content: center;
        padding: 0 32px 14px;
    }

    .icsr-chat-input-area {
        padding: 16px max(32px, calc((100% - 1100px) / 2));
    }
}

/* ---- Small popup / narrow iframe / phone (<= 560px) ---- */
@media (max-width: 560px) {
    .icsr-chat-header {
        padding: 10px 12px;
        gap: 10px;
    }

    .icsr-header-avatar {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }

    .icsr-header-title {
        font-size: calc(14px * var(--icsr-font-scale));
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .icsr-font-controls button {
        padding: 3px 6px;
        font-size: 10px;
    }

    #icsr-refresh-btn {
        margin-left: 4px !important;
    }

    .icsr-chat-messages {
        padding: 12px 10px;
        gap: 10px;
    }

    .icsr-message,
    .icsr-typing {
        max-width: 94%;
    }

    .icsr-msg-bubble {
        padding: 10px 12px;
    }

    /* Suggestions: allow wrapping inside the chip instead of overflowing */
    .icsr-quick-replies {
        padding: 0 10px 8px;
        gap: 6px;
    }

    .icsr-quick-btn {
        white-space: normal;
        text-align: left;
        padding: 7px 12px;
    }

    /* Input row: dropdown gets its own full-width line, input + send share the next */
    .icsr-chat-input-area {
        flex-wrap: wrap;
        padding: 10px;
        gap: 8px;
        align-items: stretch;
    }

    #icsr-context-select {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
        margin: 0;
        height: 42px;
    }

    .icsr-input-wrapper {
        flex: 1 1 0;
    }

    #icsr-chat-input {
        height: 42px;
        min-height: 42px;
    }

    #icsr-send-btn {
        width: 42px;
        height: 42px;
        align-self: flex-end;
    }
}

/* ---- Very narrow (<= 360px) ---- */
@media (max-width: 360px) {
    .icsr-header-avatar {
        display: none;
    }

    .icsr-font-controls {
        display: none;
    }
}

/* ---- Short frame (<= 520px tall): win back vertical space ---- */
@media (max-height: 520px) {
    .icsr-chat-header {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .icsr-chat-messages {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .icsr-quick-replies {
        padding-bottom: 6px;
    }

    .icsr-chat-input-area {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .icsr-powered-by {
        padding: 3px;
    }
}

/* ============================================
   Compact topic menu + suggestion cards
   (the ≡ button replaces the wide dropdown on narrow widths, like a
   chat popup; wide / full-page layouts keep the dropdown)
   ============================================ */
.icsr-chat-input-area {
    position: relative;
}

#icsr-menu-btn,
#icsr-menu-pop {
    display: none;
}

#icsr-menu-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: var(--icsr-radius-sm);
    border: 2px solid var(--icsr-primary-light);
    background: var(--icsr-bg-card);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: var(--icsr-transition);
}

#icsr-menu-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: var(--icsr-primary-light);
    stroke-width: 2.4;
    stroke-linecap: round;
}

#icsr-menu-btn:hover,
#icsr-menu-btn[aria-expanded="true"] {
    background: var(--icsr-primary-light);
}

#icsr-menu-btn:hover svg,
#icsr-menu-btn[aria-expanded="true"] svg {
    stroke: #fff;
}

#icsr-menu-pop {
    position: absolute;
    left: 10px;
    bottom: calc(100% - 4px);
    min-width: 190px;
    max-width: calc(100% - 20px);
    background: var(--icsr-bg-card);
    border: 1px solid var(--icsr-border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 31, 63, 0.18);
    padding: 6px;
    z-index: 20;
    flex-direction: column;
    gap: 2px;
}

#icsr-menu-pop button {
    text-align: left;
    padding: 10px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-family: 'Inter', sans-serif;
    font-size: calc(13.5px * var(--icsr-font-scale));
    font-weight: 500;
    color: var(--icsr-text-primary);
    cursor: pointer;
}

#icsr-menu-pop button:hover {
    background: rgba(0, 80, 158, 0.08);
}

#icsr-menu-pop button.active {
    background: rgba(0, 80, 158, 0.12);
    color: var(--icsr-primary-dark);
    font-weight: 700;
}

/* Suggestion cards: white card, same palette as the rest of the widget */
.icsr-quick-btn {
    background: var(--icsr-bg-card);
    border: 1px solid rgba(0, 80, 158, 0.25);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 31, 63, 0.06);
}

.icsr-quick-btn:hover {
    background: rgba(0, 80, 158, 0.05);
    border-color: var(--icsr-primary-light);
}

@media (max-width: 560px) {
    /* ≡ button instead of the full-width dropdown row */
    #icsr-context-select {
        display: none;
    }

    #icsr-menu-btn {
        display: flex;
    }

    #icsr-menu-pop:not([hidden]) {
        display: flex;
    }

    .icsr-chat-input-area {
        flex-wrap: nowrap;
        align-items: flex-end;
    }

    .icsr-input-wrapper {
        flex: 1 1 0;
        min-width: 0;
    }

    /* Suggestions stack as full-width cards */
    .icsr-quick-replies {
        flex-direction: column;
        align-items: stretch;
    }

    .icsr-quick-btn {
        width: 100%;
        text-align: center;
        padding: 10px 12px;
    }
}

/* Header logo (replaces the "AI" text badge) */
.icsr-header-avatar {
    background: #fff;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.icsr-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
