* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', sans-serif;
    background-color: #ECF7FE;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    background-color: #ffffff;
    border-radius: 0;
    overflow: hidden;
}

.header {
    position: relative; /* Needed for absolute positioning of the button */
    display: flex;
    align-items: center;
    justify-content: center; /* This will center the h1 */
    background-color: #016AA2;
    padding: 10px;
    height: 48px;
}

h1 {
    margin: 0;
    font-size: 28px;
    min-height: 28px;
    color: #fff;
    text-align: center;
}

.contact-us-button {
    position: absolute;
    right: 15px; /* Position to the right */
    color: #fff;
    background-color: #016AA2; /* Match the header */
    border: 2px solid #fff; /* White border */
    text-decoration: none;
    padding: 8px 18px;
    border-radius: 10px;
}

.contact-us-button:hover {
    background-color: #024264; /* Darker blue on hover */
}

.logout-button {
    position: absolute;
    left: 15px;
    color: #fff;
    background-color: #016AA2;
    border: 2px solid #fff;
    padding: 8px 18px;
    border-radius: 10px;
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
}

.logout-button:hover {
    background-color: #024264;
}

.chat-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 8px 12px;
    background: linear-gradient(135deg, var(--primary-50) 0%, var(--purple-50) 30%, var(--accent-50) 70%, var(--orange-50) 100%);
    gap: 10px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    border-radius: 0; /* square edges to merge with section background */
    background-color: transparent; /* inherit blue from .chat-section */
}

.message {
    margin-bottom: 12px;
    padding: 12px 16px;
    border-radius: 14px;
    max-width: 80%;
    line-height: 1.6;
    border: 1px solid var(--gray-300);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    opacity: 0;
    transform: translateY(20px);
    animation: slideIn 0.4s ease forwards;
}

@keyframes slideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    background: var(--primary-200);
    border-color: var(--primary-400);
    margin-left: auto;
    text-align: right;
}

.message.bot {
    background: var(--purple-50);
    border-color: var(--purple-300);
}

.message.bot.thinking {
    background: var(--purple-50);
    font-style: italic;
    color: #555;
}



.user-label, .bot-label {
    display: block;
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 3px;
    color: #016AA2;
}

form {
    display: flex;
    gap: 10px;
    padding-bottom: env(safe-area-inset-bottom); /* for iOS safe area */
}

input[type="text"] {
    flex: 1;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 16px;
}

button[type="submit"] {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    background-color: #016AA2;
    color: white;
    font-size: 16px;
    cursor: pointer;
}

button[type="submit"]:hover {
    background-color: #024264;
}

.message p {
    max-width: 100vw;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
}

.hidden {
    display: none;
}

/* Responsive design */
@media screen and (max-width: 768px) {
    .header {
        height: 44px;
        padding: 8px;
    }
    
    h1 {
        font-size: 26px;
    }
    
    .message {
        font-size: 16px;
    }
    
    .user-label, .bot-label {
        font-size: 16px;
    }

    .courses-container h1 {
        font-size: 24px;
        margin-bottom: 25px;
    }

    .intro-title {
        font-size: 4em;
    }

    .intro-subtitle {
        font-size: 1.5em;
    }

    .intro-chat-message {
        font-size: 28px;
        padding: 0px 28px;
    }
}

@media screen and (max-width: 600px) {
    .container {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }

    .chat-section {
        padding: 8px;
    }

    input[type="text"], button[type="submit"] {
        font-size: 14px;
    }

    .message {
        max-width: 100%;
        font-size: 15px;
    }
    
    .user-label, .bot-label {
        font-size: 15px;
    }

    h1 {
        font-size: 24px;
    }
    
    .header {
        height: 40px;
        padding: 6px;
    }
    
    .contact-us-button, .logout-button {
        padding: 6px 14px;
        font-size: 13px;
    }

    .courses-container {
        padding: 15px;
    }
    
    .courses-container a {
        padding: 12px 24px;
        font-size: 16px;
    }

    .intro-title {
        font-size: 3.5em;
    }

    .intro-subtitle {
        font-size: 1.3em;
    }

    .intro-chat-message {
        font-size: 24px;
        padding: 0px 24px;
    }
}

@media screen and (max-width: 480px) {
    .contact-us-button, .logout-button {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .header {
        height: 38px;
        padding: 5px;
    }
    
    h1 {
        font-size: 22px;
    }
    
    .chat-section {
        padding: 6px;
    }
    
    input[type="text"], button[type="submit"] {
        font-size: 13px;
        padding: 10px;
    }
    
    .message {
        padding: 8px 12px;
        margin-bottom: 10px;
        font-size: 14px;
    }
    
    .user-label, .bot-label {
        font-size: 14px;
    }

    .courses-container {
        padding: 10px;
    }
    
    .courses-container a {
        padding: 10px 20px;
        font-size: 14px;
    }

    .intro-title {
        font-size: 3em;
    }

    .intro-subtitle {
        font-size: 1.2em;
    }

    .intro-chat-message {
        font-size: 18px;
        padding: 0px 18px;
    }
}

/* Sidebar styles */
.sidebar {
    position: fixed;
    top: 48px;
    right: 0;
    height: calc(100vh - 48px);
    width: 280px; /* widened when open */
    background-color: #f0f0f0;
    border-radius: 10px 0 0 10px;
    box-shadow: -2px 0 5px rgba(0,0,0,0.2);
    transition: right 0.3s ease-in-out;
    z-index: 1000;
    display: flex;
}

.sidebar.closed {
    right: -280px; /* match widened width */
}

.sidebar-toggle {
    width: 30px;
    height: 120px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    
    background: linear-gradient(135deg, var(--primary-600), rgba(79, 70, 229, 0.92));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 0 10px 10px 0;
    position: absolute;
    left: -30px; /* Position outside the sidebar content */
    top: 10px;
    transition: background-color 0.2s ease;
}

.sidebar-toggle:hover {
    background: linear-gradient(135deg, var(--primary-700), rgba(67, 56, 202, 0.92));
}

.sidebar-content {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
}

.sidebar-content .primary-button {
    background: linear-gradient(135deg, var(--primary-600), rgba(79, 70, 229, 0.92));
    color: white;
    border: none;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    text-align: center;
    cursor: pointer;
    margin-bottom: 15px;
}

.sidebar-content .primary-button:hover {
    background: linear-gradient(135deg, var(--primary-700), rgba(67, 56, 202, 0.92));
}

.sidebar-content ul {
    list-style: none;
    padding: 0;
}

.sidebar-content li {
    margin-bottom: 10px;
}

.sidebar-content a {
    color: #016AA2;
    text-decoration: none;
}

.sidebar-content a:hover {
    text-decoration: underline;
} 

.ts-link {
  text-decoration: underline;
  cursor: pointer;
}

/* Sidebar tree */
.lectures-tree {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.lecture-item {
  margin: 0;
  padding: 6px 8px;
  border-radius: 6px;
}

.lecture-item.active {
  background: var(--purple-50);
  border: 1px solid var(--purple-300);
  border-radius: 14px; /* match message radius */
}

.lecture-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.lecture-row .lecture-title {
  font-weight: 600;
  color: #084c7f;
  flex: 1;
  min-width: 0; /* allow ellipsis */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lecture-item .chevron {
  display: inline-block;
  transition: transform 0.15s ease;
  color: #084c7f;
  font-weight: bold;
}

.lecture-item.expanded > .lecture-row .chevron {
  transform: rotate(90deg);
}

/* Nested chat list under a lecture */
.chat-sublist {
  list-style: none;
  padding: 4px 0 6px 22px; /* indent under lecture row */
  margin: 4px 0 0;
}

.chat-item {
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-item a {
  color: #0a6aa1;
  text-decoration: none;
  flex: 1;
  min-width: 0; /* enable ellipsis */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Highlight for the "New Chat…" entry */
.chat-item.new-chat a {
  background: var(--purple-50);
  border: 1px solid var(--purple-300);
  color: var(--purple-700);
  padding: 6px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.chat-item.new-chat a:hover {
  background: var(--purple-100);
  border-color: var(--purple-400);
}

.chat-item a:hover {
  text-decoration: underline;
}

.chat-item.placeholder,
.chat-item.empty,
.chat-item.error {
  color: #666;
  font-style: italic;
}