/* ============================================
   StudyHub - Tool-Specific Styles
   ============================================ */

/* === PDF Viewer === */
/* Main Container relative positioning for overlay */
.pdf-viewer {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    position: relative;
    /* Essential for overlay */
}

/* --- Drag Overlay (New Implementation) --- */
.drag-overlay {
    position: absolute;
    inset: -10px;
    /* Slight bleed */
    background: rgba(var(--bg-body-rgb), 0.95);
    /* High contrast background */
    backdrop-filter: blur(4px);
    border: 3px dashed var(--color-brand);
    border-radius: var(--radius-xl);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.2s ease;
    transform: scale(0.98);
}

.pdf-viewer.drag-active .drag-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    /* Capture events now */
    transform: scale(1);
}

.drag-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--color-brand);
    animation: bounceIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    /* Prevent interference with drag events */
}

.drag-overlay-content svg {
    margin-bottom: 1rem;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.drag-overlay-content h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

@keyframes bounceIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Drop Zone Styles */
.file-input {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-xl);
    background: var(--bg-surface);
    transition: all var(--transition-fast);
    cursor: pointer;
    text-align: center;
}

.file-input:hover,
.file-input.dragover,
.pdf-viewer.drag-active .file-input {
    border-color: var(--color-brand);
    background: var(--bg-surface-hover);
    transform: scale(1.02);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* Animación de pulso cuando se arrastra un archivo */
@keyframes dropZonePulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }

    70% {
        transform: scale(1.02);
        box-shadow: 0 0 0 10px rgba(99, 102, 241, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}

.pdf-viewer.drag-active .file-input {
    animation: dropZonePulse 2s infinite;
    border-style: solid;
    background: rgba(99, 102, 241, 0.05);
}


.file-input input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.file-input-icon {
    width: 64px;
    height: 64px;
    color: var(--color-brand);
    margin-bottom: var(--space-md);
    opacity: 0.8;
}

.file-input-text {
    font-size: var(--text-lg);
    color: var(--text-primary);
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}

.pdf-toolbar-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.pdf-page-input {
    width: 60px;
    text-align: center;
    padding: 0.5rem;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-weight: 500;
}

.pdf-canvas-container {
    flex: 1;
    overflow: auto;
    background: var(--bg-muted);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    justify-content: center;
    min-height: 600px;
    border: 1px solid var(--border-color);
}

.pdf-canvas {
    box-shadow: var(--shadow-lg);
    max-width: 100%;
    border-radius: var(--radius-sm);
}

/* === Calculator === */
.calculator {
    max-width: 400px;
    margin: 0 auto;
}

.calculator-display {
    background: var(--bg-body);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    text-align: right;
}

.calculator-expression {
    font-size: var(--text-sm);
    color: var(--text-muted);
    min-height: 20px;
    word-break: break-all;
}

.calculator-result {
    font-size: var(--text-4xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    font-family: var(--font-mono);
    word-break: break-all;
}

.calculator-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
}

.calc-btn {
    aspect-ratio: 1;
    font-size: var(--text-xl);
    font-weight: var(--font-medium);
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.calc-btn:hover {
    background: var(--bg-surface-hover);
    transform: scale(1.05);
}

.calc-btn:active {
    transform: scale(0.98);
}

.calc-btn-operator {
    background: var(--color-secondary);
    color: white;
}

.calc-btn-operator:hover {
    background: var(--color-secondary-hover);
}

.calc-btn-equals {
    background: var(--gradient-primary);
    color: white;
}

.calc-btn-equals:hover {
    box-shadow: var(--shadow-glow);
}

.calc-btn-clear {
    color: #f87171;
}

.calc-btn-function {
    font-size: var(--text-sm);
    color: var(--color-primary);
}

/* === Word Counter === */
.word-counter {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.word-counter-textarea {
    min-height: 300px;
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
}

.word-counter-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-md);
}

.stat-card {
    background: var(--bg-surface);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    text-align: center;
}

.stat-value {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    color: var(--color-primary);
    font-family: var(--font-mono);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

/* === Pomodoro Timer === */
.pomodoro {
    max-width: 400px;
    margin: 0 auto;
    text-align: center;
}

.pomodoro-timer {
    position: relative;
    width: 280px;
    height: 280px;
    margin: 0 auto var(--space-xl);
}

.pomodoro-circle {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background:
        conic-gradient(var(--color-primary) var(--progress, 0%),
            var(--bg-surface) var(--progress, 0%));
    padding: 8px;
}

.pomodoro-circle::before {
    content: '';
    position: absolute;
    inset: 8px;
    background: var(--bg-body);
    border-radius: 50%;
}

.pomodoro-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}

.pomodoro-time {
    font-size: var(--text-5xl);
    font-weight: var(--font-bold);
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.pomodoro-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.pomodoro-controls {
    display: flex;
    justify-content: center;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.pomodoro-modes {
    display: flex;
    justify-content: center;
    gap: var(--space-sm);
}

.pomodoro-mode {
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    background: var(--bg-surface);
    transition: all var(--transition-fast);
}

.pomodoro-mode.active {
    background: var(--gradient-primary);
    color: white;
}

/* === Spell Checker === */
.spell-checker {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.spell-checker-input {
    min-height: 250px;
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
}

.spell-results {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
}

.spell-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.spell-error-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.spell-error-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-body);
    border-radius: var(--radius-md);
    border-left: 3px solid #f87171;
}

.spell-error-word {
    font-weight: var(--font-semibold);
    color: #f87171;
}

.spell-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

.spell-suggestion {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    color: var(--color-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.spell-suggestion:hover {
    background: var(--color-primary);
    color: white;
}

/* === Notes === */
.notes-container {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-lg);
    height: 600px;
}

.notes-list {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.notes-list-items {
    flex: 1;
    overflow-y: auto;
}

.note-item {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.note-item:hover {
    background: var(--bg-surface-hover);
}

.note-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--color-primary);
}

.note-item-title {
    font-weight: var(--font-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-item-preview {
    font-size: var(--text-sm);
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.note-item-date {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

.notes-editor {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notes-editor-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.notes-editor-title {
    width: 100%;
    background: transparent;
    border: none;
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.notes-editor-content {
    flex: 1;
    padding: var(--space-md);
}

.notes-editor-textarea {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    resize: none;
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .notes-container {
        grid-template-columns: 1fr;
        height: auto;
    }

    .notes-list {
        max-height: 300px;
    }
}

/* === Empty State === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-3xl);
    text-align: center;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin-bottom: var(--space-lg);
    color: var(--text-muted);
    opacity: 0.5;
}

.empty-state-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
}

.empty-state-description {
    color: var(--text-muted);
    max-width: 400px;
}

/* === PDF Editor (Fullscreen Mode) === */
.pdf-viewer-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
}

body.editor-active {
    overflow: hidden;
    /* Prevent scrolling body while editor is open */
}

/* To ensure it stays on top of sticky navbar */
body.editor-active .navbar {
    z-index: 900;
}

.editor-top-bar {
    height: 64px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    z-index: 20;
    box-shadow: var(--shadow-sm);
}

.editor-title-section {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex: 1;
}

.file-info {
    display: flex;
    flex-direction: column;
}

.file-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.file-status {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.editor-tools-section {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--bg-body);
    padding: 4px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 48px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 10px;
    gap: 2px;
    transition: all 0.2s;
}

.tool-btn svg {
    margin-bottom: 2px;
}

.tool-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.tool-btn.active {
    background: var(--bg-surface);
    color: var(--color-brand);
    box-shadow: var(--shadow-sm);
}

.editor-actions-section {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    flex: 1;
    justify-content: flex-end;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    background: var(--bg-body);
    padding: 4px 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

#zoom-level {
    font-size: var(--text-xs);
    font-weight: 500;
    min-width: 40px;
    text-align: center;
}

.editor-main-area {
    flex: 1;
    background: var(--bg-muted);
    overflow: auto;
    position: relative;
    display: flex;
    justify-content: center;
    padding: var(--space-xl);
}

.editor-canvas-wrapper {
    box-shadow: var(--shadow-2xl);
    margin: auto;
    /* Center when smaller than viewport */
}

/* Confirmation State Styles */
.confirmation-state {
    animation: fadeIn 0.3s ease;
}

.confirmation-state .card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-xl);
}

/* === Format Capability Cards === */
.format-capabilities {
    margin-top: var(--space-xl);
    padding: var(--space-lg);
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
}

.format-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
}

.format-card {
    padding: var(--space-md);
    background: var(--bg-body);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.format-card.featured {
    border-color: var(--color-brand);
    background: rgba(99, 102, 241, 0.05);
}

.format-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.format-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 32px;
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    font-weight: 700;
    margin-bottom: var(--space-sm);
}

.format-icon.pdf {
    background: linear-gradient(135deg, #dc2626, #ef4444);
    color: white;
}

.format-icon.docx {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: white;
}

.format-info {
    display: flex;
    flex-direction: column;
    margin-bottom: var(--space-sm);
}

.format-name {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text-primary);
}

.format-level {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.format-level.level-full {
    color: var(--color-brand);
    font-weight: 500;
}

.format-features {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.format-features li {
    padding: 2px 0;
}

/* === DOCX Editor === */
.docx-editor-wrapper {
    max-width: 816px;
    /* A4 width at 96dpi */
    width: 100%;
    margin: var(--space-xl) auto;
    background: white;
    box-shadow: var(--shadow-2xl);
    border-radius: var(--radius-lg);
    min-height: 1056px;
    /* A4 height */
}

.docx-editor {
    padding: 60px 72px;
    /* Standard Word margins */
    min-height: 1056px;
    font-family: 'Calibri', 'Segoe UI', sans-serif;
    font-size: 11pt;
    line-height: 1.5;
    color: #1a1a1a;
    outline: none;
}

.docx-editor:focus {
    outline: none;
}

.docx-editor p {
    margin: 0 0 12pt 0;
}

.docx-editor h1 {
    font-size: 16pt;
    font-weight: bold;
    margin: 12pt 0;
}

.docx-editor h2 {
    font-size: 14pt;
    font-weight: bold;
    margin: 10pt 0;
}

.docx-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 12pt 0;
}

.docx-editor th,
.docx-editor td {
    border: 1px solid #ccc;
    padding: 6pt 8pt;
    text-align: left;
}

/* === DOCX Preview (docx-preview library) === */
.docx-preview-wrapper {
    width: 100%;
    height: 100%;
    overflow: auto;
    background: var(--bg-muted);
    padding: var(--space-lg);
}

.docx-preview-wrapper .docx-wrapper {
    background: white;
    margin: 0 auto;
    box-shadow: var(--shadow-2xl);
}

.docx-preview-wrapper .docx-wrapper>section.docx {
    padding: 72px !important;
    min-height: auto !important;
}

/* === DOCX Split View Editor === */
.docx-paragraph-group {
    background: white;
    padding: var(--space-sm);
    margin-bottom: var(--space-sm);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.docx-segment {
    margin-bottom: var(--space-xs);
}

.docx-segment:last-child {
    margin-bottom: 0;
}

.docx-segment-input {
    width: 100%;
    border: 1px solid transparent;
    /* Hidden border until hover/focus */
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--text-sm);
    background: transparent;
    resize: none;
    /* Auto-resized by JS */
    color: var(--text-primary);
    line-height: 1.5;
    transition: all 0.2s ease;
}

.docx-segment-input:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-color);
}

.docx-segment-input:focus {
    background: white;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 2px var(--color-brand-alpha);
    outline: none;
}

/* Paragraph-based editor (V2) */
.docx-paragraph-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
    font-weight: 500;
}

.docx-paragraph-input {
    width: 100%;
    min-height: 50px;
    padding: var(--space-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--text-sm);
    background: white;
    color: var(--text-primary);
    line-height: 1.6;
    resize: none;
    transition: all 0.2s ease;
}

.docx-paragraph-input:focus {
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px var(--color-brand-alpha);
    outline: none;
}

.docx-paragraph-group {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.docx-paragraph-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

/* === DOCX Editor (High-Fidelity Form Filler) === */
.docx-editor-layout {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: var(--space-md);
    height: calc(100vh - 120px);
    min-height: 600px;
}

.docx-editor-preview {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: auto;
    padding: var(--space-md);
    box-shadow: var(--shadow-md);
}

.docx-editor-preview .docx-wrapper {
    background: white !important;
    padding: 20px;
    margin: 0 auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Force black text for the document content to override dark mode defaults */
.docx-wrapper,
.docx-wrapper * {
    color: black !important;
    fill: black !important;
}

.docx-wrapper section {
    background: white !important;
}

.docx-editor-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.panel-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.panel-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.panel-subtitle {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

.panel-actions {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.panel-actions .btn-primary,
.panel-actions .btn-secondary {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.panel-actions .btn-primary {
    background: var(--color-brand);
    color: white;
}

.panel-actions .btn-primary:hover:not(:disabled) {
    background: var(--color-brand-hover);
}

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

.panel-actions .btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
}

.panel-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading-text,
.no-fields {
    text-align: center;
    color: var(--text-secondary);
    padding: var(--space-lg);
}

/* Responsive */
@media (max-width: 900px) {
    .docx-editor-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }

    .docx-editor-panel {
        max-height: 300px;
    }
}