/* Hyer Assistant Interface - Aligned with BL242 Consumer Web Styling */

/* Import Montserrat font */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    min-width: 320px;
    min-height: 100vh;
    position: fixed;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

body {
    font-size: 14px;
    line-height: 21px;
    color: #34323f;
    background-color: #f2f3f5;
    font-family: 'Montserrat', sans-serif;
    -ms-overflow-style: scrollbar;
    -webkit-font-smoothing: subpixel-antialiased;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

/* Utility Classes */
.fs-13 {
    font-size: 13px;
    line-height: 20px;
}

.fs-16 {
    font-size: 16px;
    line-height: 24px;
}

.fs-18 {
    font-size: 18px;
    line-height: 24px;
}

.fs-24 {
    font-size: 24px;
    line-height: 36px;
}

.text-dark-black {
    color: #414141;
}

.fw-medium {
    font-weight: 500;
}

.fw-semiBold {
    font-weight: 600;
}

.primary-color {
    color: #2f4050;
}

.text-grey {
    color: #6f7084;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-sizing: border-box;
    position: relative;
    overflow: auto;
}

/* Prefer dynamic viewport height on modern mobile browsers */
@supports (height: 100dvh) {
    .container {
        height: 100dvh;
        min-height: 100dvh;
    }
}

/* Header */
.main-header {
    background: #ffffff;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.header-icon-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #2f4050;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-icon-button:hover {
    background: #253243;
    transform: translateY(-1px);
}

.header-icon-button:focus-visible {
    outline: 2px solid #007aff;
    outline-offset: 2px;
}

.header-icon-button:active {
    transform: scale(0.97);
}

.header-icon-button svg,
.header-icon-button .header-icon {
    pointer-events: none;
    width: 20px;
    height: 20px;
    display: block;
}

.header-icon-button .header-icon {
    filter: brightness(0) invert(1);
}

.header-center {
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-logo-img {
    width: 100px;
    height: auto;
}

.header-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

/* User Dropdown */
.user-dropdown-container {
    position: relative;
}

.user-dropdown-trigger {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background-color 0.2s;
    font-family: 'Montserrat', sans-serif;
}

.user-dropdown-trigger:hover {
    background: #f8f9fa;
}

.user-dropdown-trigger .user-name {
    font-size: 14px;
    font-weight: 600;
    color: #2f4050;
}

.dropdown-arrow {
    font-size: 10px;
    color: #6f7084;
    transition: transform 0.2s;
}

.user-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 220px;
    z-index: 1000;
    overflow: hidden;
}

.dropdown-user-info {
    padding: 16px;
    background: #f8f9fa;
}

.dropdown-user-name {
    font-size: 14px;
    font-weight: 600;
    color: #2f4050;
    margin-bottom: 4px;
}

.dropdown-user-email {
    font-size: 13px;
    color: #6f7084;
}

.dropdown-divider {
    height: 1px;
    background: #dee2e6;
    margin: 0;
}

.dropdown-item {
    width: 100%;
    background: transparent;
    border: none;
    padding: 12px 16px;
    text-align: left;
    font-size: 14px;
    color: #34323f;
    cursor: pointer;
    transition: background-color 0.2s;
    font-family: 'Montserrat', sans-serif;
}

.dropdown-item:hover {
    background: #f8f9fa;
}

.dropdown-item span {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Controls Bar */
.controls-bar {
    background: #ffffff;
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.conversation-id {
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    color: #6f7084;
    display: inline-block;
}

.conversation-id-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.copy-btn {
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    color: #6f7084;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-btn:hover {
    background: #f8f9fa;
    border-color: #007AFF;
    color: #007AFF;
}

.copy-btn:active {
    transform: scale(0.95);
}

.copy-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.copy-btn:disabled:hover {
    background: transparent;
    border-color: #ddd;
    color: #6f7084;
}

.copy-btn.copied {
    background: #4CAF50;
    border-color: #4CAF50;
    color: white;
}

.copy-btn.copied svg {
    animation: checkmark 0.3s ease;
}

@keyframes checkmark {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    background-color: #dc3545;
    transition: background-color 0.2s ease;
}

.status-indicator.online {
    background-color: #28a745;
}

.status-indicator.offline {
    background-color: #dc3545;
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

/* Chat Section */
.chat-section {
    background: #ffffff;
    border-radius: 8px;
    padding: 20px;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    height: 100%;
}

/* Messages Container */
.messages {
    /* Flow messages from the top; container still fills available height */
    overflow-y: auto;
    padding: 10px 0 0 0; /* no bottom padding to eliminate gap */
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

/* Message Styles */
.message {
    margin-bottom: 15px;
    padding: 15px;
    border-radius: 8px;
    animation: slideIn 0.3s ease-out;
}

/* Reduce gap under the last message bubble */
.messages .message:last-child {
    margin-bottom: 0;
}

.message.user {
    background: #f0f7ff;
    border-left: 3px solid #2f4050;
    margin-left: 20px;
}

.message.assistant {
    background: #f8f9fa;
    border-left: 3px solid #557491;
    margin-right: 20px;
}

.message.system {
    background: #fff3cd;
    border-left: 3px solid #ffc107;
    text-align: center;
    font-size: 13px;
    color: #856404;
}

.message-content {
    margin-bottom: 5px;
    line-height: 1.5;
    color: #34323f;
}

.message-content strong {
    font-weight: 600;
    color: #2f4050;
}

.message-time {
    font-size: 11px;
    color: #6f7084;
    text-align: right;
}

/* Input Container */
.input-container {
    display: flex;
    gap: 10px;
    position: absolute;
    /* Lift slightly and respect iOS safe area */
    bottom: calc(36px + env(safe-area-inset-bottom, 0px));
    left: 20px;
    right: 20px;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Montserrat', sans-serif;
    outline: none;
    transition: border-color 0.2s;
    background: #ffffff;
    -webkit-appearance: none;
    appearance: none;
}

#messageInput:focus {
    border-color: #2f4050;
    box-shadow: 0 0 0 0.2rem rgba(47, 64, 80, 0.1);
}

#messageInput:disabled {
    background: #f8f9fa;
    color: #6c757d;
}

/* Button Styles */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Montserrat', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: #2f4050;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #557491;
}

.btn-send {
    background: #28a745;
    color: white;
    min-width: 80px;
}

.btn-send:hover:not(:disabled) {
    background: #218838;
}

.btn-secondary {
    background: #f8f9fa;
    color: #6f7084;
    font-size: 13px;
    padding: 8px 16px;
    border: 1px solid #dee2e6;
}

.btn-secondary:hover:not(:disabled) {
    background: #e9ecef;
    border-color: #adb5bd;
}

/* Debug Panel */
.debug-panel {
    background: #ffffff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    height: fit-content;
}

/* Admin-only debug items start hidden to avoid flicker for non-admins */
#llmModelItem,
#conversationCostItem {
    display: none;
}

.debug-panel h3 {
    color: #2f4050;
    margin-bottom: 15px;
    font-size: 18px;
    font-weight: 600;
}

.debug-panel h4 {
    color: #414141;
    margin: 20px 0 10px 0;
    font-size: 14px;
    font-weight: 600;
}

.debug-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #e8e8e8;
}

.debug-item label {
    font-weight: 500;
    color: #6f7084;
    font-size: 13px;
}

.debug-item span {
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    color: #34323f;
}

.model-select {
    padding: 4px 8px;
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    background: #ffffff;
    font-size: 12px;
    color: #34323f;
    font-family: 'Montserrat', sans-serif;
    cursor: pointer;
    min-width: 140px;
}

.model-select:hover {
    border-color: #3498db;
}

.model-select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

/* Status Badges */
.status-badge {
    padding: 4px 8px !important;
    border-radius: 4px !important;
    font-size: 11px !important;
    font-weight: 600;
}

.status-badge[data-value="true"] {
    background: #d4edda !important;
    color: #155724;
}

.status-badge[data-value="false"] {
    background: #f8d7da !important;
    color: #721c24;
}

/* Agent Badges */
.agent-badge {
    padding: 4px 8px !important;
    border-radius: 4px !important;
    font-size: 11px !important;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.agent-badge[data-agent="TaskCreationAgent"] {
    background: #d4edda !important;
    color: #155724;
}

.agent-badge[data-agent="TaskManagementAgent"] {
    background: #fff3cd !important;
    color: #856404;
}

.agent-badge[data-agent="ApplicantManagementAgent"] {
    background: #cce5ff !important;
    color: #004085;
}

.agent-badge[data-agent="GeneralSupportAgent"] {
    background: #f8d7da !important;
    color: #721c24;
}

/* Cost Display */
.cost-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cost-display {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: #2ecc71;
    font-size: 14px;
}

.token-count {
    font-size: 12px;
    color: #95a5a6;
    font-family: 'Courier New', monospace;
}

/* Debug Actions */
.debug-actions {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Quota table */
.quota-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
    font-size: 12px;
}

.quota-table th,
.quota-table td {
    border: 1px solid #e8e8e8;
    padding: 6px 8px;
}

/* Consistent header styling for both row and column headers */
.quota-table th {
    font-weight: 600;
    color: #6f7084;
    background: #fafafa;
}

.quota-table thead th {
    text-align: center;
}

.quota-table tbody th[scope="row"] {
    text-align: left;
    white-space: nowrap;
}

.quota-table tbody td {
    text-align: right;
    font-family: 'Courier New', monospace;
}

/* API Endpoints */
.api-endpoints ul {
    list-style: none;
    padding: 0;
}

.api-endpoints li {
    margin: 5px 0;
}

.api-endpoints a {
    color: #2f4050;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.api-endpoints a:hover {
    color: #557491;
    text-decoration: underline;
}


/* Session Validation Status */
.session-validation-status {
    display: none;
    padding: 8px 15px;
    margin: 0 20px 15px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    animation: slideDown 0.3s ease-out;
}

.session-validation-status.loading {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.session-validation-status.loading::before {
    content: '⏳ ';
}

.session-validation-status.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.session-validation-status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.session-validation-status.error::before {
    content: '⚠️ ';
}

/* Code Block Styling */
.code-block-wrapper {
    margin: 10px 0;
    border-radius: 4px;
    overflow: hidden;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.code-block-header {
    background: #e9ecef;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #dee2e6;
    font-size: 11px;
}

.code-language {
    color: #6f7084;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    text-transform: uppercase;
}

.copy-code-btn {
    background: transparent;
    border: 1px solid #adb5bd;
    color: #6f7084;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.copy-code-btn:hover {
    background: #ffffff;
    color: #495057;
    border-color: #6c757d;
}

.code-block {
    margin: 0;
    background: #f8f9fa !important;
    border: none;
    padding: 12px;
    font-size: 13px;
    line-height: 1.5;
    width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: pre;
    word-wrap: normal;
}

.code-block code {
    background: transparent !important;
    color: #212529;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;
    text-shadow: none;
    padding: 0;
    border-radius: 0;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    display: block;
    width: 100%;
    box-sizing: border-box;
}

/* Syntax Highlighting */
.code-block .token.comment,
.code-block .token.prolog,
.code-block .token.doctype,
.code-block .token.cdata {
    color: #6c757d;
    font-style: italic;
}

.code-block .token.punctuation {
    color: #6c757d;
}

.code-block .token.property,
.code-block .token.tag,
.code-block .token.constant,
.code-block .token.symbol,
.code-block .token.deleted {
    color: #d73a49;
}

.code-block .token.boolean,
.code-block .token.number {
    color: #005cc5;
}

.code-block .token.selector,
.code-block .token.attr-name,
.code-block .token.string,
.code-block .token.char,
.code-block .token.builtin,
.code-block .token.inserted {
    color: #22863a;
}

.code-block .token.operator,
.code-block .token.entity,
.code-block .token.url,
.code-block .language-css .token.string,
.code-block .style .token.string,
.code-block .token.variable {
    color: #e36209;
}

.code-block .token.atrule,
.code-block .token.attr-value,
.code-block .token.function,
.code-block .token.class-name {
    color: #6f42c1;
}

.code-block .token.keyword {
    color: #d73a49;
}

.code-block .token.regex,
.code-block .token.important {
    color: #e36209;
}

/* Message Content Overflow */
.message-content .code-block-wrapper {
    max-width: 100%;
    word-break: break-word;
    contain: layout;
}

.message-content {
    overflow-wrap: break-word;
    word-wrap: break-word;
    max-width: 100%;
}

.message {
    max-width: 100%;
    overflow: hidden;
}

.chat-section {
    min-width: 0;
}

.messages {
    min-width: 0;
    overflow-x: hidden;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2f4050;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

/* Form Input Styles */
input[type='text'],
input[type='email'],
input[type='password'],
textarea {
    -webkit-appearance: none;
    appearance: none;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        height: 100%;
    }
    
    .debug-panel {
        order: -1;
        height: auto;
    }
    
    .chat-section {
        height: calc(100dvh - 300px);
        min-height: 400px;
    }
}

/* Hide debug panel on mobile portrait devices */
@media (max-width: 768px) and (orientation: portrait) {
    .debug-panel {
        display: none !important;
    }
    
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .chat-section {
        height: calc(100dvh - 150px);
        min-height: 400px;
    }
}

/* Also hide debug panel on smaller mobile devices regardless of exact orientation */
@media (max-width: 480px) {
    .debug-panel {
        display: none !important;
    }
    
    .chat-section {
        height: calc(100dvh - 140px);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
        height: 100dvh;
    }
    
    header h1 {
        font-size: 20px;
    }

    .main-header {
        padding: 12px 16px;
        grid-template-columns: auto 1fr auto;
    }

    .header-icon-button {
        width: 36px;
        height: 36px;
    }

    .header-icon-button .header-icon {
        width: 18px;
        height: 18px;
    }
    
    .conversation-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .connection-status {
        margin-left: 0;
        justify-content: center;
    }
    
    .chat-section {
        height: calc(100dvh - 280px);
        min-height: 300px;
    }
    
    .messages {
        min-height: 150px;
    }
    
    .code-block {
        font-size: 12px;
        padding: 10px;
    }
    
    .code-block-header {
        padding: 6px 10px;
        font-size: 10px;
    }
}

/* Scrollbar Styling */
/* Hide visual scrollbars to prevent flash on update, while keeping scroll functional */
.messages {
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
}

.messages::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
}

/* iOS Safari Keyboard Fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS-specific fixes */
    html, body {
        position: fixed;
        overflow: hidden;
        width: 100%;
        height: 100%;
    }
    
    .container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .input-container {
        position: fixed;
        bottom: calc(36px + env(safe-area-inset-bottom, 0px));
        left: 20px;
        right: 20px;
        z-index: 1000;
        background: white;
        padding: 10px;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    .chat-section {
        padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    }
    
    .messages {
        bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    }
    
    #messageInput {
        font-size: 16px;
        -webkit-user-select: text;
        -webkit-appearance: none;
        border-radius: 8px;
    }
    
    #messageInput:focus {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Additional iOS viewport fixes */
@media screen and (max-device-width: 812px) and (-webkit-min-device-pixel-ratio: 2) {
    body {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    .input-container {
        position: fixed !important;
        bottom: calc(36px + env(safe-area-inset-bottom, 0px)) !important;
        padding-bottom: env(safe-area-inset-bottom, 10px) !important;
    }
    
    #messageInput {
        font-size: 16px !important;
    }
}
