/***** General *****/
html, body { height: 100%; min-height: 100vh; }
body { background: #f5f7fa; }

/***** Layout Structure *****/
.container-fluid.h-100 {
    height: calc(100vh - 4rem) !important;
    min-height: calc(100vh - 4rem);
}

.row.h-100 {
    height: calc(100vh - 4rem) !important;
    min-height: calc(100vh - 4rem);
}

.min-vh-80 {
    min-height: 80vh;
}

main.col {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4rem) !important;
    min-height: calc(100vh - 4rem);
    max-height: calc(100vh - 4rem);
    /*background: #faf19B;*/
}

#chat-controls {
    display: flex;
}

#chatbox {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 0;
}

#chat-form {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid #e0e0e0;
    padding: 16px 20px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 100;
    margin-top: 0;
}

/***** Modal Styling *****/
.modal-content {
    border: none;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-header {
    border-bottom: 1px solid #e9ecef;
    padding: 1.5rem 1.5rem 1rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px 12px 0 0;
    /*color: #214f6d;*/
}

.modal-title {
    font-weight: 600;
    color: #495057;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    border-top: 1px solid #e9ecef;
    padding: 1rem 1.5rem 1.5rem;
    background: #f8f9fa;
    border-radius: 0 0 12px 12px;
}

.modal .form-control {
    border-radius: 8px;
    border: 2px solid #e9ecef;
    padding: 0.75rem 1rem;
    transition: all 0.2s ease;
    /*background: #faf19B;*/
    /*color: #214f6d;*/
}

.modal .form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.modal .btn {
    border-radius: 8px;
    padding: 0.5rem 1.5rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.modal .btn-primary {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    /*color: #faf19B;*/
    border: none;
}

.modal .btn-primary:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    transform: translateY(-1px);
    /*color: #faf19B;*/
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.modal .btn-warning {
    background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
    border: none;
    color: #212529;
}

.modal .btn-warning:hover {
    background: linear-gradient(135deg, #e0a800 0%, #d39e00 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.3);
}

.modal .btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #545b62 100%);
    /*color: #214f6d;*/
    border: none;
}

.modal .btn-secondary:hover {
    background: linear-gradient(135deg, #545b62 0%, #4e555b 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
}

.modal .form-text {
    color: #6c757d;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

.modal .form-label {
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
}

/***** Sidebar *****/
#sidebar {
    background: #f8f9fa;
    border-right: 1px solid #e0e0e0;
    min-width: 180px;
    max-width: 260px;
    height: calc(100vh - 4rem);
    overflow-y: auto;
}
#sidebar .list-group-item {
    border: none;
    border-radius: 8px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background 0.2s;
    /*background: transparent;*/
    /*color: #214f6d;*/
}
#sidebar .list-group-item.active, #sidebar .list-group-item:hover {
    background: #e3e9f6;
    color: #0056b3;
}

/***** Chat Window *****/
.chatbox-bg {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 0;
    height: 100%;
    border-bottom: 1px solid #e0e0e0;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 20px;
}

/* Add some spacing between message groups */
.chat-message-container:not(:last-child) {
    margin-bottom: 20px;
}

/***** Chat Bubbles *****/
.chat-message-container {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 100%;
    margin-bottom: 16px;
}

/* User messages - align to right and flip order */
.chat-user .chat-message-container {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.user-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.bot-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.chat-content {
    flex: 1;
    min-width: 0;
    max-width: 70%;
}

.chat-bot .chat-content {
    margin-left: 0;
}

.chat-user .chat-content {
    margin-left: auto;
    text-align: right;
}

.chat-name {
    font-size: 0.8em;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 6px;
    padding-top: calc(16px - 0.8em);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-user .chat-name {
    text-align: right;
}

.chat-text {
    line-height: 1.5;
    color: #374151;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chat-user .chat-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
    margin-left: auto;
    max-width: 100%;
}

.chat-bot .chat-text {
    background: white;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    margin-right: auto;
    max-width: 100%;
}

/* Chat bubble tails */
.chat-user .chat-text::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    /*border-left-color: #667eea;*/
    border-bottom: none;
    border-right: none;
}

.chat-bot .chat-text::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    /*border-bottom: none;*/
    border-left: none;
}

.chat-bot .chat-text::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -9px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: #e5e7eb;
    border-bottom: none;
    border-left: none;
}

.chat-text strong {
    font-weight: 600;
}

.chat-text em {
    font-style: italic;
}

.chat-text .inline-code {
    background: rgba(0,0,0,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    color: inherit;
}

.chat-user .chat-text .inline-code {
    background: rgba(255,255,255,0.2);
}

.chat-text .code-block {
    background: #f6f8fa;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    line-height: 1.45;
}

.chat-user .chat-text .code-block {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
}

.chat-text .code-block code {
    background: none;
    padding: 0;
    color: inherit;
}

.chat-user .chat-text .code-block code {
    color: white;
}

.chat-text h1, .chat-text h2, .chat-text h3 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.25;
}

.chat-text h1 {
    font-size: 1.5em;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding-bottom: 8px;
}

.chat-user .chat-text h1 {
    border-bottom-color: rgba(255,255,255,0.2);
}

.chat-text h2 {
    font-size: 1.3em;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding-bottom: 6px;
}

.chat-user .chat-text h2 {
    border-bottom-color: rgba(255,255,255,0.2);
}

.chat-text h3 {
    font-size: 1.1em;
}

.chat-text ul {
    margin: 8px 0;
    padding-left: 24px;
}

.chat-text li {
    margin: 4px 0;
}

.chat-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 0.9em;
}

.chat-text table th,
.chat-text table td {
    border: 1px solid #e1e4e8;
    padding: 8px 12px;
    text-align: left;
}

.chat-user .chat-text table th,
.chat-user .chat-text table td {
    border-color: rgba(255,255,255,0.2);
}

.chat-text table th {
    background: #f6f8fa;
    font-weight: 600;
}

.chat-user .chat-text table th {
    background: rgba(255,255,255,0.1);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
}

.typing-indicator::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: white;
    border-bottom: none;
    border-left: none;
}

.typing-indicator::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -9px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: #e5e7eb;
    border-bottom: none;
    border-left: none;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.error-message {
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.error-message::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: #fef2f2;
    border-bottom: none;
    border-left: none;
}

.error-message::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -9px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: #fecaca;
    border-bottom: none;
    border-left: none;
}

/***** Input Area *****/
#chat-input {
    border-radius: 24px;
    border: 2px solid #e5e7eb;
    padding: 12px 20px;
    font-size: 1em;
    background: #fff;
    color: #222;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    flex: 1;
}

#chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chat-send {
    border-radius: 24px;
    min-width: 80px;
    font-weight: 500;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    padding: 12px 20px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

#chat-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

#chat-send:disabled {
    background: #e0e0e0;
    color: #aaa;
    border: none;
    transform: none;
    box-shadow: none;
}

/***** Chat Header *****/
#chat-header {
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    min-height: 56px;
}
#chat-title {
    font-weight: 600;
    color: #0056b3;
}

/***** Loading Indicator *****/
.dot-elastic {
    content: '';
    display: inline-block;
    position: relative;
    top: 0;
    width: 10px;
    height: 10px;
    border-radius: 5px;
    background: #b0b8c1;
    margin-right: 2px;
}
.dot-1 {
    animation: dot-elastic-before 1s infinite linear;
}
.dot-2 {
    animation: dot-elastic-middle 1s infinite linear;
}
.dot-3 {
    animation: dot-elastic-after 1s infinite linear;
}
@keyframes dot-elastic-before {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1, 1.5); }
    50% { transform: scale(1, 0.67); }
    75% { transform: scale(1, 1); }
}
@keyframes dot-elastic-middle {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1, 0.67); }
    50% { transform: scale(1, 1.5); }
    75% { transform: scale(1, 1); }
}
@keyframes dot-elastic-after {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1, 1); }
    50% { transform: scale(1, 0.67); }
    75% { transform: scale(1, 1.5); }
}

/***** Responsive *****/
@media (max-width: 768px) {
    .d-flex.align-items-center.ms-auto.flex-wrap {
        padding-top: 5px;
    }
}
@media (max-width: 768px) {
    #sidebar {
        display: none !important;
    }
    .d-block.d-md-none {
        display: block !important;
    }
    #mobileChatList {
        /*width: 100vw;*/
        max-width: 100vw;
        overflow-x: auto;
    }
    #conversation-list-mobile {
        max-height: 40vh;
        overflow-y: auto;
    }
    main.col {
        padding-top: 0 !important;
    }
    .chatbox-bg {
        height: 100%;
        max-height: none;
        padding: 10px;
    }
    .chat-content {
        max-width: 85%;
    }
    .chat-text {
        padding: 10px 14px;
        font-size: 0.95em;
    }
    .chat-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    #chat-form .form-control,
    #chat-form .btn,
    #new-chat-btn-mobile {
        width: auto !important;
        margin-bottom: 0 !important;
    }
    #chat-form {
        flex-direction: row;
        gap: 0.5rem;
    }
    #chat-input {
        flex: 1 1 auto;
    }
    #chat-send {
        flex: 0 0 auto;
    }
    .modal-dialog {
        max-width: 98vw;
        margin: 0.5rem auto;
    }
    .modal-content {
        border-radius: 10px;
        padding: 0.5rem;
    }
    .card, .table-responsive {
        overflow-x: auto;
    }
}
@media (max-width: 576px) {
    .container .card {
        margin: 1rem;
        padding: 1.5rem !important;
    }
    .container .card .form-control {
        padding: 0.875rem 1rem;
        font-size: 16px;
    }
    .container .card .btn {
        padding: 0.875rem 1.5rem;
        font-size: 16px;
    }
    .container .card h2 {
        font-size: 1.25rem;
    }
    .container .card .form-label {
        font-size: 0.85rem;
    }
    .modal-dialog {
        max-width: 100vw;
        margin: 0;
    }
    .modal-content {
        border-radius: 8px;
        padding: 0.25rem;
    }
    .admin-dashboard-page .container-fluid, .admin-dashboard-page .row, .admin-dashboard-page main {
        padding: 0 !important;
    }
    .admin-tabs {
        font-size: 0.95em;
        padding: 0 0.5rem;
    }
    .table-responsive {
        overflow-x: auto;
    }
}

/* Fix navbar height for localisation bar */
body > .navbar {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin-bottom: 0 !important;
}

/***** Form Styling *****/
/* Login and Password Change Forms */
.container .card {
    border: none;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.container .card .form-label {
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.container .card .form-control {
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    transition: all 0.2s ease;
    background: #fff;
}

.container .card .form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

.container .card .form-control.is-invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.container .card .form-control.is-invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.container .card .form-control::placeholder {
    color: #adb5bd;
}

.container .card .form-text {
    color: #6c757d;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.container .card .alert {
    border-radius: 8px;
    border: none;
    font-size: 0.9rem;
}

.container .card .btn {
    border-radius: 8px;
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.container .card .btn-primary {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: #faf19B;
    border: none;
}

.container .card .btn-primary:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.container .card .btn-outline-secondary {
    border: 2px solid #6c757d;
    color: #6c757d;
    background: transparent;
}

.container .card .btn-outline-secondary:hover {
    background: #6c757d;
    border-color: #6c757d;
    color: white;
}

/* Error styling */
.container .card .text-danger {
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/***** File Upload Styling *****/
#attachments-display {
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    padding: 12px 16px;
    transition: all 0.3s ease;
    position: relative;
    z-index: 10;
    margin-bottom: 0;
}

#attachments-display .small {
    font-size: 0.875rem;
    color: #6c757d;
}

#attachments-list {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 8px;
}

.attachment-item {
    background: white;
    border: 1px solid #e9ecef !important;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    margin-bottom: 8px;
}

.attachment-item:last-child {
    margin-bottom: 0;
}

.attachment-item:hover {
    border-color: #007bff !important;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.1);
}

.attachment-item .custom-icon {
    font-size: 1rem;
    color: #6c757d;
}

.attachment-item .btn-outline-danger {
    border: 1px solid #dc3545;
    color: #dc3545;
    background: transparent;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    transition: all 0.2s ease;
    max-width: 2em;
}

.attachment-item .btn-outline-danger:hover {
    background: #dc3545;
    color: white;
    transform: scale(1.05);
}

#file-input {
    display: none;
}

#file-input + label {
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    cursor: pointer;
    border: 2px solid #e9ecef;
    background: white;
    color: #6c757d;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

#file-input + label:hover {
    border-color: #007bff;
    color: #007bff;
    background: #f8f9fa;
}

#file-input + label .custom-icon {
    font-size: 1rem;
}

/* File type icons */
.custom-icon.icon-pdf {
    color: #dc3545;
}

.custom-icon.icon-xlsx {
    color: #28a745;
}

.custom-icon.icon-docx {
    color: #007bff;
}

.custom-icon.icon-txt {
    color: #6c757d;
}

.custom-icon.icon-files {
    color: #6c757d;
}

/* Success message styling */
.alert-success {
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
    border: 1px solid #c3e6cb;
    color: #155724;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.2);
}

.alert-success .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Ensure chat form stays at bottom */
#chat-form {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid #e0e0e0;
    padding: 16px 20px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 100;
    margin-top: 0;
}

/* Ensure chatbox has proper spacing */
#chatbox {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 0;
}

/* Responsive file upload */
@media (max-width: 768px) {
    #attachments-display {
        padding: 8px 12px;
    }
    
    .attachment-item {
        padding: 8px !important;
        font-size: 0.8rem;
    }
    
    #file-input + label {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    #attachments-list {
        max-height: 150px;
    }
}
