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

:root {
    --primary-color: #4256ac;
    --secondary-color: #5f6b85;
    --background-color: #fff;
    --sidebar-bg: #f6f7fc;
    --border-color: #e5e9f5;
    --accent-color: #fe843a;
    --accent-soft: rgba(254, 132, 58, 0.12);
    --highlight-adverb: #36b3d9;
    --highlight-passive: #66d466;
    --highlight-complex: #b68cd4;
    --highlight-hard: #f7b500;
    --highlight-very-hard: #e74c3c;
    --highlight-custom: #ff6b6b;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--primary-color);
    line-height: 1.6;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--background-color);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-logo {
    height: 28px;
    width: auto;
}

.header-center {
    display: flex;
    gap: 0.5rem;
}

.header-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    cursor: pointer;
    font-size: 1.1rem;
    border-radius: 999px;
    transition: all 0.2s;
}

.header-btn:hover {
    background-color: var(--accent-soft);
    border-color: var(--accent-color);
}

.header-right {
    display: flex;
    gap: 0.5rem;
}

.mode-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: 999px;
    transition: all 0.2s;
}

.mode-btn:first-child {
    border-radius: 999px;
}

.mode-btn:last-child {
    border-radius: 999px;
}

.mode-btn.active {
    background-color: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
}

/* App Layout */
.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left Navigation */
.left-nav {
    width: 250px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

.left-nav.collapsed {
    margin-left: -250px;
}

.nav-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--secondary-color);
}

.btn-icon {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background-color: var(--primary-color);
    color: white;
}

.chapters-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chapter-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    background-color: var(--background-color);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.chapter-item:hover {
    background-color: #f0f0f0;
}

.chapter-item.active {
    background-color: var(--primary-color);
    color: white;
}

.chapter-info {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    overflow: hidden;
}

.drag-handle {
    margin-right: 0.5rem;
    cursor: move;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.chapter-item:hover .drag-handle {
    opacity: 0.7;
}

.chapter-item.dragging {
    opacity: 0.5;
    cursor: move;
}

.chapter-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow: hidden;
}

.chapter-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.chapter-word-count {
    font-size: 0.75rem;
    color: var(--secondary-color);
    opacity: 0.8;
}

.chapter-item.active .chapter-word-count {
    color: rgba(255, 255, 255, 0.8);
}

.chapter-item.brainstorm {
    background-color: #f0f8ff;
    border: 1px dashed #87ceeb;
}

.chapter-item.brainstorm:hover {
    background-color: #e6f2ff;
}

.chapter-item.brainstorm.active {
    background-color: #4682b4;
    border: 1px dashed #87ceeb;
}

.chapter-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.chapter-item:hover .chapter-actions {
    opacity: 1;
}

.chapter-action {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    font-size: 0.875rem;
    opacity: 0.7;
}

.chapter-action:hover {
    opacity: 1;
}

.nav-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.total-word-count {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    text-align: center;
    font-weight: 600;
    color: var(--primary-color);
}

.document-title-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Editor Section */
.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--background-color);
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--background-color);
}

.toolbar-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    cursor: pointer;
    font-size: 0.875rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background-color: #f0f0f0;
}

/* Style the underline button */
.toolbar-btn[data-command="underline"] {
    text-decoration: underline;
}

/* Style the format paragraphs button */
.toolbar-btn[data-action="formatParagraphs"] {
    background-color: #e3f2fd;
    border-color: #2196F3;
    color: #1976D2;
}

.toolbar-btn[data-action="formatParagraphs"]:hover {
    background-color: #bbdefb;
}

.toolbar-btn[data-command="bold"] {
    font-weight: bold;
}

.toolbar-btn[data-command="italic"] {
    font-style: italic;
}

.toolbar-separator {
    display: inline-block;
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 8px;
    vertical-align: middle;
}

/* Editor */
.editor-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.editor {
    max-width: 800px;
    margin: 0 auto;
    min-height: 100%;
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    line-height: 2;
    outline: none;
}

.editor p {
    margin-bottom: 1rem;
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
}

.editor h1 {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    font-weight: bold;
    text-decoration: underline;
    margin: 1.5rem 0 1rem;
}

.editor h2 {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    font-weight: bold;
    text-decoration: none;
    margin: 1.5rem 0 1rem;
}

.editor h3 {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    font-weight: normal;
    text-decoration: underline;
    margin: 1.5rem 0 1rem;
}

.editor blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--secondary-color);
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
}

.editor ul, .editor ol {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    margin: 1rem 0;
    padding-left: 2rem;
}

.editor li {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    margin-bottom: 0.5rem;
}

/* Ensure all text elements inherit the font */
.editor * {
    font-family: 'Times New Roman', Times, serif !important;
    font-size: 12pt !important;
}

/* Override any default contenteditable styles */
.editor[contenteditable="true"] {
    font-family: 'Times New Roman', Times, serif !important;
    font-size: 12pt !important;
}

/* Ensure div elements in editor also have proper formatting */
.editor div {
    font-family: 'Times New Roman', Times, serif !important;
    font-size: 12pt !important;
    line-height: 2;
}

/* Sidebar */
.sidebar {
    width: 350px;
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 2rem;
}

.sidebar-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.sidebar-section h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

/* Readability Score */
.readability-score {
    text-align: center;
    padding: 1rem 0;
}

.grade {
    font-size: 2rem;
    font-weight: 600;
    color: #27ae60;
}

.grade-label {
    font-size: 0.875rem;
    color: var(--secondary-color);
}

/* Statistics */
.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--secondary-color);
}

.stat-value {
    font-weight: 500;
}

/* Highlight Stats */
.highlight-stat {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    border-radius: 4px;
}

.highlight-count {
    font-size: 1.125rem;
    font-weight: 600;
    min-width: 32px;
    flex-shrink: 0;
    padding-top: 2px;
}

.highlight-label {
    font-size: 0.8rem;
    line-height: 1.3;
    flex: 1;
}

.adverb-stat {
    background-color: rgba(54, 179, 217, 0.1);
    color: var(--highlight-adverb);
}

.passive-stat {
    background-color: rgba(102, 212, 102, 0.1);
    color: var(--highlight-passive);
}

.complex-stat {
    background-color: rgba(182, 140, 212, 0.1);
    color: var(--highlight-complex);
}

.hard-stat {
    background-color: rgba(247, 181, 0, 0.1);
    color: var(--highlight-hard);
}

.very-hard-stat {
    background-color: rgba(231, 76, 60, 0.1);
    color: var(--highlight-very-hard);
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-add {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.btn-small {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

.btn-primary {
    background-color: var(--accent-color);
    color: var(--background-color);
}

.btn-primary:hover {
    background-color: #e56f2f;
}

.btn-secondary {
    background-color: var(--background-color);
    color: var(--primary-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--accent-soft);
    border-color: var(--accent-color);
}

.btn-add {
    padding: 0.25rem 0.75rem;
    background-color: var(--primary-color);
    color: white;
}

/* Top Words List */
.top-words-list {
    margin-top: 1rem;
}

.word-item {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.875rem;
}

.word-count {
    color: var(--secondary-color);
}

/* Blue Underline in Edit Panel */
.blue-underline-input {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.blue-underline-input input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Highlight Mode Selector */
.highlight-mode-selector {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.highlight-mode-option {
    display: block;
    position: relative;
    cursor: pointer;
}

.highlight-mode-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.highlight-mode-option span {
    display: block;
    padding: 0.5rem 0.5rem 0.5rem 2rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: white;
    transition: all 0.15s;
    font-size: 0.875rem;
    position: relative;
}

/* Custom radio button */
.highlight-mode-option span::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border: 2px solid #ccc;
    border-radius: 50%;
    background-color: white;
}

/* Radio button inner dot */
.highlight-mode-option input[type="radio"]:checked + span::before {
    border-color: var(--highlight-adverb);
}

.highlight-mode-option input[type="radio"]:checked + span::after {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--highlight-adverb);
}

/* Hover state */
.highlight-mode-option:hover span {
    background-color: #f5f5f5;
    border-color: var(--highlight-adverb);
}

/* Selected state */
.highlight-mode-option input[type="radio"]:checked + span {
    background-color: rgba(54, 179, 217, 0.08);
    border-color: var(--highlight-adverb);
    font-weight: 500;
}

.highlight-stats-container {
    margin-top: 0.75rem;
}

/* Rhythm Highlights Legend */
.rhythm-legend {
    margin-top: 0.75rem;
}

.rhythm-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.rhythm-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    display: inline-block;
}

.rhythm-color-gradient {
    width: 60px;
    height: 20px;
    border-radius: 3px;
    display: inline-block;
}

/* Rhythm Highlight Classes */
.rhythm-highlight-very-short {
    background-color: rgba(255, 0, 0, 0.3) !important;
}

.rhythm-highlight-short {
    background-color: rgba(255, 136, 0, 0.3) !important;
}

.rhythm-highlight-medium {
    background-color: rgba(255, 255, 0, 0.3) !important;
}

.rhythm-highlight-long {
    background-color: rgba(0, 255, 0, 0.3) !important;
}

.rhythm-highlight-very-long {
    background-color: rgba(0, 136, 255, 0.3) !important;
}

/* Grammar Structures */
.grammar-structures-list {
    margin-top: 1rem;
}

.grammar-option {
    display: block;
    padding: 0.25rem 0;
    cursor: pointer;
    font-size: 0.875rem;
}

.grammar-option input[type="checkbox"] {
    margin-right: 0.5rem;
}

/* Red underline for grammar structures */
.grammar-highlight {
    border-bottom: 2px solid #e74c3c;
    padding-bottom: 1px;
}

/* When both grammar and blue underline are applied, blue takes precedence */
span.grammar-highlight.blue-underline,
span.blue-underline.grammar-highlight {
    border-bottom: 2px solid #2196F3 !important;
}

/* Ensure nested highlights don't double underline */
.blue-underline .blue-underline,
.grammar-highlight .grammar-highlight {
    border-bottom: none !important;
}

/* Preserve spacing in highlights - only target spans in the editor */
.editor [class*="highlight-"], 
.editor [class*="rhythm-highlight-"], 
.editor .grammar-highlight, 
.editor .blue-underline {
    white-space: pre-wrap;
    display: inline;
}

/* AI Tools */
.ai-selector {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.ai-selector label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}

.ai-context-section {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.ai-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.ai-option input[type="checkbox"] {
    cursor: pointer;
}

.ai-question {
    width: 100%;
    min-height: 80px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    resize: vertical;
    margin-bottom: 0.5rem;
}

.ai-response {
    margin-top: 1rem;
    padding: 1rem;
    background-color: var(--background-color);
    border-radius: 4px;
    font-size: 0.875rem;
    display: none;
}

.ai-response.active {
    display: block;
}

/* Agents List */
.agents-list {
    margin-top: 1rem;
}

.agent-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background-color: var(--background-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.agent-item:hover {
    background-color: #f0f0f0;
}

.agent-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.agent-prompt {
    font-size: 0.75rem;
    color: var(--secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

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

.modal-content {
    background-color: var(--background-color);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-content.modal-wide {
    max-width: 900px;
}

.modal-content.modal-small {
    max-width: 400px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary-color);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.agent-form {
    margin-bottom: 2rem;
}

.agent-form input,
.agent-form textarea {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.agent-form textarea {
    min-height: 100px;
    resize: vertical;
}

.existing-agents {
    margin-top: 2rem;
}

.existing-agent-item {
    display: flex;
    justify-content: space-between;
    align-items: start;
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: var(--sidebar-bg);
    border-radius: 4px;
}

.existing-agent-info {
    flex: 1;
}

.delete-agent {
    color: var(--highlight-very-hard);
    cursor: pointer;
}

/* Highlighting Classes for Editor */
.highlight-adverb {
    background-color: var(--highlight-adverb);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
}

.highlight-passive {
    background-color: var(--highlight-passive);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
}

.highlight-complex {
    background-color: var(--highlight-complex);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
}

.highlight-qualifier {
    background-color: var(--highlight-adverb);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
}

.highlight-hard {
    background-color: var(--highlight-hard);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
}

.highlight-very-hard {
    background-color: var(--highlight-very-hard);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
}

.highlight-custom {
    background-color: var(--highlight-custom);
    color: white;
    padding: 2px 4px;
    border-radius: 2px;
}

/* Blue Underline Highlights */
.blue-underline {
    border-bottom: 2px solid #2196F3 !important;
    padding-bottom: 1px;
}

/* Blue Underline Settings */
.blue-underline-section {
    margin-top: 1rem;
}

.blue-underline-input-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.blue-underline-input-group input {
    flex: 1;
}

.blue-underline-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
}

.blue-underline-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0.5rem;
    margin-bottom: 0.25rem;
    background-color: #f5f5f5;
    border-radius: 4px;
}

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

.blue-underline-item span {
    border-bottom: 2px solid #2196F3;
    padding-bottom: 1px;
}

/* Ensure blue underline takes precedence over other highlights */
span.blue-underline {
    border-bottom: 2px solid #2196F3 !important;
    background-color: transparent !important;
    position: relative;
    z-index: 10;
}

/* Prevent overlap of underlines */
span.blue-underline span,
span span.blue-underline {
    border-bottom: none !important;
}

/* When blue underline is applied to other highlights, remove their background */
span.highlight-adverb.blue-underline,
span.highlight-passive.blue-underline,
span.highlight-complex.blue-underline,
span.highlight-qualifier.blue-underline,
span.highlight-hard.blue-underline,
span.highlight-very-hard.blue-underline,
span.highlight-custom.blue-underline {
    background-color: transparent !important;
    color: inherit !important;
    padding: 0 !important;
}

.blue-underline-item button {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 0.25rem;
}

.blue-underline-item button:hover {
    color: #c0392b;
}

/* Write Mode */
.write-mode .sidebar {
    display: none;
}

.write-mode .editor-section {
    margin: 0 auto;
}

/* Global Context */
.global-context-textarea {
    width: 100%;
    min-height: 200px;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    resize: vertical;
    font-family: inherit;
}

/* Documents Grid */
.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    padding: 1rem 0;
}

.document-card {
    padding: 1.5rem;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.document-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.document-card.current-document {
    border-color: var(--primary-color);
    background-color: rgba(0, 123, 255, 0.05);
}

.document-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.document-title {
    font-weight: 600;
    flex: 1;
    margin-right: 0.5rem;
}

.document-delete-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.document-delete-btn:hover {
    opacity: 1;
    background-color: rgba(255, 0, 0, 0.1);
    border-radius: 4px;
}

.document-meta {
    font-size: 0.875rem;
    color: var(--secondary-color);
}

.document-meta-item {
    margin-bottom: 0.25rem;
}

.current-indicator {
    color: var(--primary-color);
    font-weight: 500;
}

/* Chapter Name Input */
.chapter-name-input {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Settings Modal */
.settings-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.settings-section h3 {
    margin-bottom: 1rem;
}

.settings-description {
    color: var(--secondary-color);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.api-key-group {
    margin-bottom: 1.5rem;
}

.api-key-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.api-key-input-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.api-key-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.875rem;
}

.settings-input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
}

.toggle-visibility {
    padding: 0.5rem;
    font-size: 1rem;
}

.api-key-group small {
    display: block;
    color: var(--secondary-color);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.api-key-group small a {
    color: var(--highlight-adverb);
    text-decoration: none;
}

.api-key-group small a:hover {
    text-decoration: underline;
}

.settings-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Storage Info Styles */
.storage-info {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    margin: 10px 0;
}

.storage-metric {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e5e5e7;
}

.storage-metric:last-child {
    border-bottom: none;
}

.metric-label {
    font-weight: 500;
    color: #666;
}

.metric-value {
    font-weight: 600;
    color: #333;
}

.storage-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

.btn-danger {
    background-color: var(--highlight-very-hard);
    color: white;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Chat Mode Styles */
.chat-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--background-color);
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 1rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--sidebar-bg);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.chat-message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease-in;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

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

.chat-message.user {
    align-items: flex-end;
}

.chat-message.assistant {
    align-items: flex-start;
}

.chat-message-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--secondary-color);
}

.chat-avatar {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    background-color: var(--primary-color);
    color: white;
}

.chat-message.user .chat-avatar {
    background-color: var(--accent-color);
}

.chat-message-bubble {
    display: inline-block;
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    text-align: left;
    box-shadow: 0 8px 20px rgba(29, 34, 67, 0.08);
}

.chat-message.user .chat-message-bubble {
    background-color: var(--accent-color);
    color: white;
}

.chat-message.assistant .chat-message-bubble {
    background-color: white;
    border: 1px solid var(--border-color);
}

.chat-message-bubble pre {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    overflow-x: auto;
}

.chat-message-bubble code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-size: 0.875em;
}

.chat-input-area {
    background-color: var(--background-color);
    padding: 1rem 0;
}

.chat-context-options {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 0.75rem;
}

.chat-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--secondary-color);
}

.chat-option input[type="checkbox"] {
    cursor: pointer;
}

.chat-input-container {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    resize: vertical;
    font-family: inherit;
    font-size: 0.95rem;
    min-height: 3rem;
}

.chat-input:focus {
    outline: none;
    border-color: var(--highlight-adverb);
}

.chat-send-btn {
    padding: 0.75rem 1.5rem;
    background-color: var(--highlight-adverb);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
}

.chat-send-btn:hover {
    background-color: #2a8fb8;
}

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

/* Hide sidebar in chat mode */
body.chat-mode .sidebar {
    display: none;
}

body.chat-mode .main-content {
    width: 100%;
}

/* Mode button styling */
.mode-btn:last-child {
    border-radius: 0 4px 4px 0;
}

/* AI Toggle Button */
.ai-toggle-btn {
    padding: 0.5rem 1rem;
    margin-left: 0.5rem;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border-radius: 4px;
}

.ai-toggle-btn.active {
    background-color: var(--highlight-adverb);
    color: white;
    border-color: var(--highlight-adverb);
}

.ai-toggle-btn:hover {
    background-color: #f0f0f0;
}

.ai-toggle-btn.active:hover {
    background-color: #2a8fb8;
}

.notes-toggle-btn {
    padding: 0.5rem 1rem;
    margin-left: 0.5rem;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border-radius: 4px;
}

.notes-toggle-btn.active {
    background-color: #9370db;
    color: white;
    border-color: #9370db;
}

.notes-toggle-btn:hover {
    background-color: #f0f0f0;
}

.notes-toggle-btn.active:hover {
    background-color: #7b60c3;
}

/* AI Panel Styles */
.ai-panel {
    position: relative;
    width: 400px;
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.3s ease;
}

.ai-panel-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: white;
}

.ai-panel-header h2 {
    font-size: 1.25rem;
    margin: 0 0 0.5rem 0;
}

.ai-panel-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-model-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-right: 1rem;
    font-size: 0.875rem;
    cursor: pointer;
}

/* Quick Stats Bar */
.quick-stats-bar {
    display: flex;
    justify-content: space-around;
    padding: 0.75rem 1rem;
    background-color: white;
    border-bottom: 1px solid var(--border-color);
}

.quick-stat {
    text-align: center;
}

.quick-stat-label {
    font-size: 0.75rem;
    color: var(--secondary-color);
    display: block;
}

.quick-stat-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: white;
    border-top: 1px solid var(--border-color);
}

.quick-action-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    cursor: pointer;
    font-size: 0.875rem;
    border-radius: 4px;
    transition: all 0.2s;
    font-weight: 500;
}

.quick-action-btn:hover {
    background-color: #f0f0f0;
    border-color: var(--highlight-adverb);
}

/* Agent Selector */
.agent-selector-container {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: #f5f5f5;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.agent-selector {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: white;
    font-size: 0.875rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.125rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-icon:hover {
    opacity: 1;
}

.btn-icon.btn-small {
    font-size: 0.875rem;
}

/* Adjust chat messages for AI panel */
.ai-panel .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--sidebar-bg);
}

/* AI Input Area */
.ai-input-area {
    background-color: white;
    border-top: 1px solid var(--border-color);
    padding: 1rem;
}

/* Adjust main content when AI panel is visible */
.main-content.with-ai {
    margin-right: 0;
}

/* Hide original sidebar when AI panel is shown */
body.ai-panel-open .sidebar {
    display: none;
}

/* Edit Mode Sidebar */
.edit-sidebar {
    width: 300px;
    background-color: var(--sidebar-bg);
    overflow-y: auto;
    padding: 1.5rem 1.25rem;
    height: 100%;
    border-left: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Hide edit sidebar when not in edit mode */
body:not(.edit-mode) .edit-sidebar {
    display: none !important;
}

/* Responsive adjustments */
/* Notes Panel Styles */
.notes-panel {
    position: relative;
    width: 350px;
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notes-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: white;
}

.notes-header h2 {
    margin: 0 0 1rem 0;
    font-size: 1.25rem;
}

.notes-tabs {
    display: flex;
    gap: 0.5rem;
}

.notes-tab {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    cursor: pointer;
    font-size: 0.875rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.notes-tab.active {
    background-color: var(--primary-color);
    color: white;
}

.notes-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.notes-section {
    display: none;
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.notes-section.active {
    display: flex;
    flex-direction: column;
}

.notes-textarea {
    flex: 1;
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: none;
}

.chapter-notes-header {
    margin-bottom: 1rem;
    padding: 0.5rem;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    font-weight: 600;
}

@media (max-width: 1200px) {
    .ai-panel {
        width: 350px;
    }
}

@media (max-width: 768px) {
    .ai-panel {
        position: fixed;
        right: 0;
        top: 60px;
        height: calc(100vh - 60px);
        z-index: 50;
        transform: translateX(100%);
    }
    
    .ai-panel.active {
        transform: translateX(0);
    }
}

/* Auto-export indicator */
.auto-export-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #4caf50;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: none;
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
