/* Reset CSS */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Variables */
:root {
    --primary-color: #4a90e2;
    --secondary-color: #2c3e50;
    --accent-color: #e74c3c;
    --background-color: #f5f6fa;
    --text-color: #2c3e50;
    --border-radius: 8px;
    --box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

/* General Styles */
body {
    font-family: 'Segoe UI', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    position: relative;
    width: 100%;
    overflow-x: hidden;
}

body.modal-open {
    overflow: hidden;
}

/* Scroll Progress Bar */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--primary-color);
    z-index: 1000;
    transition: width 0.3s ease;
}

/* Header Styles */
header {
    background: white;
    padding: 1rem 1rem 0.5rem;
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Search Styles */
.search-container {
    max-width: 1200px;
    margin: 1rem auto 0;
    padding: 0 1rem;
}

.search-wrapper {
    position: relative;
    width: 100%;
}

#search-input {
    width: 100%;
    padding: 0.8rem 2.5rem 0.8rem 1rem;
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: all 0.3s ease;
    background-color: white;
}

#search-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
}

.search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 5px;
    display: none;
}

.search-clear:hover {
    color: var(--accent-color);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    box-shadow: var(--box-shadow);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
}

.search-result-item {
    padding: 0.8rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: #f5f5f5;
}

.search-result-item.selected {
    background-color: rgba(74, 144, 226, 0.1);
}

.highlight {
    background-color: #fff3cd;
    padding: 0 2px;
    border-radius: 2px;
}

@media (prefers-color-scheme: dark) {
    #search-input {
        background-color: #333;
        color: white;
        border-color: #666;
    }

    .search-results {
        background-color: #2d2d2d;
    }

    .search-result-item {
        border-bottom-color: #444;
    }

    .search-result-item:hover {
        background-color: #383838;
    }

    .highlight {
        background-color: #665e00;
    }
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary-color);
}

.title-container h1 {
    font-size: 1.5rem;
    margin-bottom: 0.2rem;
}

.primary-text {
    color: var(--primary-color);
    font-weight: bold;
}

.secondary-text {
    color: var(--secondary-color);
}

.subtitle {
    font-size: 0.9rem;
    color: #666;
}

/* Container and Main Content */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    position: relative;
    overflow-x: hidden;
    width: 100%;
}

.main-wrapper {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 2rem;
    max-width: 100%;
    overflow-x: hidden;
}

/* Table of Contents */
.toc-container {
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 100px;
    height: fit-content;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.toc-container h2 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.toc-content ul {
    list-style: none;
}

.toc-content li {
    margin: 0.5rem 0;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.toc-content li:hover {
    background: rgba(74, 144, 226, 0.1);
}

.toc-content a {
    color: var(--text-color);
    text-decoration: none;
    display: block;
    font-size: 0.9rem;
}

/* Content Section */
.content {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
}

.post {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #eee;
}

.post:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.post-title {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.post-date {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.post-content {
    line-height: 1.8;
}

.post-content p {
    margin-bottom: 1rem;
}

.post-content p:last-child {
    margin-bottom: 0;
}

.post-content .hashtag {
    color: var(--primary-color);
    font-weight: 500;
    cursor: pointer;
}

.post-content .from {
    display: block;
    color: var(--secondary-color);
    font-style: italic;
    margin: 1rem 0 0.5rem;
    padding-left: 1rem;
    border-left: 3px solid var(--primary-color);
}

.post-content strong {
    color: var(--secondary-color);
    font-weight: 600;
}

.post-content em {
    color: var(--text-color);
    opacity: 0.8;
}

@media (prefers-color-scheme: dark) {
    .post-content .hashtag {
        color: #66b3ff;
    }

    .post-content .from {
        color: #a8c7fa;
        border-left-color: #66b3ff;
    }

    .post-content strong {
        color: #fff;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    overflow-y: auto;
    padding: 20px;
}

body.modal-open {
    overflow: hidden;
}

#login-btn {
    width: 100%;
    margin-top: 1rem;
    background-color: var(--primary-color);
    color: white;
    padding: 0.8rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#login-btn:hover {
    background-color: #357abd;
}

#admin-password {
    width: 100%;
    padding: 0.8rem;
    margin-top: 1rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 1rem;
}

#admin-password:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

#admin-dashboard {
    z-index: 1000;
}

#content-modal {
    z-index: 2001;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    max-width: 600px;
    width: 90%;
    margin: 2rem auto;
    position: relative;
    animation: modalFadeIn 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.modal {
    overflow-y: auto;
    padding: 20px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    box-sizing: border-box;
}

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

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    transition: var(--transition);
}

.close:hover {
    color: var(--accent-color);
}

/* Form Elements */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group textarea {
    max-height: 50vh;
    min-height: 150px;
    resize: vertical;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

/* Buttons */
button {
    cursor: pointer;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

.primary-button {
    background: var(--primary-color);
    color: white;
}

.primary-button:hover {
    background: #357abd;
}

.secondary-button {
    background: #95a5a6;
    color: white;
}

.secondary-button:hover {
    background: #7f8c8d;
}

.github-button {
    background: #333;
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.github-button:hover {
    background: #24292e;
}

/* Text Editor Toolbar */
.text-editor-toolbar {
    margin-bottom: 0.5rem;
    display: flex;
    gap: 0.5rem;
}

.format-btn {
    padding: 0.5rem;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    color: #333;
}

.format-btn:hover {
    background: #e9ecef;
}

/* Admin Dashboard */
.admin-dashboard-content {
    max-width: 800px;
}

.admin-controls {
    margin: 1rem 0;
    display: flex;
    gap: 1rem;
}

.content-list {
    margin-top: 2rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

th {
    background: #f8f9fa;
    font-weight: 600;
}

/* Back to Top Button */
#back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--primary-color);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: none;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: var(--box-shadow);
    transition: var(--transition);
}

#back-to-top:hover {
    background: #357abd;
    transform: translateY(-3px);
}

/* Chatbot Styles */
#chatbot-container {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

#chatbot-toggle {
  background: linear-gradient(135deg, #0078ff 0%, #0055cc 100%);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 120, 255, 0.3);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chatbot-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 120, 255, 0.4);
}

#chatbot-toggle:active {
  transform: scale(0.95);
}

#chatbot-box {
  display: none;
  flex-direction: column;
  width: 360px;
  height: 500px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#chatbot-box.active {
  display: flex;
}

#chatbot-header {
  background: linear-gradient(135deg, #0078ff 0%, #0055cc 100%);
  color: #fff;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

#chatbot-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

#chatbot-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  transition: all 0.2s ease;
}

#chatbot-close:hover {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
}

#chatbot-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  font-size: 0.95rem;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

#chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

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

#chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #999;
}

.chatbot-msg {
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 85%;
  word-break: break-word;
  line-height: 1.4;
  animation: fadeIn 0.3s ease;
}

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

.chatbot-msg.user {
  background: linear-gradient(135deg, #0078ff 0%, #0055cc 100%);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 120, 255, 0.2);
}

.chatbot-msg.bot {
  background: #e5e5ea;
  color: #222;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chatbot-msg.loading {
  background: #e5e5ea;
  color: #999;
  font-style: italic;
  align-self: flex-start;
}

#chatbot-form {
  display: flex;
  flex-direction: column;
  border-top: 1px solid #eee;
  background: #fff;
  padding: 12px;
  gap: 8px;
}

.chatbot-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

#chatbot-input {
  flex: 1;
  border: 1px solid #ddd;
  padding: 10px 12px;
  font-size: 0.95rem;
  border-radius: 8px;
  outline: none;
  transition: all 0.2s ease;
  font-family: inherit;
}

#chatbot-input:focus {
  border-color: #0078ff;
  box-shadow: 0 0 0 3px rgba(0, 120, 255, 0.1);
}

#chatbot-form button {
  background: linear-gradient(135deg, #0078ff 0%, #0055cc 100%);
  color: #fff;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
}

#chatbot-form button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 120, 255, 0.3);
}

#chatbot-form button:active {
  transform: translateY(0);
}

/* Responsive Design */
/* Mobile First Approach */
:root {
    --header-height: 60px;
    --container-padding: 1rem;
}

/* Base Mobile Styles (320px and up) */
@media screen and (min-width: 320px) {
    html {
        font-size: 14px;
    }

    .header-top {
        flex-direction: column;
        text-align: center;
        padding: 0.5rem;
    }

    .logo-container {
        flex-direction: column;
        margin-bottom: 1rem;
    }

    .logo {
        width: 50px;
        height: 50px;
        margin-bottom: 0.5rem;
    }

    .title-container h1 {
        font-size: 1.2rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    .main-wrapper {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .toc-container {
        position: relative;
        top: 0;
        margin-bottom: 1rem;
        max-height: 200px;
    }

    .content {
        padding: 1rem;
    }

    .modal-content {
        width: 95%;
        margin: 0.5rem;
        padding: 1rem;
    }

    .admin-controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    td, th {
        padding: 0.5rem;
    }

    #back-to-top {
        right: 1rem;
        bottom: 1rem;
        width: 40px;
        height: 40px;
    }
}

/* Tablet Styles (600px and up) */
@media screen and (min-width: 600px) {
    html {
        font-size: 15px;
    }

    .header-top {
        flex-direction: row;
        justify-content: space-between;
        padding: 1rem;
    }

    .logo-container {
        flex-direction: row;
        margin-bottom: 0;
    }

    .logo {
        width: 60px;
        height: 60px;
        margin-bottom: 0;
    }

    .title-container h1 {
        font-size: 1.4rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .modal-content {
        width: 80%;
        margin: 1rem auto;
        padding: 1.5rem;
    }

    .admin-controls {
        flex-direction: row;
        flex-wrap: wrap;
    }

    table {
        display: table;
        width: 100%;
    }

    td, th {
        padding: 0.75rem;
    }
}

/* Laptop Styles (900px and up) */
@media screen and (min-width: 900px) {
    html {
        font-size: 16px;
    }

    .main-wrapper {
        grid-template-columns: 250px 1fr;
        gap: 2rem;
    }

    .toc-container {
        position: sticky;
        top: 100px;
        max-height: calc(100vh - 120px);
    }

    .content {
        padding: 2rem;
    }

    .modal-content {
        width: 70%;
        max-width: 800px;
    }
}

/* Desktop Styles (1200px and up) */
@media screen and (min-width: 1200px) {
    .container {
        max-width: 1200px;
        margin: 2rem auto;
    }

    .header-top {
        max-width: 1200px;
        margin: 0 auto;
    }
}

/* Print Styles */
@media print {
    .toc-container,
    #back-to-top,
    #admin-btn,
    .modal {
        display: none !important;
    }

    .main-wrapper {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .content {
        box-shadow: none;
        padding: 0;
    }

    @page {
        margin: 2cm;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #0000FF;
        --secondary-color: #000000;
        --text-color: #000000;
        --background-color: #FFFFFF;
    }

    * {
        border-color: #000000 !important;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #66b3ff;
        --secondary-color: #a8c7fa;
        --background-color: #1a1a1a;
        --text-color: #ffffff;
    }

    body {
        background-color: var(--background-color);
        color: var(--text-color);
    }

    .content,
    .toc-container,
    .modal-content {
        background-color: #2d2d2d;
    }

    input,
    textarea {
        background-color: #333;
        color: white;
        border-color: #666;
    }

    th {
        background-color: #333;
    }

    .format-btn {
        background-color: #333;
        color: white;
    }
}

/* Animations */
.hover-effect {
    transition: transform 0.3s ease;
}

.hover-effect:hover {
    transform: scale(1.05);
}

/* Loading Spinner */
.loading {
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(74, 144, 226, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
